mirror of https://github.com/mkerrisk/man-pages
124 lines
3.6 KiB
Plaintext
124 lines
3.6 KiB
Plaintext
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
|
|
.TH "TRUNCATE" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
.\" truncate
|
|
.SH NAME
|
|
truncate \- truncate a file to a specified length
|
|
.SH SYNOPSIS
|
|
.LP
|
|
\fB#include <unistd.h>
|
|
.br
|
|
.sp
|
|
int truncate(const char *\fP\fIpath\fP\fB, off_t\fP \fIlength\fP\fB);
|
|
\fP
|
|
\fB
|
|
.br
|
|
\fP
|
|
.SH DESCRIPTION
|
|
.LP
|
|
The \fItruncate\fP() function shall cause the regular file named by
|
|
\fIpath\fP to have a size which shall be equal to
|
|
\fIlength\fP bytes.
|
|
.LP
|
|
If the file previously was larger than \fIlength\fP, the extra data
|
|
is discarded. If the file was previously shorter than
|
|
\fIlength\fP, its size is increased, and the extended area appears
|
|
as if it were zero-filled.
|
|
.LP
|
|
The application shall ensure that the process has write permission
|
|
for the file.
|
|
.LP
|
|
If the request would cause the file size to exceed the soft file size
|
|
limit for the process, the request shall fail and the
|
|
implementation shall generate the SIGXFSZ signal for the process.
|
|
.LP
|
|
This function shall not modify the file offset for any open file descriptions
|
|
associated with the file. Upon successful
|
|
completion, if the file size is changed, this function shall mark
|
|
for update the \fIst_ctime\fP and \fIst_mtime\fP fields of the
|
|
file, and the S_ISUID and S_ISGID bits of the file mode may be cleared.
|
|
.SH RETURN VALUE
|
|
.LP
|
|
Upon successful completion, \fItruncate\fP() shall return 0. Otherwise,
|
|
-1 shall be returned, and \fIerrno\fP set to indicate
|
|
the error.
|
|
.SH ERRORS
|
|
.LP
|
|
The \fItruncate\fP() function shall fail if:
|
|
.TP 7
|
|
.B EINTR
|
|
A signal was caught during execution.
|
|
.TP 7
|
|
.B EINVAL
|
|
The \fIlength\fP argument was less than 0.
|
|
.TP 7
|
|
.B EFBIG \fRor\fP EINVAL
|
|
The \fIlength\fP argument was greater than the maximum file size.
|
|
.TP 7
|
|
.B EIO
|
|
An I/O error occurred while reading from or writing to a file system.
|
|
.TP 7
|
|
.B EACCES
|
|
A component of the path prefix denies search permission, or write
|
|
permission is denied on the file.
|
|
.TP 7
|
|
.B EISDIR
|
|
The named file is a directory.
|
|
.TP 7
|
|
.B ELOOP
|
|
A loop exists in symbolic links encountered during resolution of the
|
|
\fIpath\fP argument.
|
|
.TP 7
|
|
.B ENAMETOOLONG
|
|
The length of the \fIpath\fP argument exceeds {PATH_MAX} or a pathname
|
|
component is longer than {NAME_MAX}.
|
|
.TP 7
|
|
.B ENOENT
|
|
A component of \fIpath\fP does not name an existing file or \fIpath\fP
|
|
is an empty string.
|
|
.TP 7
|
|
.B ENOTDIR
|
|
A component of the path prefix of \fIpath\fP is not a directory.
|
|
.TP 7
|
|
.B EROFS
|
|
The named file resides on a read-only file system.
|
|
.sp
|
|
.LP
|
|
The \fItruncate\fP() function may fail if:
|
|
.TP 7
|
|
.B ELOOP
|
|
More than {SYMLOOP_MAX} symbolic links were encountered during resolution
|
|
of the \fIpath\fP argument.
|
|
.TP 7
|
|
.B ENAMETOOLONG
|
|
Pathname resolution of a symbolic link produced an intermediate result
|
|
whose length exceeds {PATH_MAX}.
|
|
.sp
|
|
.LP
|
|
\fIThe following sections are informative.\fP
|
|
.SH EXAMPLES
|
|
.LP
|
|
None.
|
|
.SH APPLICATION USAGE
|
|
.LP
|
|
None.
|
|
.SH RATIONALE
|
|
.LP
|
|
None.
|
|
.SH FUTURE DIRECTIONS
|
|
.LP
|
|
None.
|
|
.SH SEE ALSO
|
|
.LP
|
|
\fIopen\fP() , the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
|
|
\fI<unistd.h>\fP
|
|
.SH COPYRIGHT
|
|
Portions of this text are reprinted and reproduced in electronic form
|
|
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
|
|
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
|
|
Electrical and Electronics Engineers, Inc and The Open Group. In the
|
|
event of any discrepancy between this version and the original IEEE and
|
|
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
is the referee document. The original Standard can be obtained online at
|
|
http://www.opengroup.org/unix/online.html .
|