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