fixed the under development line
[unix-history] / usr / src / lib / libc / sys / truncate.2
CommitLineData
15715acc
KB
1.\" Copyright (c) 1983, 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
813c5fba 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
88b3ccf2 5.\"
15715acc 6.\" @(#)truncate.2 8.1 (Berkeley) %G%
813c5fba 7.\"
931b8415
CL
8.Dd
9.Dt TRUNCATE 2
10.Os BSD 4.2
11.Sh NAME
12.Nm truncate ,
13.Nm ftruncate
14.Nd truncate a file to a specified length
15.Sh SYNOPSIS
16.Fd #include <unistd.h>
17.Ft int
18.Fn truncate "const char *path" "off_t length"
19.Ft int
20.Fn ftruncate "int fd" "off_t length"
21.Sh DESCRIPTION
22.Fn Truncate
813c5fba 23causes the file named by
931b8415 24.Fa path
813c5fba 25or referenced by
931b8415 26.Fa fd
813c5fba 27to be truncated to at most
931b8415 28.Fa length
813c5fba
KM
29bytes in size. If the file previously
30was larger than this size, the extra data
31is lost.
32With
931b8415 33.Fn ftruncate ,
813c5fba 34the file must be open for writing.
931b8415 35.Sh RETURN VALUES
813c5fba 36A value of 0 is returned if the call succeeds. If the call
931b8415
CL
37fails a -1 is returned, and the global variable
38.Va errno
813c5fba 39specifies the error.
931b8415
CL
40.Sh ERRORS
41.Fn Truncate
813c5fba 42succeeds unless:
931b8415
CL
43.Bl -tag -width [ENOTDIR]
44.It Bq Er ENOTDIR
b5984ffe 45A component of the path prefix is not a directory.
931b8415 46.It Bq Er EINVAL
b5984ffe 47The pathname contains a character with the high-order bit set.
931b8415 48.It Bq Er ENAMETOOLONG
b5984ffe
KM
49A component of a pathname exceeded 255 characters,
50or an entire path name exceeded 1023 characters.
931b8415 51.It Bq Er ENOENT
813c5fba 52The named file does not exist.
931b8415 53.It Bq Er EACCES
b5984ffe 54Search permission is denied for a component of the path prefix.
931b8415 55.It Bq Er EACCES
234f27d4 56The named file is not writable by the user.
931b8415 57.It Bq Er ELOOP
b5984ffe 58Too many symbolic links were encountered in translating the pathname.
931b8415 59.It Bq Er EISDIR
813c5fba 60The named file is a directory.
931b8415 61.It Bq Er EROFS
813c5fba 62The named file resides on a read-only file system.
931b8415 63.It Bq Er ETXTBSY
813c5fba 64The file is a pure procedure (shared text) file that is being executed.
931b8415 65.It Bq Er EIO
b5984ffe 66An I/O error occurred updating the inode.
931b8415
CL
67.It Bq Er EFAULT
68.Fa Path
813c5fba 69points outside the process's allocated address space.
931b8415
CL
70.El
71.Pp
72.Fn Ftruncate
813c5fba 73succeeds unless:
931b8415
CL
74.Bl -tag -width [ENOTDIR]
75.It Bq Er EBADF
813c5fba 76The
931b8415 77.Fa fd
813c5fba 78is not a valid descriptor.
931b8415 79.It Bq Er EINVAL
813c5fba 80The
931b8415 81.Fa fd
813c5fba 82references a socket, not a file.
931b8415 83.It Bq Er EINVAL
234f27d4 84The
931b8415 85.Fa fd
234f27d4 86is not open for writing.
931b8415
CL
87.El
88.Sh SEE ALSO
89.Xr open 2
90.Sh BUGS
813c5fba
KM
91These calls should be generalized to allow ranges
92of bytes in a file to be discarded.
931b8415
CL
93.Sh HISTORY
94The
95.Nm
96function call appeared in
97.Bx 4.2 .