truncate(2)
NAME
truncate, ftruncate − truncate a file to a specified length
SYNOPSIS
#include <unistd.h>
int truncate(const char *path, size_t length);
int ftruncate(int fildes, size_t length);
DESCRIPTION
truncate() causes the file named by path or referenced by fd to have a size of length bytes. If the file previously was larger than this size, the extra data is lost. If it was previously shorter, bytes between the old and new lengths are read as zeroes. With ftruncate(), the file must be open for writing; for truncate() the user must have write permission for the file.
RETURN VALUES
truncate() returns a value of 0 if successful; otherwise a −1 is returned, and errno is set to indicate the error.
ERRORS
truncate() fails if any of the following conditions are encountered:
[ENOTDIR] A component of the path prefix of path is not a directory.
[EACCES] A component of the path prefix denies search permission.
[EACCES] Write permission is denied on the file.
[EINVAL] length was greater than the maximum file size.
[EISDIR] The named file is a directory.
[EROFS] The named file resides on a read-only file system.
[ETXTBSY] The file is a pure procedure (shared text) file that is being executed.
[EFAULT] path points outside the process’s allocated address space. The reliable detection of this error is implementation dependent.
[ELOOP] Too many symbolic links were encountered in translating the path name.
[ENAMETOOLONG]
The length of the specified path name exceeds PATH_MAX bytes, or the length of a component of the path name exceeds NAME_MAX bytes while _POSIX_NO_TRUNC is in effect.
[EDQUOT] User’s disk quota block limit has been reached for this file system.
ftruncate () fails if any of the following conditions are encountered:
[EBADF] fd is not a valid file descriptor.
[EINVAL] fd references a file that was opened without write permission.
[EDQUOT] User’s disk quota block limit has been reached for this file system.
AUTHOR
truncate() was developed by the University of California, Berkeley.
SEE ALSO
STANDARDS CONFORMANCE
truncate(): AES
ftruncate(): AES
Hewlett-Packard Company — HP-UX Release 9.0: August 1992