Date: Mon, 10 Jun 1996 20:54:56 GMT From: James Raynard <fqueries@jraynard.demon.co.uk> To: Eric.Berenguier@sycomore.fr Cc: questions@freebsd.org Subject: Re: Bug in truncate function ? Message-ID: <199606102054.UAA03545@jraynard.demon.co.uk> In-Reply-To: <v01530503ade1e4a001d7@[192.134.92.34]> (message from Eric Berenguier on Mon, 10 Jun 1996 16:51:49 %2B0200)
next in thread | previous in thread | raw e-mail | index | archive | help
> here is a small exemple that doesn't work as i think it should:
>
> -- Exemple -----------------------------------------------------------
> #include <fcntl.h>
>
> main() {
> int fd;
> fd = open("/tmp/pp01234", O_RDWR | O_CREAT , 0600);
> if (ftruncate(fd,0)<0) {
> perror("truncate");
> }
> }
> ----------------------------------------------------------------------
>
> this program ouputs:
> truncate: invalid argument
This works fine if you include unistd.h, as recommended by the
ftruncate man page:-
$ cat temp.c
#include <fcntl.h>
#include <unistd.h>
main() {
int fd;
fd = open("/tmp/pp01234", O_RDWR | O_CREAT , 0600);
if (ftruncate(fd,0)<0) {
perror("truncate");
}
}
$ gcc temp.c
$ ./a.out
$ ls -l /tmp/pp01234
-rw------- 1 james bin 0 Jun 10 20:48 /tmp/pp01234
PS I always compile test programs with -Wall - this would have picked
up the missing header, as well as one or two less important omissions
which are left as an exercise for the reader 8-)
--
James Raynard, Edinburgh, Scotland
james@jraynard.demon.co.uk
jraynard@FreeBSD.ORG
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199606102054.UAA03545>
