1TRUNCATE(3P)               POSIX Programmer's Manual              TRUNCATE(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       truncate — truncate a file to a specified length
14

SYNOPSIS

16       #include <unistd.h>
17
18       int truncate(const char *path, off_t length);
19

DESCRIPTION

21       The truncate() function shall cause the regular file named by  path  to
22       have a size which shall be equal to length bytes.
23
24       If  the  file previously was larger than length, the extra data is dis‐
25       carded. If the file was previously shorter than  length,  its  size  is
26       increased, and the extended area appears as if it were zero-filled.
27
28       The  application shall ensure that the process has write permission for
29       the file.
30
31       If the request would cause the file size to exceed the soft  file  size
32       limit  for  the  process, the request shall fail and the implementation
33       shall generate the SIGXFSZ signal for the process.
34
35       The truncate() function shall not modify the file offset for  any  open
36       file descriptions associated with the file. Upon successful completion,
37       if the file size is changed, truncate() shall mark for update the  last
38       data  modification  and last file status change timestamps of the file,
39       and the S_ISUID and S_ISGID bits of the file mode may be cleared.
40

RETURN VALUE

42       Upon successful completion, truncate() shall return  0.  Otherwise,  −1
43       shall be returned, and errno set to indicate the error.
44

ERRORS

46       The truncate() function shall fail if:
47
48       EINTR  A signal was caught during execution.
49
50       EINVAL The length argument was less than 0.
51
52       EFBIG or EINVAL
53              The length argument was greater than the maximum file size.
54
55       EIO    An  I/O  error  occurred while reading from or writing to a file
56              system.
57
58       EACCES A component of the path  prefix  denies  search  permission,  or
59              write permission is denied on the file.
60
61       EISDIR The named file is a directory.
62
63       ELOOP  A loop exists in symbolic links encountered during resolution of
64              the path argument.
65
66       ENAMETOOLONG
67              The  length  of  a  component  of  a  pathname  is  longer  than
68              {NAME_MAX}.
69
70       ENOENT A component of path does not name an existing file or path is an
71              empty string.
72
73       ENOTDIR
74              A component of the path prefix names an existing  file  that  is
75              neither  a  directory nor a symbolic link to a directory, or the
76              path argument contains at least one  non-<slash>  character  and
77              ends  with  one or more trailing <slash> characters and the last
78              pathname component names an existing  file  that  is  neither  a
79              directory nor a symbolic link to a directory.
80
81       EROFS  The named file resides on a read-only file system.
82
83       The truncate() function may fail if:
84
85       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
86              resolution of the path argument.
87
88       ENAMETOOLONG
89              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
90              tion  of  a symbolic link produced an intermediate result with a
91              length that exceeds {PATH_MAX}.
92
93       The following sections are informative.
94

EXAMPLES

96       None.
97

APPLICATION USAGE

99       None.
100

RATIONALE

102       None.
103

FUTURE DIRECTIONS

105       None.
106

SEE ALSO

108       open()
109
110       The Base Definitions volume of POSIX.1‐2008, <unistd.h>
111
113       Portions of this text are reprinted and reproduced in  electronic  form
114       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
115       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
116       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
117       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
118       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
119       event of any discrepancy between this version and the original IEEE and
120       The  Open Group Standard, the original IEEE and The Open Group Standard
121       is the referee document. The original Standard can be  obtained  online
122       at http://www.unix.org/online.html .
123
124       Any  typographical  or  formatting  errors that appear in this page are
125       most likely to have been introduced during the conversion of the source
126       files  to  man page format. To report such errors, see https://www.ker
127       nel.org/doc/man-pages/reporting_bugs.html .
128
129
130
131IEEE/The Open Group                  2013                         TRUNCATE(3P)
Impressum