d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.
[official-gcc.git] / libphobos / libdruntime / core / sys / posix / sys / ioccom.d
blob36917653e3c951b6c507b1f056cecb4f221c7c04
1 /**
2 * D header file for POSIX.
4 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
5 */
7 module core.sys.posix.sys.ioccom;
9 version (OSX)
10 version = Darwin;
11 else version (iOS)
12 version = Darwin;
13 else version (TVOS)
14 version = Darwin;
15 else version (WatchOS)
16 version = Darwin;
18 version (Posix):
20 nothrow @nogc:
22 version (Darwin)
24 /* OSX ioctl's (based on FreeBSD) encode the command in the lower 16-bits
25 * and the size of any in/out parameters in the lower 13 bits of the upper
26 * 16-bits of a 32 bit unsigned integer. The high 3 bits of the upper
27 * 16-bits encode the in/out status of the parameter.
29 enum uint IOCPARM_MASK = 0x1fff; // parameter length, at most 13 bits
30 uint IOCPARM_LEN(uint x) // to extract the encoded parameter length
32 return ((x >> 16) & IOCPARM_MASK);
34 uint IOCBASECMD(uint x) // to extract the encoded command
36 return (x & ~(IOCPARM_MASK << 16));
38 uint IOCGROUP(uint x) // to extract the encoded group
40 return ((x >> 8) & 0xff);
43 enum uint IOCPARM_MAX = (IOCPARM_MASK + 1); // max size of ioctl args
45 enum uint IOC_VOID = 0x20000000; // no parameters
46 enum uint IOC_OUT = 0x40000000; // copy parameters back
47 enum uint IOC_IN = 0x80000000; // copy parameters into
48 enum uint IOC_INOUT = (IOC_IN | IOC_OUT); // copy parameter into and get back
49 enum uint IOC_DIRMASK = 0xe0000000; // mask to extract above direction parameters
51 // encode the ioctl info into 32 bits
52 uint _IOC(T=typeof(null))(uint inorout, uint group, uint num, size_t len)
54 return (inorout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num);
57 // encode a command with no parameters
58 uint _IO(char g, int n)
60 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, cast(size_t)0);
62 // encode a command that returns info
63 uint _IOR(T)(char g, int n)
65 return _IOC!(T)(IOC_OUT, cast(uint)g, cast(uint)n, T.sizeof);
67 // encode a command that takes info
68 uint _IOW(T)(char g, int n)
70 return _IOC!(T)(IOC_IN, cast(uint)g, cast(uint)n, T.sizeof);
72 // encode a command that takes info and returns info
73 uint _IOWR(T)(char g, int n)
75 return _IOC!(T)(IOC_INOUT, cast(uint)g, cast(uint)n, T.sizeof);
78 else version (FreeBSD)
80 /* FreeBSD ioctl's encode the command in the lower 16-bits
81 * and the size of any in/out parameters in the lower 13 bits of the upper
82 * 16-bits of a 32 bit unsigned integer. The high 3 bits of the upper
83 * 16-bits encode the in/out status of the parameter.
85 enum uint IOCPARM_SHIFT = 13; // number of bits for ioctl size
86 enum uint IOCPARM_MASK = ((1 << IOCPARM_SHIFT) - 1); // parameter length mask
87 uint IOCPARM_LEN(uint x) // to extract the encoded parameter length
89 return ((x >> 16) & IOCPARM_MASK);
91 uint IOCBASECMD(uint x) // to extract the encoded command
93 return (x & ~(IOCPARM_MASK << 16));
95 uint IOCGROUP(uint x) // to extract the encoded group
97 return ((x >> 8) & 0xff);
100 enum uint IOCPARM_MAX = (1 << IOCPARM_SHIFT); // max size of ioctl args
102 enum uint IOC_VOID = 0x20000000; // no parameters
103 enum uint IOC_OUT = 0x40000000; // copy parameters back
104 enum uint IOC_IN = 0x80000000; // copy parameters into
105 enum uint IOC_INOUT = (IOC_IN | IOC_OUT);
106 enum uint IOC_DIRMASK = (IOC_VOID|IOC_OUT|IOC_IN);
108 // encode the ioctl info into 32 bits
109 uint _IOC(uint inorout, uint group, uint num, size_t len)
111 return (inorout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num);
114 // encode a command with no parameters
115 uint _IO(char g, int n)
117 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, cast(size_t)0);
119 uint _IOWINT(char g, int n)
121 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, int.sizeof);
123 // encode a command that returns info
124 uint _IOR(T)(char g, int n)
126 return _IOC(IOC_OUT, cast(uint)g, cast(uint)n, T.sizeof);
128 // encode a command that takes info
129 uint _IOW(T)(char g, int n)
131 return _IOC(IOC_IN, cast(uint)g, cast(uint)n, T.sizeof);
133 // encode a command that takes info and returns info
134 uint _IOWR(T)(char g, int n)
136 return _IOC(IOC_INOUT, cast(uint)g, cast(uint)n, T.sizeof);
139 else version (OpenBSD)
141 /* OpenBSD ioctl's encode the command in the lower 16-bits
142 * and the size of any in/out parameters in the lower 13 bits of the upper
143 * 16-bits of a 32 bit unsigned integer. The high 3 bits of the upper
144 * 16-bits encode the in/out status of the parameter.
146 enum uint IOCPARM_MASK = 0x1fff; // parameter length mask
147 uint IOCPARM_LEN(uint x) // to extract the encoded parameter length
149 return ((x >> 16) & IOCPARM_MASK);
151 uint IOCBASECMD(uint x) // to extract the encoded command
153 return (x & ~(IOCPARM_MASK << 16));
155 uint IOCGROUP(uint x) // to extract the encoded group
157 return ((x >> 8) & 0xff);
160 enum uint IOCPARM_MAX = (1 << 12); // max size of ioctl args
162 enum uint IOC_VOID = 0x20000000; // no parameters
163 enum uint IOC_OUT = 0x40000000; // copy parameters back
164 enum uint IOC_IN = 0x80000000; // copy parameters into
165 enum uint IOC_INOUT = (IOC_IN | IOC_OUT);
166 enum uint IOC_DIRMASK = 0xe0000000;
168 // encode the ioctl info into 32 bits
169 uint _IOC(uint inorout, uint group, uint num, size_t len)
171 return (inorout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num);
174 // encode a command with no parameters
175 uint _IO(char g, int n)
177 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, cast(size_t)0);
179 // encode a command that returns info
180 uint _IOR(T)(char g, int n)
182 return _IOC(IOC_OUT, cast(uint)g, cast(uint)n, T.sizeof);
184 // encode a command that takes info
185 uint _IOW(T)(char g, int n)
187 return _IOC(IOC_IN, cast(uint)g, cast(uint)n, T.sizeof);
189 // encode a command that takes info and returns info
190 uint _IOWR(T)(char g, int n)
192 return _IOC(IOC_INOUT, cast(uint)g, cast(uint)n, T.sizeof);