From owner-freebsd-questions Tue Jun 11 05:21:20 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id FAA05042 for questions-outgoing; Tue, 11 Jun 1996 05:21:20 -0700 (PDT) Received: from relay-4.mail.demon.net (relay-4.mail.demon.net [158.152.1.108]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id FAA04777 for ; Tue, 11 Jun 1996 05:19:41 -0700 (PDT) Received: from post.demon.co.uk ([158.152.1.72]) by relay-4.mail.demon.net id ah18344; 11 Jun 96 12:10 GMT Received: from jraynard.demon.co.uk ([158.152.42.77]) by relay-3.mail.demon.net id aa13309; 11 Jun 96 1:08 +0100 Received: (from fqueries@localhost) by jraynard.demon.co.uk (8.7.5/8.6.12) id UAA03545; Mon, 10 Jun 1996 20:54:56 GMT Date: Mon, 10 Jun 1996 20:54:56 GMT Message-Id: <199606102054.UAA03545@jraynard.demon.co.uk> From: James Raynard To: Eric.Berenguier@sycomore.fr CC: questions@freebsd.org In-reply-to: (message from Eric Berenguier on Mon, 10 Jun 1996 16:51:49 +0200) Subject: Re: Bug in truncate function ? Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > here is a small exemple that doesn't work as i think it should: > > -- Exemple ----------------------------------------------------------- > #include > > 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 #include 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