1 /* ftruncate emulations that work on some System V's.
2 This file is in the public domain. */
13 return fcntl (fd
, F_CHSIZE
, length
);
17 /* The following function was written by
18 kucharsk@Solbourne.com (William Kucharski) */
25 ftruncate (fd
, length
)
32 if (fstat (fd
, &filebuf
) < 0)
35 if (filebuf
.st_size
< length
)
37 /* Extend file length. */
38 if (lseek (fd
, (length
- 1), SEEK_SET
) < 0)
41 /* Write a "0" byte. */
42 if (write (fd
, "", 1) != 1)
47 /* Truncate length. */
51 fl
.l_type
= F_WRLCK
; /* Write lock on file space. */
53 /* This relies on the UNDOCUMENTED F_FREESP argument to
54 fcntl, which truncates the file so that it ends at the
55 position indicated by fl.l_start.
56 Will minor miracles never cease? */
57 if (fcntl (fd
, F_FREESP
, &fl
) < 0)
65 ftruncate (fd
, length
)
69 return chsize (fd
, length
);