authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-12-05 10:37:30+00:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-12-14 18:42:51-05:00
log31a26bf483ea5cb59d362810f1095426b3aeeb25
tree66d721415cec82827776e69c3a45b42dc0ca4749
parent648c1c5d28f3c3b1da1acf326b733c47436007d1

std: add and improve some system API bindings


2 files changed, 103 insertions(+), 0 deletions(-)

lib/std/c.zig+10
......@@ -10810,6 +10810,16 @@ pub const ptrace = switch (native_os) {
1081010810 else => {},
1081110811};
1081210812
10813pub extern "c" fn semget(key: std.posix.key_t, nsems: c_int, semflg: c_int) c_int;
10814pub extern "c" fn semctl(semid: c_int, semnum: c_int, op: c_int, ...) c_int;
10815pub extern "c" fn semop(semid: c_int, sops: [*]std.posix.sembuf, nsops: usize) c_int;
10816pub extern "c" fn semtimedop(
10817 semid: c_int,
10818 sops: [*]std.posix.sembuf,
10819 nsops: usize,
10820 timeout: ?*const timespec,
10821) c_int;
10822
1081310823pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;
1081410824pub extern "c" fn sem_destroy(sem: *sem_t) c_int;
1081510825pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: mode_t, value: c_uint) *sem_t;
lib/std/posix.zig+93
......@@ -275,6 +275,99 @@ pub const LOG = struct {
275275 pub const DEBUG = 7;
276276};
277277
278pub const key_t = switch (native_os) {
279 .linux, .illumos => enum(c_int) {
280 IPC_PRIVATE = 0,
281 _,
282 },
283 .freebsd, .netbsd, .openbsd, .dragonfly => enum(c_long) {
284 IPC_PRIVATE = 0,
285 _,
286 },
287 .haiku,
288 .driverkit,
289 .ios,
290 .maccatalyst,
291 .macos,
292 .tvos,
293 .visionos,
294 .watchos,
295 => enum(i32) {
296 IPC_PRIVATE = 0,
297 _,
298 },
299 else => unreachable,
300};
301pub const SETVAL = switch (native_os) {
302 .linux => 16,
303
304 .illumos,
305 .haiku,
306
307 .freebsd,
308 .netbsd,
309 .openbsd,
310 .dragonfly,
311
312 .driverkit,
313 .ios,
314 .maccatalyst,
315 .macos,
316 .tvos,
317 .visionos,
318 .watchos,
319 => 8,
320
321 else => unreachable,
322};
323pub const SEM_UNDO = switch (native_os) {
324 .linux,
325 .illumos,
326
327 .freebsd,
328 .netbsd,
329 .openbsd,
330 .dragonfly,
331
332 .driverkit,
333 .ios,
334 .maccatalyst,
335 .macos,
336 .tvos,
337 .visionos,
338 .watchos,
339 => 0x1000,
340
341 .haiku => 10,
342
343 else => unreachable,
344};
345pub const sembuf = switch (native_os) {
346 .linux,
347 .illumos,
348 .haiku,
349
350 .freebsd,
351 .netbsd,
352 .openbsd,
353 .dragonfly,
354
355 .driverkit,
356 .ios,
357 .maccatalyst,
358 .macos,
359 .tvos,
360 .visionos,
361 .watchos,
362 => extern struct {
363 sem_num: c_ushort,
364 sem_op: c_short,
365 sem_flg: c_short,
366 },
367
368 else => unreachable,
369};
370
278371pub const socket_t = if (native_os == .windows) windows.ws2_32.SOCKET else fd_t;
279372
280373/// Obtains errno from the return value of a system function call.