Subject: Re: Problem with ftruncate() ...
To: None <cagney@highland.oz.au>
From: Manuel Bouyer <bouyer@ensta.fr>
List: current-users
Date: 05/18/1994 12:21:58
cagney@highland.oz.au wrote:
>
> 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);
> }
>
>
/usr/include/fnctl.h doesn't seem to include /usr/include/unistd.h, where is
the prototype for ftruncate.
Perhaps you should add '#include <unistd.h>', or use a cast:
'status = ftruncate(fd, (off_t)6);'
--
--
Manuel Bouyer, Ecole Nationale Superieure de Techniques Avancees, Paris
email: bouyer@ensta.fr
--
------------------------------------------------------------------------------