Subject: Problem with ftruncate() ...
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: None <cagney@highland.oz.au>
List: current-users
Date: 05/18/1994 17:58:46
Hi,

The code below doesn't work on NetBSD-current ~2nd May on a x86
yet works under SunOS 4.1.3. (The call to ftruncate() fails???).

One thing I did notice but didn't seem to fix the problem (I didn't really
expect it to :-) is in:

	src/lib/libc/sys/ftruncate.c

it is declared as:

	ftruncate(char *path, off_t length)

instead of:

	ftruncate(int fd, off_t length)

The output I get is:

	After open: Undefined error: 0
	Open returns 3
	After Write: Undefined error: 0
	Write returns 6
	After ftruncate: Invalid argument
	ftruncate returns -1


any hints? Is it an error and if so has it been fixed?

			Andrew



#include <fcntl.h>
main()
{
	int fd;
	int status;
	char *file = "/tmp/foo";
	char *data = "123456";
	int datalen = strlen(data);

	fd = open(file, O_RDWR | O_CREAT, 0600);
	perror("After open");
	printf("Open returns %d\n", fd);

	status = write(fd, data, datalen);
	perror("After Write");
	printf("Write returns %d\n", status);

	status = ftruncate(fd, 6);
	perror("After ftruncate");
	printf("ftruncate returns %d\n", status);

	unlink(file);

	exit(0);
}


------------------------------------------------------------------------------