1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright Sean Kelly 2005 - 2009.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 
10 /*          Copyright Sean Kelly 2005 - 2009.
11  * Distributed under the Boost Software License, Version 1.0.
12  *    (See accompanying file LICENSE or copy at
13  *          http://www.boost.org/LICENSE_1_0.txt)
14  */
15 module core.sys.posix.sys.ipc;
16 
17 import core.sys.posix.config;
18 public import core.sys.posix.sys.types; // for uid_t, gid_t, mode_t, key_t
19 
20 version (OSX)
21     version = Darwin;
22 else version (iOS)
23     version = Darwin;
24 else version (TVOS)
25     version = Darwin;
26 else version (WatchOS)
27     version = Darwin;
28 
29 version (Posix):
30 extern (C) nothrow @nogc:
31 
32 //
33 // XOpen (XSI)
34 //
35 /*
36 struct ipc_perm
37 {
38     uid_t    uid;
39     gid_t    gid;
40     uid_t    cuid;
41     gid_t    cgid;
42     mode_t   mode;
43 }
44 
45 IPC_CREAT
46 IPC_EXCL
47 IPC_NOWAIT
48 
49 IPC_PRIVATE
50 
51 IPC_RMID
52 IPC_SET
53 IPC_STAT
54 */
55 
56 version (linux)
57 {
58     struct ipc_perm
59     {
60         key_t   __key;
61         uid_t   uid;
62         gid_t   gid;
63         uid_t   cuid;
64         gid_t   cgid;
65         ushort  mode;
66         ushort  __pad1;
67         ushort  __seq;
68         ushort  __pad2;
69         c_ulong __unused1;
70         c_ulong __unused2;
71     }
72 
73     enum IPC_CREAT      = 0x0200; // 01000
74     enum IPC_EXCL       = 0x0400; // 02000
75     enum IPC_NOWAIT     = 0x0800; // 04000
76 
77     enum key_t IPC_PRIVATE = 0;
78 
79     enum IPC_RMID       = 0;
80     enum IPC_SET        = 1;
81     enum IPC_STAT       = 2;
82 }
83 else version (Darwin)
84 {
85     align(4) struct ipc_perm
86     {
87         uid_t   uid;
88         gid_t   gid;
89         uid_t   cuid;
90         gid_t   cgid;
91         mode_t  mode;
92         ushort  _seq;
93         key_t   _key;
94     }
95 
96     enum IPC_CREAT      = 0x0200; // 01000
97     enum IPC_EXCL       = 0x0400; // 02000
98     enum IPC_NOWAIT     = 0x0800; // 04000
99 
100     enum key_t IPC_PRIVATE = 0;
101 
102     enum IPC_RMID       = 0;
103     enum IPC_SET        = 1;
104     enum IPC_STAT       = 2;
105 }
106 else version (FreeBSD)
107 {
108     struct ipc_perm_old // <= FreeBSD7
109     {
110         ushort cuid;
111         ushort cguid;
112         ushort uid;
113         ushort gid;
114         ushort mode;
115         ushort seq;
116         key_t key;
117     }
118 
119     struct ipc_perm
120     {
121         uid_t   cuid;
122         gid_t   cgid;
123         uid_t   uid;
124         gid_t   gid;
125         mode_t  mode;
126         ushort  seq;
127         key_t   key;
128     }
129 
130     enum IPC_CREAT      = 0x0200; // 01000
131     enum IPC_EXCL       = 0x0400; // 02000
132     enum IPC_NOWAIT     = 0x0800; // 04000
133 
134     enum key_t IPC_PRIVATE = 0;
135 
136     enum IPC_RMID       = 0;
137     enum IPC_SET        = 1;
138     enum IPC_STAT       = 2;
139 }
140 else version (NetBSD)
141 {
142     struct ipc_perm
143     {
144         uid_t   cuid;
145         gid_t   cgid;
146         uid_t   uid;
147         gid_t   gid;
148         mode_t  mode;
149         ushort  seq;
150         key_t   key;
151     }
152 
153     enum IPC_CREAT      = 0x0100; // 01000
154     enum IPC_EXCL       = 0x0200; // 02000
155     enum IPC_NOWAIT     = 0x0400; // 04000
156 
157     enum key_t IPC_PRIVATE = 0;
158 
159     enum IPC_RMID       = 0;
160     enum IPC_SET        = 1;
161     enum IPC_STAT       = 2;
162 }
163 else version (OpenBSD)
164 {
165     struct ipc_perm
166     {
167         uid_t   cuid;
168         gid_t   cgid;
169         uid_t   uid;
170         gid_t   gid;
171         mode_t  mode;
172         ushort  seq;
173         key_t   key;
174     }
175 
176     enum IPC_CREAT      = 0x0200; // 01000
177     enum IPC_EXCL       = 0x0400; // 02000
178     enum IPC_NOWAIT     = 0x0800; // 04000
179 
180     enum key_t IPC_PRIVATE = 0;
181 
182     enum IPC_RMID       = 0;
183     enum IPC_SET        = 1;
184     enum IPC_STAT       = 2;
185 }
186 else version (DragonFlyBSD)
187 {
188     struct ipc_perm
189     {
190         uid_t   cuid;
191         gid_t   cgid;
192         uid_t   uid;
193         gid_t   gid;
194         mode_t  mode;
195         ushort  seq;
196         key_t   key;
197     }
198 
199     enum IPC_CREAT      = 0x0200; // 01000
200     enum IPC_EXCL       = 0x0400; // 02000
201     enum IPC_NOWAIT     = 0x0800; // 04000
202 
203     enum key_t IPC_PRIVATE = 0;
204 
205     enum IPC_RMID       = 0;
206     enum IPC_SET        = 1;
207     enum IPC_STAT       = 2;
208 }
209 else version (Solaris)
210 {
211     version (D_LP64)
212     {
213         struct ipc_perm
214         {
215             uid_t   uid;
216             gid_t   gid;
217             uid_t   cuid;
218             gid_t   cgid;
219             mode_t  mode;
220             uint    seq;
221             key_t   key;
222         }
223     }
224     else
225     {
226         struct ipc_perm
227         {
228             uid_t   uid;
229             gid_t   gid;
230             uid_t   cuid;
231             gid_t   cgid;
232             mode_t  mode;
233             uint    seq;
234             key_t   key;
235             int[4] pad;
236         }
237     }
238 
239     enum IPC_CREAT      = 0x200;
240     enum IPC_EXCL       = 0x400;
241     enum IPC_NOWAIT     = 0x800;
242 
243     enum key_t IPC_PRIVATE = 0;
244 
245     enum IPC_RMID       = 10;
246     enum IPC_SET        = 11;
247     enum IPC_STAT       = 12;
248 }
249 else
250 {
251     static assert(false, "Unsupported platform");
252 }
253 
254 /*
255 key_t ftok(const scope char*, int);
256 */
257 
258 version (CRuntime_Glibc)
259 {
260     key_t ftok(const scope char*, int);
261 }
262 else version (Darwin)
263 {
264     key_t ftok(const scope char*, int);
265 }
266 else version (FreeBSD)
267 {
268     key_t ftok(const scope char*, int);
269 }
270 else version (NetBSD)
271 {
272     key_t ftok(const scope char*, int);
273 }
274 else version (OpenBSD)
275 {
276     key_t ftok(const scope char*, int);
277 }
278 else version (DragonFlyBSD)
279 {
280     key_t ftok(const scope char*, int);
281 }
282 else version (Solaris)
283 {
284     key_t ftok(const scope char*, int);
285 }
286 else version (CRuntime_Bionic)
287 {
288     key_t ftok(const scope char*, int);
289 }
290 else version (CRuntime_Musl)
291 {
292     key_t ftok(const scope char*, int);
293 }
294 else version (CRuntime_UClibc)
295 {
296     key_t ftok(const scope char*, int);
297 }
298 else
299 {
300     static assert(false, "Unsupported platform");
301 }