truncating a file opened via open()

Guy Harris guy at sun.uucp
Thu Jun 20 20:03:02 AEST 1985


> > There are precisely two solutions for non-4.2BSD systems:
> > 1) implement (f)truncate on your system...
> 
> Kind of tough for people without source licenses (I know, I'm whining).

Actually, it was meant as a hint to various vendors, some of whom may be
long-distance carriers...

> > 2) Copy the entire file, up to the point of truncation, to a temporary
> > file, then copy it back to the original file.

> I don't see how this works unless you unlink the file and then re-creat
> it before writing it back.

Why unlink it?  Re-"creat"ing will do the job - it truncates the file to
zero length (unless you don't have write permission, which is unlikely
unless the file is newly created and you created it without giving yourself
write permission).

	Guy Harris



More information about the Comp.unix.wizards mailing list