Path: utzoo!attcan!uunet!lll-winken!lll-tis!mordor!joyce!ames!mailrus!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Xenix Keywords: Xenix, C, Files Message-ID: <767@proxftl.UUCP> Date: 15 Sep 88 05:08:49 GMT References: <171@uniblab.UUCP> Reply-To: bill@proxftl.UUCP (T. William Wells) Distribution: na Organization: Proximity Technology, Ft. Lauderdale Lines: 32 Summary: Expires: Sender: Followup-To: In article <171@uniblab.UUCP> al@uniblab.UUCP (alan krantz) writes: : I'm writing a C program using SCO Xenix 386 ver 2.2.?. : 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. : I know if i open an existing file with creat it will truncate : the length to zero. I want to be able to do that with a file : i have already opened and read from. I am speaking from what I know of UNIX, so I don't know for sure that Xenix does the same, but if you open the file again, with the truncate bit set, it should set the file length to zero. Of course, you also have to seek the other file descriptor to the beginning of the file. In other words, if you know the file name, you could write a routine like: void trunc_file(file, fd) char *file; int fd; { lseek(fd, 0L, 0); close(open(file, O_TRUNC|O_WRONLY)); } When it exits, your fd should point to the beginning of an empty file. (Of course, if you *want* to write to the old position, you don't have to seek.) --- Bill novavax!proxftl!bill