]> git.ipfire.org Git - thirdparty/gcc.git/blob - libphobos/libdruntime/core/sys/posix/sys/ioccom.d
libphobos: Merge upstream druntime 94686651
[thirdparty/gcc.git] / libphobos / libdruntime / core / sys / posix / sys / ioccom.d
1 /**
2 * D header file for POSIX.
3 *
4 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
5 */
6
7 module core.sys.posix.sys.ioccom;
8
9 version (Posix):
10
11 nothrow @nogc:
12
13 version (OSX)
14 {
15 /* OSX ioctl's (based on FreeBSD) encode the command in the lower 16-bits
16 * and the size of any in/out parameters in the lower 13 bits of the upper
17 * 16-bits of a 32 bit unsigned integer. The high 3 bits of the upper
18 * 16-bits encode the in/out status of the parameter.
19 */
20 enum uint IOCPARM_MASK = 0x1fff; // parameter length, at most 13 bits
21 uint IOCPARM_LEN(uint x) // to extract the encoded parameter length
22 {
23 return ((x >> 16) & IOCPARM_MASK);
24 }
25 uint IOCBASECMD(uint x) // to extract the encoded command
26 {
27 return (x & ~(IOCPARM_MASK << 16));
28 }
29 uint IOCGROUP(uint x) // to extract the encoded group
30 {
31 return ((x >> 8) & 0xff);
32 }
33
34 enum uint IOCPARM_MAX = (IOCPARM_MASK + 1); // max size of ioctl args
35
36 enum uint IOC_VOID = 0x20000000; // no parameters
37 enum uint IOC_OUT = 0x40000000; // copy parameters back
38 enum uint IOC_IN = 0x80000000; // copy parameters into
39 enum uint IOC_INOUT = (IOC_IN | IOC_OUT); // copy parameter into and get back
40 enum uint IOC_DIRMASK = 0xe0000000; // mask to extract above direction parameters
41
42 // encode the ioctl info into 32 bits
43 uint _IOC(T=typeof(null))(uint inorout, uint group, uint num, size_t len)
44 {
45 return (inorout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num);
46 }
47
48 // encode a command with no parameters
49 uint _IO(char g, int n)
50 {
51 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, cast(size_t)0);
52 }
53 // encode a command that returns info
54 uint _IOR(T)(char g, int n)
55 {
56 return _IOC!(T)(IOC_OUT, cast(uint)g, cast(uint)n, T.sizeof);
57 }
58 // encode a command that takes info
59 uint _IOW(T)(char g, int n)
60 {
61 return _IOC!(T)(IOC_IN, cast(uint)g, cast(uint)n, T.sizeof);
62 }
63 // encode a command that takes info and returns info
64 uint _IOWR(T)(char g, int n)
65 {
66 return _IOC!(T)(IOC_INOUT, cast(uint)g, cast(uint)n, T.sizeof);
67 }
68 }