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

NAME

12       truncate — truncate a file to a specified length
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

95       None.
96

APPLICATION USAGE

98       None.
99

RATIONALE

101       None.
102

FUTURE DIRECTIONS

104       None.
105

SEE ALSO

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