xref: /freebsd-12.1/lib/libc/sys/ioctl.2 (revision 7d0fc2f4)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)ioctl.2	8.2 (Berkeley) 12/11/93
33.\"
34.\" $FreeBSD$
35.\"
36.Dd December 11, 1993
37.Dt IOCTL 2
38.Os
39.Sh NAME
40.Nm ioctl
41.Nd control device
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.In sys/ioctl.h
46.Ft int
47.Fn ioctl "int d" "unsigned long request" ...
48.Sh DESCRIPTION
49The
50.Fn ioctl
51system call manipulates the underlying device parameters of special files.
52In particular, many operating
53characteristics of character special files (e.g.\& terminals)
54may be controlled with
55.Fn ioctl
56requests.
57The argument
58.Fa d
59must be an open file descriptor.
60.Pp
61The third argument to
62.Fn ioctl
63is traditionally named
64.Va "char *argp" .
65Most uses of
66.Fn ioctl
67in
68.Fx 3.0 ,
69however, require the third argument to be a
70.Vt caddr_t
71or an
72.Vt int .
73.Pp
74An
75.Fn ioctl
76.Fa request
77has encoded in it whether the argument is an
78.Dq in
79argument
80or
81.Dq out
82argument, and the size of the argument
83.Fa argp
84in bytes.
85Macros and defines used in specifying an ioctl
86.Fa request
87are located in the file
88.In sys/ioctl.h .
89.Sh RETURN VALUES
90If an error has occurred, a value of -1 is returned and
91.Va errno
92is set to indicate the error.
93.Sh ERRORS
94The
95.Fn ioctl
96system call
97will fail if:
98.Bl -tag -width Er
99.It Bq Er EBADF
100The
101.Fa d
102argument
103is not a valid descriptor.
104.It Bq Er ENOTTY
105The
106.Fa d
107argument
108is not associated with a character
109special device.
110.It Bq Er ENOTTY
111The specified request does not apply to the kind
112of object that the descriptor
113.Fa d
114references.
115.It Bq Er EINVAL
116The
117.Fa request
118or
119.Fa argp
120argument
121is not valid.
122.It Bq Er EFAULT
123The
124.Fa argp
125argument
126points outside the process's allocated address space.
127.El
128.Sh SEE ALSO
129.Xr execve 2 ,
130.Xr fcntl 2 ,
131.Xr intro 4 ,
132.Xr tty 4
133.Sh HISTORY
134The
135.Fn ioctl
136function appeared in
137.At v7 .
138