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

NAME

6       truncate - truncate a file to a specified length
7

SYNOPSIS

9       #include <unistd.h>
10
11       int truncate(const char *path, off_t length);
12
13

DESCRIPTION

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

RETURN VALUE

36       Upon  successful  completion,  truncate() shall return 0. Otherwise, -1
37       shall be returned, and errno set to indicate the error.
38

ERRORS

40       The truncate() function shall fail if:
41
42       EINTR  A signal was caught during execution.
43
44       EINVAL The length argument was less than 0.
45
46       EFBIG or EINVAL
47              The length argument was greater than the maximum file size.
48
49       EIO    An I/O error occurred while reading from or writing  to  a  file
50              system.
51
52       EACCES A  component  of  the  path  prefix denies search permission, or
53              write permission is denied on the file.
54
55       EISDIR The named file is a directory.
56
57       ELOOP  A loop exists in symbolic links encountered during resolution of
58              the path argument.
59
60       ENAMETOOLONG
61              The length of the path argument exceeds {PATH_MAX} or a pathname
62              component is longer than {NAME_MAX}.
63
64       ENOENT A component of path does not name an existing file or path is an
65              empty string.
66
67       ENOTDIR
68              A component of the path prefix of path is not a directory.
69
70       EROFS  The named file resides on a read-only file system.
71
72
73       The truncate() function may fail if:
74
75       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
76              resolution of the path argument.
77
78       ENAMETOOLONG
79              Pathname resolution of a symbolic link produced an  intermediate
80              result whose length exceeds {PATH_MAX}.
81
82
83       The following sections are informative.
84

EXAMPLES

86       None.
87

APPLICATION USAGE

89       None.
90

RATIONALE

92       None.
93

FUTURE DIRECTIONS

95       None.
96

SEE ALSO

98       open()   ,   the   Base  Definitions  volume  of  IEEE Std 1003.1-2001,
99       <unistd.h>
100
102       Portions of this text are reprinted and reproduced in  electronic  form
103       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
104       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
105       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
106       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
107       event of any discrepancy between this version and the original IEEE and
108       The Open Group Standard, the original IEEE and The Open Group  Standard
109       is  the  referee document. The original Standard can be obtained online
110       at http://www.opengroup.org/unix/online.html .
111
112
113
114IEEE/The Open Group                  2003                          TRUNCATE(P)
Impressum