Truncating an existing file (and lockf question)

Joe English jeenglis at alcor.usc.edu
Thu Apr 25 04:00:32 AEST 1991


nto0302 at dsacg3.dsac.dla.mil (Bob Fisher) writes:
>How can I truncate the end of a large file without copying the part
>to be preserved to a new file and then doing a remove/rename?
>
>This is for SVR3 but may need ported to BSD4.3.

Check for a system call called 'truncate' or 'ftruncate'.
SunOS has these, but the man pages are (as usual) unclear
as to whether they're from BSD, System V, both, or neither.
I seem to remember seeing this under both BSD4.3 and SVR3.

This brings up another question:  I was looking under the
man page for 'fcntl' to see if it had a truncate option,
and found the following under the description of F_SETLK:


     A shared or exclusive lock is either advisory  or  mandatory
     depending on the mode bits of the file containing the locked
     segment.  The lock is mandatory if the set-GID bit (S_ISGID)
     is  set  and  the  group execute bit (S_IXGRP) is clear (see
     stat(2V) for information about mode bits).   Otherwise,  the
     lock is advisory.


This sounds really weird.  Why should locking behaviour depend 
on the setgid bit?   Is this just a SunOS quirk?

Followups to comp.unix.questions....


--Joe English

  jeenglis at alcor.usc.edu



More information about the Comp.lang.c mailing list