truncate(2) DG/UX 5.4 Rel. 2.01 truncate(2)
NAME
truncate - truncate a file to a specified length
SYNOPSIS
#include <unistd.h>
int truncate (path, length)
char * path;
long length;
where:
path Address of a pathname
length Maximum length of file after truncation
DESCRIPTION
Truncate causes the file named by path to be truncated to at most
length bytes in size. If path refers to a symbolic link, the target
of the symbolic link is truncated.
The subject file must reside on a file system device mounted read-
write. Also, it must not be a directory. If mandatory locking is
enabled on the file, truncate waits until all locks on the file are
cleared.
If an error occurs, no changes occur. Otherwise, the subject file is
changed with the following consequences:
⊕ For files of type `ordinary-disk-file', if the file's size is
greater than length bytes, it is truncated to that length, and
the file's size is updated. If the file's size is less than
length bytes, the file is lengthened by appending null bytes
and the file's size is updated.
⊕ If file is not of type `ordinary-disk-file', neither its
contents nor its size are altered.
⊕ The `time-last-modified' and `time-last-changed' attributes
are set to the current time. These attributes are changed
even if there is no change to the file's contents.
ACCESS CONTROL
The calling process must have permission to resolve path.
The calling process must have write access to the file.
RETURN VALUE
0 The file was successfully truncated.
-1 An error occurred. errno is set to indicate the error.
DIAGNOSTICS
Errno may be set to one of the following error codes:
Licensed material--property of copyright holder(s) 1
truncate(2) DG/UX 5.4 Rel. 2.01 truncate(2)
EACCES Write permission is denied for the named file.
EISDIR The named file is a directory.
EROFS The named file resides on a file system device mounted
read-only.
ENOENT The file the pathname resolved to does not exist.
ENOENT A non-terminal component of the pathname does not
exist.
ENOTDIR A non-terminal component of the pathname was not a
directory or symbolic link.
ENAMETOOLONG The pathname exceeds the length limit for pathnames.
ENAMETOOLONG A component of the pathname exceeds the length limit
for filenames.
ENOMEM There are not enough system resources to resolve the
pathname or to expand a symbolic link.
ELOOP The number of symbolic links encountered during
pathname resolution exceeded MAXSYMLINKS. A symbolic
link cycle is suspected.
EPERM The pathname contains a character not in the allowed
character set.
EFAULT The pathname does not completely reside in the
process's address space or the pathname does not
terminate in the process's address space.
EINTR The truncate system call was interrupted while waiting
for a mandatory record lock to clear.
SEE ALSO
creat(2), open(2), ftruncate(3C).
STANDARDS
When using m88kbcs as the Software Development Environment target,
the truncate function will be emulated using BCS system calls. Since
this emulation uses the open system call, a failure will occur if
all file descriptors are in use. In this case, errno will be set to
EMFILE. Also, since this is an emulation requiring several BCS
system calls, a slight performance degradation may be noticed in
comparison to using truncate in /lib/libc.a.
Licensed material--property of copyright holder(s) 2