FAT | RFS | XFS
truncate()
PROTOTYPE
#include <posix.h>
int truncate(const char *path, off_t length);
DESCRIPTION
truncate() sets the length of the regular file specified by path to length characters. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD. If the file is extended, ‘\0’ characters are appended.
If zeroing the extended area is unneeded, consider using resize(). It is a non-standard routine that behaves like truncate() except if the file is extended, the extended area is left uninitialized. This can give higher performance.
If the file’s length is changed, its status change and data modification timestamps are updated.
The caller needs search access to the path prefix and write access to the specified file.
If successful, truncate() returns 0. Otherwise, it sets errno and returns -1.
ERROR CODES
| EACCES | No execute access to a directory in the path prefix or no write access to the specified file. |
| EFAULT | path equals NULL. |
| EINVAL | length is negative. |
| EISDIR | The specified file is a directory. |
| ENAMETOOLONG | A name in path exceeds the effective maximum file name length. |
| ENOENT | path is the empty string or includes a file that was not found. |
| ENOSPC | No space is left on volume to write file data. |
| ENOTDIR | One of the non-leaf path components is not a directory. |
| EROFS | The volume is read-only. |
EXAMPLE
if (truncate("/flash/rhello.c", 100))
perror("truncate() failed");