1TRUNCATE(2)                   System Calls Manual                  TRUNCATE(2)
2
3
4

NAME

6       truncate - truncate a file to a specified length
7

SYNOPSIS

9       truncate(path, length)
10       char *path;
11       off_t length;
12
13       ftruncate(fd, length)
14       int fd;
15       off_t length;
16

DESCRIPTION

18       Truncate  causes the file named by path or referenced by fd to be trun‐
19       cated to at most length bytes in size.   If  the  file  previously  was
20       larger  than  this  size,  the extra data is lost.  With ftruncate, the
21       file must be open for writing.
22

RETURN VALUES

24       A value of 0 is returned if the call succeeds.  If the call fails a  -1
25       is returned, and the global variable errno specifies the error.
26

ERRORS

28       Truncate succeeds unless:
29
30       [ENOTDIR]      A component of the path prefix is not a directory.
31
32       [EINVAL]       The  pathname  contains  a character with the high-order
33                      bit set.
34
35       [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an
36                      entire path name exceeded 1023 characters.
37
38       [ENOENT]       The named file does not exist.
39
40       [EACCES]       Search  permission is denied for a component of the path
41                      prefix.
42
43       [EACCES]       The named file is not writable by the user.
44
45       [ELOOP]        Too many symbolic links were encountered in  translating
46                      the pathname.
47
48       [EISDIR]       The named file is a directory.
49
50       [EROFS]        The named file resides on a read-only file system.
51
52       [ETXTBSY]      The  file is a pure procedure (shared text) file that is
53                      being executed.
54
55       [EIO]          An I/O error occurred updating the inode.
56
57       [EFAULT]       Path points  outside  the  process's  allocated  address
58                      space.
59
60       Ftruncate succeeds unless:
61
62       [EBADF]        The fd is not a valid descriptor.
63
64       [EINVAL]       The fd references a socket, not a file.
65
66       [EINVAL]       The fd is not open for writing.
67

SEE ALSO

69       open(2)
70

BUGS

72       These calls should be generalized to allow ranges of bytes in a file to
73       be discarded.
74
75
76
774.2 Berkeley Distribution       March 29, 1986                     TRUNCATE(2)
Impressum