make "mv <file> <non-existent-dir>" print reasonable msg
[unix-history] / usr / src / lib / libc / sys / fcntl.2
CommitLineData
c24fefdc
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
1df601cf 5.\" @(#)fcntl.2 6.2 (Berkeley) %G%
c24fefdc 6.\"
4ef918f1 7.TH FCNTL 2 ""
c24fefdc
KM
8.UC 5
9.SH NAME
10fcntl \- file control
11.SH SYNOPSIS
12.nf
13.ft B
14#include <fcntl.h>
15.PP
16.ft B
17res = fcntl(fd, cmd, arg)
18int res;
19int fd, cmd, arg;
20.ft R
21.SH DESCRIPTION
22.I Fcntl
23provides for control over descriptors.
24The argument
25.I fd
26is a descriptor to be operated on by
27.I cmd
28as follows:
29.TP 15
30F_DUPFD
31Return a new descriptor as follows:
32.IP
33Lowest numbered available descriptor greater than or equal to
34.I arg.
35.IP
36Same object references as the original descriptor.
37.IP
38New descriptor shares the same file pointer if the object
39was a file.
40.IP
41Same access mode (read, write or read/write).
42.IP
43Same file status flags (i.e., both file descriptors
44share the same file status flags).
45.IP
46The close-on-exec flag associated with the new file descriptor
47is set to remain open across
48.IR execv (2)
49system calls.
50.TP 15
51F_GETFD
52Get the close-on-exec flag associated with the file descriptor
53.IR fd .
54If the low-order bit is 0, the file will remain open across
55.IR exec ,
56otherwise the file will be closed upon execution of
57.I exec.
58.TP 15
59F_SETFD
60Set the close-on-exec flag associated with
61.I fd
62to the low order bit of
63.I arg
64(0 or 1 as above).
65.TP 15
66F_GETFL
67Get descriptor status flags, as described below.
68.TP 15
69F_SETFL
70Set descriptor status flags.
71.TP 15
72F_GETOWN
73Get the process ID or process group
74currently receiving SIGIO and SIGURG
75signals; process groups are returned
76as negative values.
77.TP
78F_SETOWN
79Set the process or process group
80to receive SIGIO and SIGURG signals;
81process groups are specified by supplying
82.I arg
83as negative, otherwise
84.I arg
85is interpreted as a process ID.
86.LP
87The flags for the F_GETFL and F_SETFL flags are as follows:
88.TP 15
89FNDELAY
90Non-blocking I/O; if no data is available to a
91.I read
92call, or if a write operation would block,
93the call returns -1 with the error EWOULDBLOCK.
94.TP
95FAPPEND
96Force each write to append at the end of file;
97corresponds to the O_APPEND flag of
98.IR open (2).
99.TP
100FASYNC
101Enable the SIGIO signal to be sent to the process group
102when I/O is possible, e.g.
103upon availability of data to be read.
104.SH "RETURN VALUE
105Upon successful completion, the value returned depends on
106.I cmd
107as follows:
108.sp .5v
109.nf
110.ta .25i 1.25i
111 F_DUPFD A new file descriptor.
112 F_GETFD Value of flag (only the low-order bit is defined).
113 F_GETFL Value of flags.
114 F_GETOWN Value of file descriptor owner.
115 other Value other than \-1.
116.fi
117.sp .5v
118Otherwise, a value of \-1 is returned and
119.I errno
120is set to indicate the error.
121.SH ERRORS
122.I Fcntl
123will fail if one or more of the following are true:
124.TP 15
125[EBADF]
126.I Fildes
127is not a valid open file descriptor.
128.TP 15
129[EMFILE]
130.I Cmd
131is F_DUPFD and the maximum allowed number of file descriptors are currently
132open.
133.TP 15
134[EINVAL]
135.I Cmd
136is F_DUPFD and
137.I arg
138is negative or greater the maximum allowable number
139(see
140.IR getdtablesize (2)).
141.SH "SEE ALSO
142close(2), execve(2), getdtablesize(2), open(2), sigvec(2)
143.SH BUGS
144The asynchronous I/O facilities of FNDELAY and FASYNC
1df601cf 145are currently available only for tty and socket operations.