FAT | RFS | XFS

fresize()

PROTOTYPE

#include <posix.h>

int fresize(int fid, off_t length);

DESCRIPTION

fresize() is a non-standard routine that sets the length of the open regular file identified by fid to length characters. If the file is extended, the extended area is left uninitialized. The file’s current position is set to the end of file.

If the file length is changed, its status change and data modification timestamps are updated.

fresize() can be used in place of ftruncate() for higher performance if zeroing the extended area isn’t required. It is used in Blunk’s implementation of the CIFS network file system protocol, which extends the length of a file to its projected new length immediately before writing data to it.

If successful, fresize() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EBADF fid is not the descriptor of a file open in write or append mode.
EINVAL length is negative.
EISDIR The specified file is a directory.
ENOSPC No space is left on volume to write file data.
ENXIO The volume has been removed.
EROFS The volume is read-only.

EXAMPLE

  /*-------------------------------------------------------------------*/
  /* Create file and extend its length to 5 clusters.                  */
  /*-------------------------------------------------------------------*/
  fid = open("foo.txt", O_RDWR | O_CREAT, 0777);
  if (fid == -1)
    error("open() failed");
  if (fresize(fid, 5 * clust_size))
    error("fresize() failed");