Ftruncate on SysV?

Conor P. Cahill cpcahil at virtech.uucp
Sun Mar 11 01:40:57 AEST 1990


In article <}*~#}T at rpi.edu> night at pawl.rpi.edu (Trip Martin) writes:
>I'm trying to port PLP to SysV, and one of the few remaining hurdles
>is the ftruncate system call.  Does anyone know of a way of simulating
>that call in SysV?  BTW, root access is not a problem, although I'd
>like to avoid using privileged operations if I can.

Get current size of file
If the ftruncate size is greater than current size
	lseek to ftruncate size - 1
	write(fd,"",1)
Else if you know the name of the file
	create tmpfile
	copy file to tmpfile upto ftruncate size
	mv file to file.old
	mv tmpfile to file
	close(fd)
	fd = open file
	dup(fd) untile you get it to the same fd that it was before
	close the extra fds created by the duping
Else
	you're SOL (unless you want to go searching around the file system
	to find the name of the file which can take a very long time).

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.wizards mailing list