TRUNCATE(2) COMMAND REFERENCE TRUNCATE(2)
NAME
truncate, ftruncate - truncate a file to a specified length
SYNOPSIS
truncate(path, length)
char *path;
long length;
ftruncate(fd, length)
int fd, long length;
DESCRIPTION
Truncate causes the file named by path or referenced by fd
to be truncated to at most length bytes in size. If the
file previously was larger than this size, the extra data is
lost. With ftruncate, the file must be open for writing.
DIAGNOSTICS
Truncate succeeds unless:
[ENOASCII]
The pathname contains a character with the high-order
bit set.
[ENAMETOOLONG]
The pathname path is too long.
[ENOTDIR]
A component of the path prefix of path is not a
directory.
[EIO]
An I/O error occurred while reading from or writing to
the file system.
[ENOENT]
The named file path does not exist.
[EACCES]
A component of the path prefix of path denies search
permission.
[EACCES]
Write permission is denied for path.
[EACCES]
If the file is located on a remote host, this error code
will be returned if the local host name and local user
name does not appear in /usr/lib/dfs/access on the
remote machine. See access(dfs)(5n).
[EISDIR]
Printed 10/17/86 1
TRUNCATE(2) COMMAND REFERENCE TRUNCATE(2)
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.
[ELOOP]
Too many symbolic links were encourntered in translating
the pathname.
[EINVAL]
Length value given was negative.
[EDFSNOSUCHHOST]
The pathname referenced a remote host, but when we
broadcast a request for its address, no host responded.
Ftruncate succeeds unless:
[EBADF]
Fd is not a valid descriptor.
[EACCES]
Write permission is denied for the file referenced by
fd.
[EINVAL]
Fd references a socket, not a file.
[EROFS]
Fd resides on a read-only file system.
[EINVAL]
Length value given was negative.
RETURN VALUE
Upon successful completion, a value of 0 is returned.
Otherwise, a value of -1 is returned and errno is set to
indicate the error.
CAVEATS
Partial blocks discarded as the result of truncation are not
zero filled; this can result in holes in files which do not
read as zero.
Printed 10/17/86 2
TRUNCATE(2) COMMAND REFERENCE TRUNCATE(2)
These calls should be generalized to allow ranges of bytes
in a file to be discarded.
SEE ALSO
open(2).
Printed 10/17/86 3
%%index%%
na:72,95;
sy:167,649;
de:816,460;
di:1276,1079;2499,1055;
rv:3554,236;
ca:3790,201;4135,97;
se:4232,122;
%%index%%000000000138