2 static const char rcsid[] = "$Id: ftruncate.c,v 1.3 2005/04/27 18:16:45 sra Exp $";
7 * ftruncate - set file size, BSD Style
9 * shortens or enlarges the file as neeeded
10 * uses some undocumented locking call. It is known to work on SCO unix,
11 * other vendors should try.
12 * The #error directive prevents unsupported OSes
15 #include "port_before.h"
29 #include "port_after.h"
32 __ftruncate(int fd, long wantsize) {
35 /* determine current file size */
36 if ((cursize = lseek(fd, 0L, 2)) == -1)
39 /* maybe lengthen... */
40 if (cursize < wantsize) {
41 if (lseek(fd, wantsize - 1, 0) == -1 ||
42 write(fd, "", 1) == -1) {
48 /* maybe shorten... */
49 if (wantsize < cursize) {
54 fl.l_start = wantsize;
56 return (fcntl(fd, F_FREESP, &fl));
63 int __bindcompat_ftruncate;