Subject: Problem with ftruncate() ...
To: None <>
From: None <>
List: current-users
Date: 05/18/1994 17:58:46

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:


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?


#include <fcntl.h>
	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);