truncating a file opened via open()
Ken Turkowski
ken at turtlevax.UUCP
Tue Jun 11 09:46:54 AEST 1985
In article <340 at cmu-cs-edu1.ARPA> hua at cmu-cs-edu1.ARPA (Ernest Hua) writes:
>Does anyone have any idea how to truncate a file at the current point in
>writing if it is opened by open()? I cannot use creat() because the file
>is being used by another process, and I cannot use unlink() it is likely
>that it is linked. If the updated contents is longer than the original,
>it is not a problem because the file length is just extended. But if the
>updated contents is shorter, the file does not shrink. We have 4.1BSD on
>several 780's and 750's.
try
size = lseek(fd, 0L, 1); /* tell(fd) */
ftruncate(fd, size); /* int fd, size; */
It's yet another undocumented feature on 4.2.
--
Ken Turkowski @ CADLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,nsc,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken at DECWRL.ARPA
More information about the Comp.unix.wizards
mailing list