1TRUNCATE(3P) POSIX Programmer's Manual TRUNCATE(3P)
2
3
4
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
12 truncate - truncate a file to a specified length
13
15 #include <unistd.h>
16
17 int truncate(const char *path, off_t length);
18
19
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 This function shall not modify the file offset for any open file
36 descriptions associated with the file. Upon successful completion, if
37 the file size is changed, this function shall mark for update the
38 st_ctime and st_mtime fields of the file, and the S_ISUID and S_ISGID
39 bits of the file mode may be cleared.
40
42 Upon successful completion, truncate() shall return 0. Otherwise, -1
43 shall be returned, and errno set to indicate the error.
44
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 the path argument exceeds {PATH_MAX} or a pathname
68 component is longer than {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 of path is not a directory.
75
76 EROFS The named file resides on a read-only file system.
77
78
79 The truncate() function may fail if:
80
81 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
82 resolution of the path argument.
83
84 ENAMETOOLONG
85 Pathname resolution of a symbolic link produced an intermediate
86 result whose length exceeds {PATH_MAX}.
87
88
89 The following sections are informative.
90
92 None.
93
95 None.
96
98 None.
99
101 None.
102
104 open(), the Base Definitions volume of IEEE Std 1003.1-2001, <unistd.h>
105
107 Portions of this text are reprinted and reproduced in electronic form
108 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
109 -- Portable Operating System Interface (POSIX), The Open Group Base
110 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
111 Electrical and Electronics Engineers, Inc and The Open Group. In the
112 event of any discrepancy between this version and the original IEEE and
113 The Open Group Standard, the original IEEE and The Open Group Standard
114 is the referee document. The original Standard can be obtained online
115 at http://www.opengroup.org/unix/online.html .
116
117
118
119IEEE/The Open Group 2003 TRUNCATE(3P)