Xenix

shirono at hcx3.SSD.HARRIS.COM shirono at hcx3.SSD.HARRIS.COM
Tue Sep 20 02:07:00 AEST 1988


/* Written  3:10 pm  Sep 15, 1988 by chip at ateng.UUCP in hcx3:comp.lang.c */
According to english at stromboli.usc.edu (Joe English):
>In article <171 at uniblab.UUCP> al at uniblab.UUCP (alan krantz) writes:
>> If i have an open file and want to set that files length
>> to zero, do i have to close the file and reopen it?
>
>Can't be done; you do have to close() and re- creat() or 
>open(... | O_TRUNC).

	int fd1, fd2;

	fd1 = creat("filename", 0666);
	write(fd1, "howdy", 5);
	fd2 = creat("filename", 0666);  /* truncates file */
	close(fd2);
	/* but fd1 is still open and available */
/* End of text from hcx3:comp.lang.c */

Also, fd1 is at offset 5.  The next write would happen at that point, leaving
a hole (or ASCII nul's).

______________________________________________________________________________
                               ||   Internet: shirono at ssd.harris.com
     Roberto Shironoshita      ||
      Harris Corporation       ||             ...!novavax---\
   Computer Systems Division   ||   UUCP:     ...!uunet-------!hcx1!shirono
                               ||             ...!mit-eddie-/
------------------------------------------------------------------------------
DISCLAIMER: The opinions expressed here are my own; they in no way reflect the
            opinion or policies of Harris Corporation.



More information about the Comp.lang.c mailing list