1-- platform/libc on Darwin: its C library is its system interface, and
2-- these are its numbers, records and the calls Darwin has that Linux's
3-- C library does not, or names otherwise. What every system declares
4-- alike is in libc.ldn.
5
6fixed if compiler.os == darwin then
7 --- The calling thread's errno cell, `__error`. Read it immediately after
8 --- the failing call, before any other call that may set it.
9 public extern(c) link(symbol: "__error") errno_cell:
10 () -> (cell: ptr mut i32)
11
12 --- `open` flag: create the file if it does not exist. Linux keeps one
13 --- value on every architecture; Darwin and FreeBSD share the BSD one.
14 public o_creat: i32 = 512
15 --- `open` flag: truncate an existing regular file to length zero.
16 public o_trunc: i32 = 1024
17 --- `open` flag: with `o_creat`, fail with EEXIST if the name is taken.
18 public o_excl: i32 = 2048
19 --- `open` flag: every write goes to the end of the file.
20 public o_append: i32 = 8
21 --- `mmap` flag: the mapping is backed by no file and starts zeroed.
22 public map_anonymous: i32 = 4096
23 --- `poll`'s count of records, C's `nfds_t`.
24 public poll_count: type = u32
25
26 --- `clock_gettime` clock: time since a point the system fixes, never
27 --- set back. Each system numbers it its own way.
28 public clock_monotonic: i32 = 6
29
30 --- Fill the `length` bytes at `into` with random bytes from the C
31 --- library's generator, which the kernel's entropy keys and rekeys and
32 --- which is fit for keys. It never fails. Darwin's and FreeBSD's.
33 public extern(c) arc4random_buf: (into: ptr mut u8, length: usize)
34 -> none
35
36 -- Full records rather than guessed opaque storage, each selected by its
37 -- system and C ABI by name, so a system or an ABI none names has no
38 -- `file_status` rather than another's. Darwin arm64 uses the ordinary
39 -- stat symbol with its 64-bit inode ABI.
40
41 fixed if compiler.c_darwin_lp64 then
42 --- `sizeof (struct stat)` in the native C headers.
43 public file_status_size: usize = 144
44 --- C's `struct stat`, as `stat` fills it on this system. C declares
45 --- `dev_t` as `int32_t` here, but a device number is a bit pattern, not
46 --- a quantity, and devfs's may have the sign bit set, so both device
47 --- fields are unsigned and widening them never traps.
48 public file_status: type = struct
49 device: u32
50 mode: u16
51 links: u16
52 inode: u64
53 uid: u32
54 gid: u32
55 special_device: u32
56 accessed: timespec
57 modified: timespec
58 changed: timespec
59 created: timespec
60 bytes: i64
61 blocks: i64
62 block_size: i32
63 flags: u32
64 generation: u32
65 spare: i32
66 reserved: [2]i64
67 end file_status
68 end if
69
70 --- `open` flag: fail with ENOTDIR unless the path names a directory.
71 --- Linux's arm64 keeps a value of its own.
72 public o_directory: i32 = 1048576
73 --- `fstatat` flag: report a symbolic link itself.
74 public at_symlink_nofollow: i32 = 32
75
76 --- C's `struct dirent` as `readdir` returns it, with the 64-bit
77 --- inode every arm64 Darwin has.
78 public directory_record: type = struct
79 inode: u64
80 seek_offset: u64
81 record_length: u16
82 name_length: u16
83 kind: u8
84 name: [1024]u8
85 end directory_record
86
87 --- The directory descriptor that makes an `*at` call's relative path
88 --- relative to the working directory.
89 public at_fdcwd: i32 = -2
90 --- `unlinkat` flag: remove an empty directory rather than a file.
91 public at_removedir: i32 = 128
92
93 --- Make the directory `path`, relative to `directory` (or `at_fdcwd`),
94 --- with the permission bits `mode`, which the process umask filters:
95 --- 0, or -1 with the reason in errno.
96 public extern(c) mkdirat: (directory: i32, path: ptr u8, mode: u16)
97 -> (status: i32)
98
99 --- `open` flag: the new descriptor is closed when the process executes
100 --- a program, set with it. Darwin has no `pipe2`.
101 public o_cloexec: i32 = 16777216
102 --- `fcntl` command: duplicate a descriptor onto the lowest free number
103 --- at or above the argument, closed on exec.
104 public f_dupfd_cloexec: i32 = 67
105
106 --- A `posix_spawn_file_actions_t` or a `posix_spawnattr_t`: on Darwin
107 --- and FreeBSD a pointer the C library allocates, which its `init` writes
108 --- into the caller's cell and its `destroy` frees. glibc's are records of
109 --- its own, so these declarations are Darwin's and FreeBSD's alone.
110 public spawn_object: type = usize
111
112 --- Start a list of the actions `posix_spawn` performs in the child before
113 --- it executes the program: 0, or the errno.
114 public extern(c) posix_spawn_file_actions_init:
115 (actions: ptr mut spawn_object) -> (error: i32)
116
117 --- Free a list of actions: 0, or the errno.
118 public extern(c) posix_spawn_file_actions_destroy:
119 (actions: ptr mut spawn_object) -> (error: i32)
120
121 --- Add to `actions` making the child's `target` a duplicate of `source`:
122 --- 0, or the errno.
123 public extern(c) posix_spawn_file_actions_adddup2:
124 (actions: ptr mut spawn_object, source: i32, target: i32) -> (error: i32)
125
126 --- Start a set of attributes for `posix_spawn`: 0, or the errno.
127 public extern(c) posix_spawnattr_init:
128 (attributes: ptr mut spawn_object) -> (error: i32)
129
130 --- Free a set of attributes: 0, or the errno.
131 public extern(c) posix_spawnattr_destroy:
132 (attributes: ptr mut spawn_object) -> (error: i32)
133
134 --- Set the attributes' flags, C's `short`: 0, or the errno.
135 public extern(c) posix_spawnattr_setflags:
136 (attributes: ptr mut spawn_object, flags: i16) -> (error: i32)
137
138 --- Start the program at `path`, with the null-terminated `arguments` and
139 --- `environment` tables, in a child, applying `actions` and `attributes`
140 --- first, and put its ID in `child`: 0, or the errno, which a program
141 --- that could not be executed reports too, its child already reaped.
142 --- Nothing searches a path for the program.
143 public extern(c) posix_spawn:
144 (child: ptr mut i32, path: ptr u8, actions: ptr spawn_object,
145 attributes: ptr spawn_object, arguments: ptr ptr u8,
146 environment: ptr ptr u8) -> (error: i32)
147
148 --- `posix_spawnattr_setflags` flag, Darwin's own: every descriptor the
149 --- actions do not name is closed in the child, as though each were
150 --- closed on exec.
151 public posix_spawn_cloexec_default: i16 = 16384
152
153 --- Add to `actions` that the child keeps `descriptor` as it is, which
154 --- `posix_spawn_cloexec_default` would otherwise close: Darwin's own.
155 public extern(c) posix_spawn_file_actions_addinherit_np:
156 (actions: ptr mut spawn_object, descriptor: i32) -> (error: i32)
157
158 --- `socket` domain: IPv6, AF_INET6, which each system numbers its own
159 --- way.
160 public af_inet6: i32 = 30
161 --- `setsockopt` level: the socket itself, SOL_SOCKET.
162 public sol_socket: i32 = 65535
163 --- `sol_socket` option, an `i32`: a listener may bind an address that
164 --- earlier connections still hold in TIME_WAIT.
165 public so_reuseaddr: i32 = 4
166 --- `sol_socket` option, read as an `i32`: the pending error, cleared as
167 --- it is read.
168 public so_error: i32 = 4103
169 --- `sol_socket` option, a `time_limit`: how long a receive waits.
170 public so_rcvtimeo: i32 = 4102
171 --- `sol_socket` option, a `time_limit`: how long a send waits.
172 public so_sndtimeo: i32 = 4101
173 --- `ipproto_ipv6` option, an `i32`: an IPv6 socket takes IPv6 alone.
174 public ipv6_v6only: i32 = 27
175 --- `sol_socket` option, an `i32`: a write or send to a peer that has
176 --- gone fails with EPIPE and raises no SIGPIPE. Linux has none.
177 public so_nosigpipe: i32 = 4130
178 --- `sizeof (struct sockaddr_un)`'s path: the longest Unix-domain path
179 --- with its NUL.
180 public sockaddr_un_path: u32 = 104
181
182 --- C's `struct timeval`, which a socket time limit is: Darwin's
183 --- microseconds are an `int`.
184 public time_limit: type = struct
185 seconds: i64
186 microseconds: i32
187 padding: i32
188 end time_limit
189
190 --- Darwin's `sigset_t`, 32 bits.
191 public signal_set: type = struct
192 bits: [1]u32
193 end signal_set
194
195 --- C's `struct sigaction` as Darwin declares it.
196 public signal_action: type = struct
197 handler: u64
198 mask: signal_set
199 flags: i32
200 end signal_action
201
202 --- `posix_spawnattr_setflags` flag: the child's signals named by
203 --- `posix_spawnattr_setsigdefault` start at their default disposition.
204 public posix_spawn_setsigdef: i16 = 4
205
206 --- Name the signals whose disposition a child `posix_spawn` starts with
207 --- `posix_spawn_setsigdef` set is reset to the default: 0, or the
208 --- errno.
209 public extern(c) posix_spawnattr_setsigdefault:
210 (attributes: ptr mut spawn_object, signals: ptr signal_set)
211 -> (error: i32)
212
213 --- Set the permission bits of the file `path` names, relative to
214 --- `directory`, to `mode`, following a final symbolic link with
215 --- `flags` zero: 0, or -1 with the reason in errno.
216 public extern(c) fchmodat: (directory: i32, path: ptr u8, mode: u16,
217 flags: i32) -> (status: i32)
218 --- Set the permission bits of the file open as `descriptor`: 0, or -1
219 --- with the reason in errno.
220 public extern(c) fchmod: (descriptor: i32, mode: u16) -> (status: i32)
221
222 --- `fcntl` command, Darwin's own: hand the file to its device and have
223 --- the device write what it holds in its own cache, which `fsync`
224 --- leaves there. A file system that cannot fails with ENOTSUP.
225 public f_fullfsync: i32 = 51
226
227 --- `linkat` flag: follow a final symbolic link of the old path.
228 public at_symlink_follow: i32 = 64
229 --- `open` flag: a terminal opened does not become the controlling one.
230 public o_noctty: i32 = 131072
231 --- `fcntl` command: describe a record lock in the way, `F_GETLK`.
232 public f_getlk: i32 = 7
233 --- `fcntl` command: take or give up a record lock at once, `F_SETLK`.
234 public f_setlk: i32 = 8
235 --- `fcntl` command: take a record lock, waiting for it, `F_SETLKW`.
236 public f_setlkw: i32 = 9
237 --- A record lock's type: shared.
238 public f_rdlck: i16 = 1
239 --- A record lock's type: exclusive.
240 public f_wrlck: i16 = 3
241 --- A record lock's type: none.
242 public f_unlck: i16 = 2
243
244 --- C's `struct flock`, a record lock: its start and length, zero to the
245 --- end of the file however far it reaches, the process holding it,
246 --- which `f_getlk` fills, its type and where its start counts from.
247 public lock_record: type = struct
248 start: i64
249 length: i64
250 process: i32
251 kind: i16
252 whence: i16
253 end lock_record
254
255 --- Darwin's `struct passwd`: the account's name, password, user and
256 --- group IDs, password change time, class, comment, home directory,
257 --- shell and expiry, the strings pointers into the call's buffer.
258 public account_record: type = struct
259 name: usize
260 password: usize
261 user: u32
262 group: u32
263 changed: i64
264 class: usize
265 comment: usize
266 home: usize
267 shell: usize
268 expires: i64
269 end account_record
270
271 --- A terminal's settings, Darwin's `struct termios`, whose flags and
272 --- speeds are C `long`s: the input, output, control and local modes,
273 --- the control characters, `vmin` and `vtime` among them, and the
274 --- speeds.
275 public terminal_record: type = struct
276 input_modes: u64
277 output_modes: u64
278 control_modes: u64
279 local_modes: u64
280 characters: [20]u8
281 padding: u32
282 input_speed: u64
283 output_speed: u64
284 end terminal_record
285
286 --- Read the terminal `descriptor`'s settings into `into`: 0, or -1 with
287 --- the reason in errno, ENOTTY for any other file.
288 public extern(c) tcgetattr: (descriptor: i32, into: ptr mut terminal_record)
289 -> (status: i32)
290 --- Set the terminal `descriptor`'s settings to `settings`, when `timing`
291 --- says: 0, or -1 with the reason in errno.
292 public extern(c) tcsetattr: (descriptor: i32, timing: i32,
293 settings: ptr terminal_record) -> (status: i32)
294
295 --- `terminal_record` input mode: ignore a break. Darwin and FreeBSD
296 --- share 4.4BSD's numbers.
297 public ignbrk: u32 = 1
298 --- Input mode: a break interrupts.
299 public brkint: u32 = 2
300 --- Input mode: mark a parity error.
301 public parmrk: u32 = 8
302 --- Input mode: strip the eighth bit.
303 public istrip: u32 = 32
304 --- Input mode: read a newline as a carriage return.
305 public inlcr: u32 = 64
306 --- Input mode: ignore a carriage return.
307 public igncr: u32 = 128
308 --- Input mode: read a carriage return as a newline.
309 public icrnl: u32 = 256
310 --- Input mode: XON and XOFF control output.
311 public ixon: u32 = 512
312 --- Output mode: process output.
313 public opost: u32 = 1
314 --- Control mode: the character size's bits.
315 public csize: u32 = 768
316 --- Control mode: eight-bit characters.
317 public cs8: u32 = 768
318 --- Control mode: parity.
319 public parenb: u32 = 4096
320 --- Local mode: input is echoed.
321 public echo: u32 = 8
322 --- Local mode: a newline is echoed even without `echo`.
323 public echonl: u32 = 16
324 --- Local mode: the interrupt, quit and suspend characters raise their
325 --- signals.
326 public isig: u32 = 128
327 --- Local mode: input is read a line at a time and may be edited.
328 public icanon: u32 = 256
329 --- Local mode: the implementation's own input processing.
330 public iexten: u32 = 1024
331 --- `terminal_record` character index: how few bytes a read returns,
332 --- outside line mode.
333 public vmin: usize = 16
334 --- `terminal_record` character index: how long a read waits, in tenths
335 --- of a second, outside line mode.
336 public vtime: usize = 17
337
338 --- `ioctl` request: read a terminal's `window_record`.
339 public tiocgwinsz: u64 = 0x40087468
340 --- `ioctl` request: set a terminal's `window_record`.
341 public tiocswinsz: u64 = 0x80087467
342
343 --- Open a new pseudo-terminal's controller with the `open` flags given:
344 --- its descriptor, or -1 with the reason in errno.
345 public extern(c) posix_openpt: (flags: i32) -> (descriptor: i32)
346 --- Give the caller the pseudo-terminal of the controller `descriptor`:
347 --- 0, or -1 with the reason in errno.
348 public extern(c) grantpt: (descriptor: i32) -> (status: i32)
349 --- Let the pseudo-terminal of the controller `descriptor` be opened: 0,
350 --- or -1 with the reason in errno.
351 public extern(c) unlockpt: (descriptor: i32) -> (status: i32)
352 --- Put the path of the controller `descriptor`'s terminal, with a NUL,
353 --- in the `length` bytes at `into`: 0, or nonzero, the errno itself
354 --- or -1 with it in errno, ERANGE when it does not fit.
355 public extern(c) ptsname_r: (descriptor: i32, into: ptr mut u8,
356 length: usize) -> (status: i32)
357
358 --- `dlopen` mode: the object's symbols resolve no other object's
359 --- references. Darwin's default is `rtld_global`, so it is always
360 --- given.
361 public rtld_local: i32 = 4
362 --- `dlopen` mode: the object's symbols resolve the references of an
363 --- object loaded after it.
364 public rtld_global: i32 = 8
365end if