Orphaned Response

matt at prism.UUCP matt at prism.UUCP
Thu Jun 20 12:35:00 AEST 1985


/**** prism:net.unix-wizar / turtlevax!ken /  7:46 pm  Jun 10, 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.
/* ---------- */

Ah, but if you look carefully, you'll see that the original poster
(Ernest Hua) states very clearly that he's using 4.1, NOT 4.2 BSD.   If
I recall correctly, there's no equivilent of truncate() or ftruncate()
in 4.1.  [By the way, both of these functions are perfectly well
documented in our copy of 4.2 - why not in yours?]

-----------------------------------------------------------------------------
 Matt Landau            {cca, datacube, ihnp4, inmet, mit-eddie, wjh12}...
 Mirror Systems, Inc.                                   ...mirror!prism!matt
-----------------------------------------------------------------------------



More information about the Comp.unix.wizards mailing list