Landin library reference discuss source

platform/libc/freebsd.ldn

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