2 static const char rcsid[] = "$Id: ftruncate.c,v 1.1 2001/03/29 06:30:32 marka Exp $";
6 * ftruncate - set file size, BSD Style
8 * shortens or enlarges the file as neeeded
9 * uses some undocumented locking call. It is known to work on SCO unix,
10 * other vendors should try.
11 * The #error directive prevents unsupported OSes
14 #include "port_before.h"
28 #include "port_after.h"
31 __ftruncate(int fd, long wantsize) {
34 /* determine current file size */
35 if ((cursize = lseek(fd, 0L, 2)) == -1)
38 /* maybe lengthen... */
39 if (cursize < wantsize) {
40 if (lseek(fd, wantsize - 1, 0) == -1 ||
41 write(fd, "", 1) == -1) {
47 /* maybe shorten... */
48 if (wantsize < cursize) {
53 fl.l_start = wantsize;
55 return (fcntl(fd, F_FREESP, &fl));
62 int __bindcompat_ftruncate;