Debian Codegraph @

debian/missing-sources/libc/src/unix/bsd/mod.rs

raw
1 use crate::prelude::*;
2
3 pub type off_t = i64;
4 pub type useconds_t = u32;
5 pub type blkcnt_t = i64;
6 pub type socklen_t = u32;
7 pub type sa_family_t = u8;
8 pub type pthread_t = crate::uintptr_t;
9 pub type nfds_t = c_uint;
10 pub type regoff_t = off_t;
11
12 s! {
13 pub struct sockaddr {
14 pub sa_len: u8,
15 pub sa_family: sa_family_t,
16 pub sa_data: [c_char; 14],
17 }
18
19 pub struct sockaddr_in6 {
20 pub sin6_len: u8,
21 pub sin6_family: sa_family_t,
22 pub sin6_port: crate::in_port_t,
23 pub sin6_flowinfo: u32,
24 pub sin6_addr: crate::in6_addr,
25 pub sin6_scope_id: u32,
26 }
27
28 pub struct passwd {
29 pub pw_name: *mut c_char,
30 pub pw_passwd: *mut c_char,
31 pub pw_uid: crate::uid_t,
32 pub pw_gid: crate::gid_t,
33 pub pw_change: crate::time_t,
34 pub pw_class: *mut c_char,
35 pub pw_gecos: *mut c_char,
36 pub pw_dir: *mut c_char,
37 pub pw_shell: *mut c_char,
38 pub pw_expire: crate::time_t,
39
40 #[cfg(not(any(
41 target_os = "macos",
42 target_os = "ios",
43 target_os = "tvos",
44 target_os = "watchos",
45 target_os = "visionos",
46 target_os = "netbsd",
47 target_os = "openbsd"
48 )))]
49 pub pw_fields: c_int,
50 }
51
52 pub struct ifaddrs {
53 pub ifa_next: *mut ifaddrs,
54 pub ifa_name: *mut c_char,
55 pub ifa_flags: c_uint,
56 pub ifa_addr: *mut crate::sockaddr,
57 pub ifa_netmask: *mut crate::sockaddr,
58 pub ifa_dstaddr: *mut crate::sockaddr,
59 pub ifa_data: *mut c_void,
60 #[cfg(target_os = "netbsd")]
61 pub ifa_addrflags: c_uint,
62 }
63
64 pub struct fd_set {
65 #[cfg(all(
66 target_pointer_width = "64",
67 any(target_os = "freebsd", target_os = "dragonfly")
68 ))]
69 fds_bits: [i64; FD_SETSIZE as usize / 64],
70 #[cfg(not(all(
71 target_pointer_width = "64",
72 any(target_os = "freebsd", target_os = "dragonfly")
73 )))]
74 fds_bits: [i32; FD_SETSIZE as usize / 32],
75 }
76
77 pub struct tm {
78 pub tm_sec: c_int,
79 pub tm_min: c_int,
80 pub tm_hour: c_int,
81 pub tm_mday: c_int,
82 pub tm_mon: c_int,
83 pub tm_year: c_int,
84 pub tm_wday: c_int,
85 pub tm_yday: c_int,
86 pub tm_isdst: c_int,
87 pub tm_gmtoff: c_long,
88 pub tm_zone: *mut c_char,
89 }
90
91 pub struct msghdr {
92 pub msg_name: *mut c_void,
93 pub msg_namelen: crate::socklen_t,
94 pub msg_iov: *mut crate::iovec,
95 pub msg_iovlen: c_int,
96 pub msg_control: *mut c_void,
97 pub msg_controllen: crate::socklen_t,
98 pub msg_flags: c_int,
99 }
100
101 pub struct cmsghdr {
102 pub cmsg_len: crate::socklen_t,
103 pub cmsg_level: c_int,
104 pub cmsg_type: c_int,
105 }
106
107 pub struct fsid_t {
108 __fsid_val: [i32; 2],
109 }
110
111 pub struct if_nameindex {
112 pub if_index: c_uint,
113 pub if_name: *mut c_char,
114 }
115
116 pub struct regex_t {
117 __re_magic: c_int,
118 __re_nsub: size_t,
119 __re_endp: *const c_char,
120 __re_g: *mut c_void,
121 }
122
123 pub struct regmatch_t {
124 pub rm_so: regoff_t,
125 pub rm_eo: regoff_t,
126 }
127
128 pub struct option {
129 pub name: *const c_char,
130 pub has_arg: c_int,
131 pub flag: *mut c_int,
132 pub val: c_int,
133 }
134 pub struct sockaddr_un {
135 pub sun_len: u8,
136 pub sun_family: sa_family_t,
137 pub sun_path: [c_char; 104],
138 }
139
140 pub struct utsname {
141 #[cfg(not(target_os = "dragonfly"))]
142 pub sysname: [c_char; 256],
143 #[cfg(target_os = "dragonfly")]
144 pub sysname: [c_char; 32],
145 #[cfg(not(target_os = "dragonfly"))]
146 pub nodename: [c_char; 256],
147 #[cfg(target_os = "dragonfly")]
148 pub nodename: [c_char; 32],
149 #[cfg(not(target_os = "dragonfly"))]
150 pub release: [c_char; 256],
151 #[cfg(target_os = "dragonfly")]
152 pub release: [c_char; 32],
153 #[cfg(not(target_os = "dragonfly"))]
154 pub version: [c_char; 256],
155 #[cfg(target_os = "dragonfly")]
156 pub version: [c_char; 32],
157 #[cfg(not(target_os = "dragonfly"))]
158 pub machine: [c_char; 256],
159 #[cfg(target_os = "dragonfly")]
160 pub machine: [c_char; 32],
161 }
162 }
163
164 pub const LC_ALL: c_int = 0;
165 pub const LC_COLLATE: c_int = 1;
166 pub const LC_CTYPE: c_int = 2;
167 pub const LC_MONETARY: c_int = 3;
168 pub const LC_NUMERIC: c_int = 4;
169 pub const LC_TIME: c_int = 5;
170 pub const LC_MESSAGES: c_int = 6;
171
172 pub const FIOCLEX: c_ulong = 0x20006601;
173 pub const FIONCLEX: c_ulong = 0x20006602;
174 pub const FIONREAD: c_ulong = 0x4004667f;
175 pub const FIONBIO: c_ulong = 0x8004667e;
176 pub const FIOASYNC: c_ulong = 0x8004667d;
177 pub const FIOSETOWN: c_ulong = 0x8004667c;
178 pub const FIOGETOWN: c_ulong = 0x4004667b;
179
180 pub const PATH_MAX: c_int = 1024;
181 pub const MAXPATHLEN: c_int = PATH_MAX;
182
183 pub const IOV_MAX: c_int = 1024;
184
185 pub const SA_ONSTACK: c_int = 0x0001;
186 pub const SA_SIGINFO: c_int = 0x0040;
187 pub const SA_RESTART: c_int = 0x0002;
188 pub const SA_RESETHAND: c_int = 0x0004;
189 pub const SA_NOCLDSTOP: c_int = 0x0008;
190 pub const SA_NODEFER: c_int = 0x0010;
191 pub const SA_NOCLDWAIT: c_int = 0x0020;
192
193 pub const SS_ONSTACK: c_int = 1;
194 pub const SS_DISABLE: c_int = 4;
195
196 pub const SIGCHLD: c_int = 20;
197 pub const SIGBUS: c_int = 10;
198 pub const SIGUSR1: c_int = 30;
199 pub const SIGUSR2: c_int = 31;
200 pub const SIGCONT: c_int = 19;
201 pub const SIGSTOP: c_int = 17;
202 pub const SIGTSTP: c_int = 18;
203 pub const SIGURG: c_int = 16;
204 pub const SIGIO: c_int = 23;
205 pub const SIGSYS: c_int = 12;
206 pub const SIGTTIN: c_int = 21;
207 pub const SIGTTOU: c_int = 22;
208 pub const SIGXCPU: c_int = 24;
209 pub const SIGXFSZ: c_int = 25;
210 pub const SIGVTALRM: c_int = 26;
211 pub const SIGPROF: c_int = 27;
212 pub const SIGWINCH: c_int = 28;
213 pub const SIGINFO: c_int = 29;
214
215 pub const SIG_SETMASK: c_int = 3;
216 pub const SIG_BLOCK: c_int = 0x1;
217 pub const SIG_UNBLOCK: c_int = 0x2;
218
219 pub const IP_TOS: c_int = 3;
220 pub const IP_MULTICAST_IF: c_int = 9;
221 pub const IP_MULTICAST_TTL: c_int = 10;
222 pub const IP_MULTICAST_LOOP: c_int = 11;
223
224 pub const IPV6_UNICAST_HOPS: c_int = 4;
225 pub const IPV6_MULTICAST_IF: c_int = 9;
226 pub const IPV6_MULTICAST_HOPS: c_int = 10;
227 pub const IPV6_MULTICAST_LOOP: c_int = 11;
228 pub const IPV6_V6ONLY: c_int = 27;
229 pub const IPV6_DONTFRAG: c_int = 62;
230
231 pub const IPTOS_ECN_NOTECT: u8 = 0x00;
232 pub const IPTOS_ECN_MASK: u8 = 0x03;
233 pub const IPTOS_ECN_ECT1: u8 = 0x01;
234 pub const IPTOS_ECN_ECT0: u8 = 0x02;
235 pub const IPTOS_ECN_CE: u8 = 0x03;
236
237 pub const ST_RDONLY: c_ulong = 1;
238
239 pub const SCM_RIGHTS: c_int = 0x01;
240
241 pub const NCCS: usize = 20;
242
243 pub const O_ACCMODE: c_int = 0x3;
244 pub const O_RDONLY: c_int = 0;
245 pub const O_WRONLY: c_int = 1;
246 pub const O_RDWR: c_int = 2;
247 pub const O_APPEND: c_int = 8;
248 pub const O_CREAT: c_int = 512;
249 pub const O_TRUNC: c_int = 1024;
250 pub const O_EXCL: c_int = 2048;
251 pub const O_ASYNC: c_int = 0x40;
252 pub const O_SYNC: c_int = 0x80;
253 pub const O_NONBLOCK: c_int = 0x4;
254 pub const O_NOFOLLOW: c_int = 0x100;
255 pub const O_SHLOCK: c_int = 0x10;
256 pub const O_EXLOCK: c_int = 0x20;
257 pub const O_FSYNC: c_int = O_SYNC;
258 pub const O_NDELAY: c_int = O_NONBLOCK;
259
260 pub const F_GETOWN: c_int = 5;
261 pub const F_SETOWN: c_int = 6;
262
263 pub const F_RDLCK: c_short = 1;
264 pub const F_UNLCK: c_short = 2;
265 pub const F_WRLCK: c_short = 3;
266
267 pub const MNT_RDONLY: c_int = 0x00000001;
268 pub const MNT_SYNCHRONOUS: c_int = 0x00000002;
269 pub const MNT_NOEXEC: c_int = 0x00000004;
270 pub const MNT_NOSUID: c_int = 0x00000008;
271 pub const MNT_ASYNC: c_int = 0x00000040;
272 pub const MNT_EXPORTED: c_int = 0x00000100;
273 pub const MNT_UPDATE: c_int = 0x00010000;
274 pub const MNT_RELOAD: c_int = 0x00040000;
275 pub const MNT_FORCE: c_int = 0x00080000;
276
277 pub const Q_SYNC: c_int = 0x600;
278 pub const Q_QUOTAON: c_int = 0x100;
279 pub const Q_QUOTAOFF: c_int = 0x200;
280
281 pub const TCIOFF: c_int = 3;
282 pub const TCION: c_int = 4;
283 pub const TCOOFF: c_int = 1;
284 pub const TCOON: c_int = 2;
285 pub const TCIFLUSH: c_int = 1;
286 pub const TCOFLUSH: c_int = 2;
287 pub const TCIOFLUSH: c_int = 3;
288 pub const TCSANOW: c_int = 0;
289 pub const TCSADRAIN: c_int = 1;
290 pub const TCSAFLUSH: c_int = 2;
291 pub const VEOF: usize = 0;
292 pub const VEOL: usize = 1;
293 pub const VEOL2: usize = 2;
294 pub const VERASE: usize = 3;
295 pub const VWERASE: usize = 4;
296 pub const VKILL: usize = 5;
297 pub const VREPRINT: usize = 6;
298 pub const VINTR: usize = 8;
299 pub const VQUIT: usize = 9;
300 pub const VSUSP: usize = 10;
301 pub const VDSUSP: usize = 11;
302 pub const VSTART: usize = 12;
303 pub const VSTOP: usize = 13;
304 pub const VLNEXT: usize = 14;
305 pub const VDISCARD: usize = 15;
306 pub const VMIN: usize = 16;
307 pub const VTIME: usize = 17;
308 pub const VSTATUS: usize = 18;
309 pub const _POSIX_VDISABLE: crate::cc_t = 0xff;
310 pub const IGNBRK: crate::tcflag_t = 0x00000001;
311 pub const BRKINT: crate::tcflag_t = 0x00000002;
312 pub const IGNPAR: crate::tcflag_t = 0x00000004;
313 pub const PARMRK: crate::tcflag_t = 0x00000008;
314 pub const INPCK: crate::tcflag_t = 0x00000010;
315 pub const ISTRIP: crate::tcflag_t = 0x00000020;
316 pub const INLCR: crate::tcflag_t = 0x00000040;
317 pub const IGNCR: crate::tcflag_t = 0x00000080;
318 pub const ICRNL: crate::tcflag_t = 0x00000100;
319 pub const IXON: crate::tcflag_t = 0x00000200;
320 pub const IXOFF: crate::tcflag_t = 0x00000400;
321 pub const IXANY: crate::tcflag_t = 0x00000800;
322 pub const IMAXBEL: crate::tcflag_t = 0x00002000;
323 pub const OPOST: crate::tcflag_t = 0x1;
324 pub const ONLCR: crate::tcflag_t = 0x2;
325 pub const OXTABS: crate::tcflag_t = 0x4;
326 pub const ONOEOT: crate::tcflag_t = 0x8;
327 pub const CIGNORE: crate::tcflag_t = 0x00000001;
328 pub const CSIZE: crate::tcflag_t = 0x00000300;
329 pub const CS5: crate::tcflag_t = 0x00000000;
330 pub const CS6: crate::tcflag_t = 0x00000100;
331 pub const CS7: crate::tcflag_t = 0x00000200;
332 pub const CS8: crate::tcflag_t = 0x00000300;
333 pub const CSTOPB: crate::tcflag_t = 0x00000400;
334 pub const CREAD: crate::tcflag_t = 0x00000800;
335 pub const PARENB: crate::tcflag_t = 0x00001000;
336 pub const PARODD: crate::tcflag_t = 0x00002000;
337 pub const HUPCL: crate::tcflag_t = 0x00004000;
338 pub const CLOCAL: crate::tcflag_t = 0x00008000;
339 pub const ECHOKE: crate::tcflag_t = 0x00000001;
340 pub const ECHOE: crate::tcflag_t = 0x00000002;
341 pub const ECHOK: crate::tcflag_t = 0x00000004;
342 pub const ECHO: crate::tcflag_t = 0x00000008;
343 pub const ECHONL: crate::tcflag_t = 0x00000010;
344 pub const ECHOPRT: crate::tcflag_t = 0x00000020;
345 pub const ECHOCTL: crate::tcflag_t = 0x00000040;
346 pub const ISIG: crate::tcflag_t = 0x00000080;
347 pub const ICANON: crate::tcflag_t = 0x00000100;
348 pub const ALTWERASE: crate::tcflag_t = 0x00000200;
349 pub const IEXTEN: crate::tcflag_t = 0x00000400;
350 pub const EXTPROC: crate::tcflag_t = 0x00000800;
351 pub const TOSTOP: crate::tcflag_t = 0x00400000;
352 pub const FLUSHO: crate::tcflag_t = 0x00800000;
353 pub const NOKERNINFO: crate::tcflag_t = 0x02000000;
354 pub const PENDIN: crate::tcflag_t = 0x20000000;
355 pub const NOFLSH: crate::tcflag_t = 0x80000000;
356 pub const MDMBUF: crate::tcflag_t = 0x00100000;
357
358 pub const WNOHANG: c_int = 0x00000001;
359 pub const WUNTRACED: c_int = 0x00000002;
360
361 pub const RTLD_LAZY: c_int = 0x1;
362 pub const RTLD_NOW: c_int = 0x2;
363 pub const RTLD_NEXT: *mut c_void = -1isize as *mut c_void;
364 pub const RTLD_DEFAULT: *mut c_void = -2isize as *mut c_void;
365 pub const RTLD_SELF: *mut c_void = -3isize as *mut c_void;
366
367 pub const LOG_CRON: c_int = 9 << 3;
368 pub const LOG_AUTHPRIV: c_int = 10 << 3;
369 pub const LOG_FTP: c_int = 11 << 3;
370 pub const LOG_PERROR: c_int = 0x20;
371
372 pub const TCP_NODELAY: c_int = 1;
373 pub const TCP_MAXSEG: c_int = 2;
374
375 pub const PIPE_BUF: usize = 512;
376
377 // si_code values for SIGBUS signal
378 pub const BUS_ADRALN: c_int = 1;
379 pub const BUS_ADRERR: c_int = 2;
380 pub const BUS_OBJERR: c_int = 3;
381
382 // si_code values for SIGCHLD signal
383 pub const CLD_EXITED: c_int = 1;
384 pub const CLD_KILLED: c_int = 2;
385 pub const CLD_DUMPED: c_int = 3;
386 pub const CLD_TRAPPED: c_int = 4;
387 pub const CLD_STOPPED: c_int = 5;
388 pub const CLD_CONTINUED: c_int = 6;
389
390 pub const POLLIN: c_short = 0x1;
391 pub const POLLPRI: c_short = 0x2;
392 pub const POLLOUT: c_short = 0x4;
393 pub const POLLERR: c_short = 0x8;
394 pub const POLLHUP: c_short = 0x10;
395 pub const POLLNVAL: c_short = 0x20;
396 pub const POLLRDNORM: c_short = 0x040;
397 pub const POLLWRNORM: c_short = 0x004;
398 pub const POLLRDBAND: c_short = 0x080;
399 pub const POLLWRBAND: c_short = 0x100;
400
401 cfg_if! {
402 // Not yet implemented on NetBSD
403 if #[cfg(not(any(target_os = "netbsd")))] {
404 pub const BIOCGBLEN: c_ulong = 0x40044266;
405 pub const BIOCSBLEN: c_ulong = 0xc0044266;
406 pub const BIOCFLUSH: c_uint = 0x20004268;
407 pub const BIOCPROMISC: c_uint = 0x20004269;
408 pub const BIOCGDLT: c_ulong = 0x4004426a;
409 pub const BIOCGETIF: c_ulong = 0x4020426b;
410 pub const BIOCSETIF: c_ulong = 0x8020426c;
411 pub const BIOCGSTATS: c_ulong = 0x4008426f;
412 pub const BIOCIMMEDIATE: c_ulong = 0x80044270;
413 pub const BIOCVERSION: c_ulong = 0x40044271;
414 pub const BIOCGHDRCMPLT: c_ulong = 0x40044274;
415 pub const BIOCSHDRCMPLT: c_ulong = 0x80044275;
416 pub const SIOCGIFADDR: c_ulong = 0xc0206921;
417 }
418 }
419
420 pub const REG_BASIC: c_int = 0o0000;
421 pub const REG_EXTENDED: c_int = 0o0001;
422 pub const REG_ICASE: c_int = 0o0002;
423 pub const REG_NOSUB: c_int = 0o0004;
424 pub const REG_NEWLINE: c_int = 0o0010;
425 pub const REG_NOSPEC: c_int = 0o0020;
426 pub const REG_PEND: c_int = 0o0040;
427 pub const REG_DUMP: c_int = 0o0200;
428
429 pub const REG_NOMATCH: c_int = 1;
430 pub const REG_BADPAT: c_int = 2;
431 pub const REG_ECOLLATE: c_int = 3;
432 pub const REG_ECTYPE: c_int = 4;
433 pub const REG_EESCAPE: c_int = 5;
434 pub const REG_ESUBREG: c_int = 6;
435 pub const REG_EBRACK: c_int = 7;
436 pub const REG_EPAREN: c_int = 8;
437 pub const REG_EBRACE: c_int = 9;
438 pub const REG_BADBR: c_int = 10;
439 pub const REG_ERANGE: c_int = 11;
440 pub const REG_ESPACE: c_int = 12;
441 pub const REG_BADRPT: c_int = 13;
442 pub const REG_EMPTY: c_int = 14;
443 pub const REG_ASSERT: c_int = 15;
444 pub const REG_INVARG: c_int = 16;
445 pub const REG_ATOI: c_int = 255;
446 pub const REG_ITOA: c_int = 0o0400;
447
448 pub const REG_NOTBOL: c_int = 0o00001;
449 pub const REG_NOTEOL: c_int = 0o00002;
450 pub const REG_STARTEND: c_int = 0o00004;
451 pub const REG_TRACE: c_int = 0o00400;
452 pub const REG_LARGE: c_int = 0o01000;
453 pub const REG_BACKR: c_int = 0o02000;
454
455 pub const TIOCCBRK: c_uint = 0x2000747a;
456 pub const TIOCSBRK: c_uint = 0x2000747b;
457
458 pub const PRIO_PROCESS: c_int = 0;
459 pub const PRIO_PGRP: c_int = 1;
460 pub const PRIO_USER: c_int = 2;
461
462 pub const ITIMER_REAL: c_int = 0;
463 pub const ITIMER_VIRTUAL: c_int = 1;
464 pub const ITIMER_PROF: c_int = 2;
465
466 // net/route.h
467
468 pub const RTF_UP: c_int = 0x1;
469 pub const RTF_GATEWAY: c_int = 0x2;
470 pub const RTF_HOST: c_int = 0x4;
471 pub const RTF_REJECT: c_int = 0x8;
472 pub const RTF_DYNAMIC: c_int = 0x10;
473 pub const RTF_MODIFIED: c_int = 0x20;
474 pub const RTF_DONE: c_int = 0x40;
475 pub const RTF_STATIC: c_int = 0x800;
476 pub const RTF_BLACKHOLE: c_int = 0x1000;
477 pub const RTF_PROTO2: c_int = 0x4000;
478 pub const RTF_PROTO1: c_int = 0x8000;
479
480 // Message types
481 pub const RTM_ADD: c_int = 0x1;
482 pub const RTM_DELETE: c_int = 0x2;
483 pub const RTM_CHANGE: c_int = 0x3;
484 pub const RTM_GET: c_int = 0x4;
485 pub const RTM_LOSING: c_int = 0x5;
486 pub const RTM_REDIRECT: c_int = 0x6;
487 pub const RTM_MISS: c_int = 0x7;
488
489 // Bitmask values for rtm_addrs.
490 pub const RTA_DST: c_int = 0x1;
491 pub const RTA_GATEWAY: c_int = 0x2;
492 pub const RTA_NETMASK: c_int = 0x4;
493 pub const RTA_GENMASK: c_int = 0x8;
494 pub const RTA_IFP: c_int = 0x10;
495 pub const RTA_IFA: c_int = 0x20;
496 pub const RTA_AUTHOR: c_int = 0x40;
497 pub const RTA_BRD: c_int = 0x80;
498
499 // Index offsets for sockaddr array for alternate internal encoding.
500 pub const RTAX_DST: c_int = 0;
501 pub const RTAX_GATEWAY: c_int = 1;
502 pub const RTAX_NETMASK: c_int = 2;
503 pub const RTAX_GENMASK: c_int = 3;
504 pub const RTAX_IFP: c_int = 4;
505 pub const RTAX_IFA: c_int = 5;
506 pub const RTAX_AUTHOR: c_int = 6;
507 pub const RTAX_BRD: c_int = 7;
508
509 f! {
510 pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr {
511 if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() {
512 (*mhdr).msg_control.cast::<cmsghdr>()
513 } else {
514 core::ptr::null_mut()
515 }
516 }
517
518 pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
519 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
520 let fd = fd as usize;
521 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
522 return;
523 }
524
525 pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
526 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
527 let fd = fd as usize;
528 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0;
529 }
530
531 pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
532 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
533 let fd = fd as usize;
534 (*set).fds_bits[fd / bits] |= 1 << (fd % bits);
535 return;
536 }
537
538 pub fn FD_ZERO(set: *mut fd_set) -> () {
539 for slot in &mut (*set).fds_bits {
540 *slot = 0;
541 }
542 }
543 }
544
545 safe_f! {
546 pub const fn WTERMSIG(status: c_int) -> c_int {
547 status & 0o177
548 }
549
550 pub const fn WIFEXITED(status: c_int) -> bool {
551 (status & 0o177) == 0
552 }
553
554 pub const fn WEXITSTATUS(status: c_int) -> c_int {
555 (status >> 8) & 0x00ff
556 }
557
558 pub const fn WCOREDUMP(status: c_int) -> bool {
559 (status & 0o200) != 0
560 }
561
562 pub const fn QCMD(cmd: c_int, type_: c_int) -> c_int {
563 (cmd << 8) | (type_ & 0x00ff)
564 }
565 }
566
567 extern "C" {
568 #[cfg_attr(
569 all(target_os = "macos", target_arch = "x86"),
570 link_name = "getrlimit$UNIX2003"
571 )]
572 pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int;
573 #[cfg_attr(
574 all(target_os = "macos", target_arch = "x86"),
575 link_name = "setrlimit$UNIX2003"
576 )]
577 pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
578
579 pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
580 pub fn abs(i: c_int) -> c_int;
581 pub fn labs(i: c_long) -> c_long;
582 #[cfg_attr(
583 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
584 link_name = "rand@FBSD_1.0"
585 )]
586 pub fn rand() -> c_int;
587 #[cfg_attr(
588 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
589 link_name = "srand@FBSD_1.0"
590 )]
591 pub fn srand(seed: c_uint);
592
593 pub fn getifaddrs(ifap: *mut *mut crate::ifaddrs) -> c_int;
594 pub fn freeifaddrs(ifa: *mut crate::ifaddrs);
595 pub fn setgroups(ngroups: c_int, ptr: *const crate::gid_t) -> c_int;
596 pub fn setlogin(name: *const c_char) -> c_int;
597 pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
598 pub fn kqueue() -> c_int;
599 pub fn unmount(target: *const c_char, arg: c_int) -> c_int;
600 pub fn syscall(num: c_int, ...) -> c_int;
601 #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")]
602 pub fn getpwent() -> *mut passwd;
603 pub fn setpwent();
604 pub fn endpwent();
605 pub fn endgrent();
606 pub fn getgrent() -> *mut crate::group;
607
608 pub fn getprogname() -> *const c_char;
609 pub fn setprogname(name: *const c_char);
610 pub fn getloadavg(loadavg: *mut c_double, nelem: c_int) -> c_int;
611 pub fn if_nameindex() -> *mut if_nameindex;
612 pub fn if_freenameindex(ptr: *mut if_nameindex);
613
614 pub fn getpeereid(socket: c_int, euid: *mut crate::uid_t, egid: *mut crate::gid_t) -> c_int;
615
616 #[cfg_attr(
617 all(target_os = "macos", not(target_arch = "aarch64")),
618 link_name = "glob$INODE64"
619 )]
620 #[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
621 #[cfg_attr(
622 all(target_os = "freebsd", any(freebsd11, freebsd10)),
623 link_name = "glob@FBSD_1.0"
624 )]
625 pub fn glob(
626 pattern: *const c_char,
627 flags: c_int,
628 errfunc: Option<extern "C" fn(epath: *const c_char, errno: c_int) -> c_int>,
629 pglob: *mut crate::glob_t,
630 ) -> c_int;
631 #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
632 #[cfg_attr(
633 all(target_os = "freebsd", any(freebsd11, freebsd10)),
634 link_name = "globfree@FBSD_1.0"
635 )]
636 pub fn globfree(pglob: *mut crate::glob_t);
637
638 pub fn posix_madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
639
640 pub fn shm_unlink(name: *const c_char) -> c_int;
641
642 #[cfg_attr(
643 all(target_os = "macos", target_arch = "x86_64"),
644 link_name = "seekdir$INODE64"
645 )]
646 #[cfg_attr(
647 all(target_os = "macos", target_arch = "x86"),
648 link_name = "seekdir$INODE64$UNIX2003"
649 )]
650 pub fn seekdir(dirp: *mut crate::DIR, loc: c_long);
651
652 #[cfg_attr(
653 all(target_os = "macos", target_arch = "x86_64"),
654 link_name = "telldir$INODE64"
655 )]
656 #[cfg_attr(
657 all(target_os = "macos", target_arch = "x86"),
658 link_name = "telldir$INODE64$UNIX2003"
659 )]
660 pub fn telldir(dirp: *mut crate::DIR) -> c_long;
661 pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
662
663 #[cfg_attr(
664 all(target_os = "macos", target_arch = "x86"),
665 link_name = "msync$UNIX2003"
666 )]
667 #[cfg_attr(target_os = "netbsd", link_name = "__msync13")]
668 pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
669
670 #[cfg_attr(
671 all(target_os = "macos", target_arch = "x86"),
672 link_name = "recvfrom$UNIX2003"
673 )]
674 pub fn recvfrom(
675 socket: c_int,
676 buf: *mut c_void,
677 len: size_t,
678 flags: c_int,
679 addr: *mut crate::sockaddr,
680 addrlen: *mut crate::socklen_t,
681 ) -> ssize_t;
682 pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
683 #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")]
684 pub fn futimes(fd: c_int, times: *const crate::timeval) -> c_int;
685 pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char;
686
687 #[cfg_attr(
688 all(target_os = "macos", target_arch = "x86"),
689 link_name = "bind$UNIX2003"
690 )]
691 pub fn bind(
692 socket: c_int,
693 address: *const crate::sockaddr,
694 address_len: crate::socklen_t,
695 ) -> c_int;
696
697 #[cfg_attr(
698 all(target_os = "macos", target_arch = "x86"),
699 link_name = "writev$UNIX2003"
700 )]
701 pub fn writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
702 #[cfg_attr(
703 all(target_os = "macos", target_arch = "x86"),
704 link_name = "readv$UNIX2003"
705 )]
706 pub fn readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
707
708 #[cfg_attr(
709 all(target_os = "macos", target_arch = "x86"),
710 link_name = "sendmsg$UNIX2003"
711 )]
712 pub fn sendmsg(fd: c_int, msg: *const crate::msghdr, flags: c_int) -> ssize_t;
713 #[cfg_attr(
714 all(target_os = "macos", target_arch = "x86"),
715 link_name = "recvmsg$UNIX2003"
716 )]
717 pub fn recvmsg(fd: c_int, msg: *mut crate::msghdr, flags: c_int) -> ssize_t;
718
719 pub fn sync();
720 pub fn getgrgid_r(
721 gid: crate::gid_t,
722 grp: *mut crate::group,
723 buf: *mut c_char,
724 buflen: size_t,
725 result: *mut *mut crate::group,
726 ) -> c_int;
727 #[cfg_attr(
728 all(target_os = "macos", target_arch = "x86"),
729 link_name = "sigaltstack$UNIX2003"
730 )]
731 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
732 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int;
733 #[cfg_attr(target_os = "netbsd", link_name = "__sigsuspend14")]
734 pub fn sigsuspend(mask: *const crate::sigset_t) -> c_int;
735 pub fn sem_close(sem: *mut sem_t) -> c_int;
736 pub fn getdtablesize() -> c_int;
737 pub fn getgrnam_r(
738 name: *const c_char,
739 grp: *mut crate::group,
740 buf: *mut c_char,
741 buflen: size_t,
742 result: *mut *mut crate::group,
743 ) -> c_int;
744 #[cfg_attr(
745 all(target_os = "macos", target_arch = "x86"),
746 link_name = "pthread_sigmask$UNIX2003"
747 )]
748 pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int;
749 pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
750 pub fn getgrnam(name: *const c_char) -> *mut crate::group;
751 #[cfg_attr(
752 all(target_os = "macos", target_arch = "x86"),
753 link_name = "pthread_cancel$UNIX2003"
754 )]
755 pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
756 pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
757 pub fn sched_get_priority_min(policy: c_int) -> c_int;
758 pub fn sched_get_priority_max(policy: c_int) -> c_int;
759 pub fn sem_unlink(name: *const c_char) -> c_int;
760 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
761 pub fn getpwnam_r(
762 name: *const c_char,
763 pwd: *mut passwd,
764 buf: *mut c_char,
765 buflen: size_t,
766 result: *mut *mut passwd,
767 ) -> c_int;
768 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
769 pub fn getpwuid_r(
770 uid: crate::uid_t,
771 pwd: *mut passwd,
772 buf: *mut c_char,
773 buflen: size_t,
774 result: *mut *mut passwd,
775 ) -> c_int;
776 #[cfg_attr(
777 all(target_os = "macos", target_arch = "x86"),
778 link_name = "sigwait$UNIX2003"
779 )]
780 pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
781 pub fn pthread_atfork(
782 prepare: Option<unsafe extern "C" fn()>,
783 parent: Option<unsafe extern "C" fn()>,
784 child: Option<unsafe extern "C" fn()>,
785 ) -> c_int;
786 pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group;
787 #[cfg_attr(
788 all(target_os = "macos", target_arch = "x86"),
789 link_name = "popen$UNIX2003"
790 )]
791 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE;
792 pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int;
793 pub fn pthread_create(
794 native: *mut crate::pthread_t,
795 attr: *const crate::pthread_attr_t,
796 f: extern "C" fn(*mut c_void) -> *mut c_void,
797 value: *mut c_void,
798 ) -> c_int;
799 pub fn acct(filename: *const c_char) -> c_int;
800 #[cfg_attr(
801 all(target_os = "macos", target_arch = "x86"),
802 link_name = "wait4$UNIX2003"
803 )]
804 #[cfg_attr(
805 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
806 link_name = "wait4@FBSD_1.0"
807 )]
808 #[cfg_attr(target_os = "netbsd", link_name = "__wait450")]
809 pub fn wait4(
810 pid: crate::pid_t,
811 status: *mut c_int,
812 options: c_int,
813 rusage: *mut crate::rusage,
814 ) -> crate::pid_t;
815 #[cfg_attr(
816 all(target_os = "macos", target_arch = "x86"),
817 link_name = "getitimer$UNIX2003"
818 )]
819 #[cfg_attr(target_os = "netbsd", link_name = "__getitimer50")]
820 pub fn getitimer(which: c_int, curr_value: *mut crate::itimerval) -> c_int;
821 #[cfg_attr(
822 all(target_os = "macos", target_arch = "x86"),
823 link_name = "setitimer$UNIX2003"
824 )]
825 #[cfg_attr(target_os = "netbsd", link_name = "__setitimer50")]
826 pub fn setitimer(
827 which: c_int,
828 new_value: *const crate::itimerval,
829 old_value: *mut crate::itimerval,
830 ) -> c_int;
831
832 pub fn regcomp(preg: *mut regex_t, pattern: *const c_char, cflags: c_int) -> c_int;
833
834 pub fn regexec(
835 preg: *const regex_t,
836 input: *const c_char,
837 nmatch: size_t,
838 pmatch: *mut regmatch_t,
839 eflags: c_int,
840 ) -> c_int;
841
842 pub fn regerror(
843 errcode: c_int,
844 preg: *const regex_t,
845 errbuf: *mut c_char,
846 errbuf_size: size_t,
847 ) -> size_t;
848
849 pub fn regfree(preg: *mut regex_t);
850
851 pub fn arc4random() -> u32;
852 pub fn arc4random_buf(buf: *mut c_void, size: size_t);
853 pub fn arc4random_uniform(l: u32) -> u32;
854
855 pub fn drand48() -> c_double;
856 pub fn erand48(xseed: *mut c_ushort) -> c_double;
857 pub fn lrand48() -> c_long;
858 pub fn nrand48(xseed: *mut c_ushort) -> c_long;
859 pub fn mrand48() -> c_long;
860 pub fn jrand48(xseed: *mut c_ushort) -> c_long;
861 pub fn srand48(seed: c_long);
862 pub fn seed48(xseed: *mut c_ushort) -> *mut c_ushort;
863 pub fn lcong48(p: *mut c_ushort);
864 pub fn getopt_long(
865 argc: c_int,
866 argv: *const *mut c_char,
867 optstring: *const c_char,
868 longopts: *const option,
869 longindex: *mut c_int,
870 ) -> c_int;
871
872 pub fn strftime(
873 buf: *mut c_char,
874 maxsize: size_t,
875 format: *const c_char,
876 timeptr: *const crate::tm,
877 ) -> size_t;
878 pub fn strftime_l(
879 buf: *mut c_char,
880 maxsize: size_t,
881 format: *const c_char,
882 timeptr: *const crate::tm,
883 locale: crate::locale_t,
884 ) -> size_t;
885
886 #[cfg_attr(target_os = "netbsd", link_name = "__devname50")]
887 pub fn devname(dev: crate::dev_t, mode_t: crate::mode_t) -> *mut c_char;
888
889 pub fn issetugid() -> c_int;
890 }
891
892 cfg_if! {
893 if #[cfg(any(
894 target_os = "macos",
895 target_os = "ios",
896 target_os = "tvos",
897 target_os = "watchos",
898 target_os = "visionos"
899 ))] {
900 mod apple;
901 pub use self::apple::*;
902 } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] {
903 mod netbsdlike;
904 pub use self::netbsdlike::*;
905 } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] {
906 mod freebsdlike;
907 pub use self::freebsdlike::*;
908 } else {
909 // Unknown target_os
910 }
911 }