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

NAME

6       fcntl - file control
7

SYNOPSIS

9       #include <fcntl.h>
10
11       res = fcntl(fd, cmd, arg)
12       int res;
13       int fd, cmd, arg;
14

DESCRIPTION

16       Fcntl  provides  for  control  over  descriptors.  The argument fd is a
17       descriptor to be operated on by cmd as follows:
18
19       F_DUPFD        Return a new descriptor as follows:
20
21                      Lowest numbered available  descriptor  greater  than  or
22                      equal to arg.
23
24                      Same object references as the original descriptor.
25
26                      New  descriptor  shares  the  same  file  pointer if the
27                      object was a file.
28
29                      Same access mode (read, write or read/write).
30
31                      Same file status  flags  (i.e.,  both  file  descriptors
32                      share the same file status flags).
33
34                      The  close-on-exec  flag  associated  with  the new file
35                      descriptor is set to remain open across execv(2)  system
36                      calls.
37
38       F_GETFD        Get  the  close-on-exec  flag  associated  with the file
39                      descriptor fd.  If the low-order bit is 0, the file will
40                      remain  open  across  exec,  otherwise  the file will be
41                      closed upon execution of exec.
42
43       F_SETFD        Set the close-on-exec flag associated with fd to the low
44                      order bit of arg (0 or 1 as above).
45
46       F_GETFL        Get descriptor status flags, as described below.
47
48       F_SETFL        Set descriptor status flags.
49
50       F_GETOWN       Get  the process ID or process group currently receiving
51                      SIGIO and SIGURG signals; process groups are returned as
52                      negative values.
53
54       F_SETOWN       Set  the  process  or process group to receive SIGIO and
55                      SIGURG signals; process groups are specified by  supply‐
56                      ing  arg  as negative, otherwise arg is interpreted as a
57                      process ID.
58
59       The flags for the F_GETFL and F_SETFL flags are as follows:
60
61       O_NONBLOCK     Non-blocking I/O; if no data  is  available  to  a  read
62                      call,  or  if  a  write  operation would block, the call
63                      returns -1 with the error EWOULDBLOCK.
64
65       O_APPEND       Force each write to append at the end  of  file;  corre‐
66                      sponds to the O_APPEND flag of open(2).
67
68       O_ASYNC        Enable  the SIGIO signal to be sent to the process group
69                      when I/O is possible, e.g., upon availability of data to
70                      be read.
71

RETURN VALUE

73       Upon  successful  completion, the value returned depends on cmd as fol‐
74       lows:
75         F_DUPFD   A new file descriptor.
76         F_GETFD   Value of flag (only the low-order bit is defined).
77         F_GETFL   Value of flags.
78         F_GETOWN  Value of file descriptor owner.
79         other     Value other than -1.
80       Otherwise, a value of -1 is returned and errno is set to  indicate  the
81       error.
82

ERRORS

84       Fcntl will fail if one or more of the following are true:
85
86       [EBADF]        Fildes is not a valid open file descriptor.
87
88       [EMFILE]       Cmd  is  F_DUPFD  and the maximum allowed number of file
89                      descriptors are currently open.
90
91       [EINVAL]       Cmd is F_DUPFD and arg is negative or greater  than  the
92                      maximum allowable number (see getdtablesize(2)).
93
94       [ESRCH]        Cmd  is F_SETOWN and the process ID given as argument is
95                      not in use.
96

SEE ALSO

98       close(2), execve(2), getdtablesize(2), open(2), sigvec(2)
99

BUGS

101       The asynchronous I/O facilities of O_NONBLOCK and O_ASYNC are currently
102       available only for tty and socket operations.
103
104
105
1064.2 Berkeley Distribution        Nov 30, 1994                         FCNTL(2)
Impressum