From: Martin Str|mberg Message-Id: <199907181039.MAA03004@father.ludd.luth.se> Subject: Re: ftruncate To: djgpp-workers AT delorie DOT com (DJGPP-WORKERS) Date: Sun, 18 Jul 1999 12:39:42 +0200 (MET DST) X-Mailer: ELM [version 2.4ME+ PL15 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com kant:/tmp> uname -a Linux kant 2.0.33 #1 Fri Aug 21 06:21:28 CEST 1998 i586 unknown kant:/tmp> ldd d /lib/nfslock.so.0 => /lib/nfslock.so.0 (0x4000d000) libc.so.6 => /lib/libc.so.6 (0x40012000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) kant:/tmp> touch /tmp/.aasas kant:/tmp> ./d Open done. Write done (w = 19). ftruncate done (ft = 0). lseek returned 19. kant:/tmp> ls -al /tmp/.aasas -rw-r--r-- 1 martin users 2 Jul 18 12:37 /tmp/.aasas Test program follows. Welin, String Quartet No. 7, MartinS #include #include #include #include #include int main(void) { int fd; int ft; int w; char my_str[] = "This is my string.\n"; fd = open("/tmp/.aasas", O_WRONLY); if( fd < 0 ) { perror("open on /tmp/.aasas failed"); exit(1); } fprintf(stderr, "Open done.\n"); w = write(fd, my_str, strlen(my_str)); fprintf(stderr, "Write done (w = %d).\n", w); ft = ftruncate(fd, 2); if(ft < 0) { perror("ftruncate failed.\n"); } fprintf(stderr, "ftruncate done (ft = %d).\n", ft); ft = lseek(fd, 0, SEEK_CUR); fprintf(stderr, "lseek returned %d.\n", ft); return(0); }