| author | |
| committer | |
| log | f66a607607c20841ed59a1fe11486333f8621426 |
| tree | 1914649ce4cc7f5691fec0602fa7b46d3414aee8 |
| parent | e1868029e9c861fa6b1382ba52052264fc5f9c31 |
11 files changed, 117 insertions(+), 20 deletions(-)
lib/std/fs.zig+8-7| ... | @@ -681,13 +681,14 @@ pub const Dir = struct { | ... | @@ -681,13 +681,14 @@ pub const Dir = struct { |
| 681 | var locked = false; | 681 | var locked = false; |
| 682 | if (flags.lock) { | 682 | if (flags.lock) { |
| 683 | // TODO: integrate async I/O | 683 | // TODO: integrate async I/O |
| 684 | try os.fcntlFlockBlocking(fd, &os.flock{ | 684 | // mem.zeroes is used here because flock's structure can vary across architectures and systems |
| 685 | .lock_type = if (flags.write) os.F_WRLCK else os.F_RDLCK, | 685 | var flock = mem.zeroes(os.Flock); |
| 686 | .whence = os.SEEK_SET, | 686 | flock.l_type = if (flags.write) os.F_WRLCK else os.F_RDLCK; |
| 687 | .start = 0, | 687 | flock.l_whence = os.SEEK_SET; |
| 688 | .len = 0, | 688 | flock.l_start = 0; |
| 689 | .pid = 0, | 689 | flock.l_len = 0; |
| 690 | }); | 690 | flock.l_pid = 0; |
| 691 | try os.fcntlFlockBlocking(fd, &flock); | ||
| 691 | locked = true; | 692 | locked = true; |
| 692 | } | 693 | } |
| 693 | 694 |
lib/std/os.zig+1-1| ... | @@ -1141,7 +1141,7 @@ pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8) | ... | @@ -1141,7 +1141,7 @@ pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8) |
| 1141 | } | 1141 | } |
| 1142 | 1142 | ||
| 1143 | /// Attempts to get lock the file, blocking if the file is locked. | 1143 | /// Attempts to get lock the file, blocking if the file is locked. |
| 1144 | pub fn fcntlFlockBlocking(fd: fd_t, flock_p: *const flock) OpenError!void { | 1144 | pub fn fcntlFlockBlocking(fd: fd_t, flock_p: *const Flock) OpenError!void { |
| 1145 | const rc = system.fcntl(fd, F_SETLKW, flock_p); | 1145 | const rc = system.fcntl(fd, F_SETLKW, flock_p); |
| 1146 | if (rc < 0) { | 1146 | if (rc < 0) { |
| 1147 | std.debug.panic("fcntl error: {}\n", .{rc}); | 1147 | std.debug.panic("fcntl error: {}\n", .{rc}); |
lib/std/os/bits/darwin.zig+8| ... | @@ -55,6 +55,14 @@ pub const mach_timebase_info_data = extern struct { | ... | @@ -55,6 +55,14 @@ pub const mach_timebase_info_data = extern struct { |
| 55 | pub const off_t = i64; | 55 | pub const off_t = i64; |
| 56 | pub const ino_t = u64; | 56 | pub const ino_t = u64; |
| 57 | 57 | ||
| 58 | pub const Flock = extern struct { | ||
| 59 | l_start: off_t, | ||
| 60 | l_len: off_t, | ||
| 61 | l_pid: pid_t, | ||
| 62 | l_type: i16, | ||
| 63 | l_whence: i16, | ||
| 64 | }; | ||
| 65 | |||
| 58 | /// Renamed to Stat to not conflict with the stat function. | 66 | /// Renamed to Stat to not conflict with the stat function. |
| 59 | /// atime, mtime, and ctime have functions to return `timespec`, | 67 | /// atime, mtime, and ctime have functions to return `timespec`, |
| 60 | /// because although this is a POSIX API, the layout and names of | 68 | /// because although this is a POSIX API, the layout and names of |
lib/std/os/bits/freebsd.zig+14| ... | @@ -51,6 +51,16 @@ pub const dl_phdr_info = extern struct { | ... | @@ -51,6 +51,16 @@ pub const dl_phdr_info = extern struct { |
| 51 | dlpi_phnum: u16, | 51 | dlpi_phnum: u16, |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | pub const Flock = extern struct { | ||
| 55 | l_start: off_t, | ||
| 56 | l_len: off_t, | ||
| 57 | l_pid: pid_t, | ||
| 58 | l_type: i16, | ||
| 59 | l_whence: i16, | ||
| 60 | l_sysid: i32, | ||
| 61 | __unused: [4]u8, | ||
| 62 | }; | ||
| 63 | |||
| 54 | pub const msghdr = extern struct { | 64 | pub const msghdr = extern struct { |
| 55 | /// optional address | 65 | /// optional address |
| 56 | msg_name: ?*sockaddr, | 66 | msg_name: ?*sockaddr, |
| ... | @@ -350,6 +360,10 @@ pub const F_GETLK = 5; | ... | @@ -350,6 +360,10 @@ pub const F_GETLK = 5; |
| 350 | pub const F_SETLK = 6; | 360 | pub const F_SETLK = 6; |
| 351 | pub const F_SETLKW = 7; | 361 | pub const F_SETLKW = 7; |
| 352 | 362 | ||
| 363 | pub const F_RDLCK = 1; | ||
| 364 | pub const F_WRLCK = 3; | ||
| 365 | pub const F_UNLCK = 2; | ||
| 366 | |||
| 353 | pub const F_SETOWN_EX = 15; | 367 | pub const F_SETOWN_EX = 15; |
| 354 | pub const F_GETOWN_EX = 16; | 368 | pub const F_GETOWN_EX = 16; |
| 355 | 369 |
lib/std/os/bits/linux/arm-eabi.zig+15| ... | @@ -8,6 +8,7 @@ const stack_t = linux.stack_t; | ... | @@ -8,6 +8,7 @@ const stack_t = linux.stack_t; |
| 8 | const sigset_t = linux.sigset_t; | 8 | const sigset_t = linux.sigset_t; |
| 9 | const uid_t = linux.uid_t; | 9 | const uid_t = linux.uid_t; |
| 10 | const gid_t = linux.gid_t; | 10 | const gid_t = linux.gid_t; |
| 11 | const pid_t = linux.pid_t; | ||
| 11 | 12 | ||
| 12 | pub const SYS_restart_syscall = 0; | 13 | pub const SYS_restart_syscall = 0; |
| 13 | pub const SYS_exit = 1; | 14 | pub const SYS_exit = 1; |
| ... | @@ -446,6 +447,10 @@ pub const F_GETLK = 12; | ... | @@ -446,6 +447,10 @@ pub const F_GETLK = 12; |
| 446 | pub const F_SETLK = 13; | 447 | pub const F_SETLK = 13; |
| 447 | pub const F_SETLKW = 14; | 448 | pub const F_SETLKW = 14; |
| 448 | 449 | ||
| 450 | pub const F_RDLCK = 0; | ||
| 451 | pub const F_WRLCK = 1; | ||
| 452 | pub const F_UNLCK = 2; | ||
| 453 | |||
| 449 | pub const F_SETOWN_EX = 15; | 454 | pub const F_SETOWN_EX = 15; |
| 450 | pub const F_GETOWN_EX = 16; | 455 | pub const F_GETOWN_EX = 16; |
| 451 | 456 | ||
| ... | @@ -493,6 +498,16 @@ pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT; | ... | @@ -493,6 +498,16 @@ pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT; |
| 493 | pub const HWCAP_LPAE = 1 << 20; | 498 | pub const HWCAP_LPAE = 1 << 20; |
| 494 | pub const HWCAP_EVTSTRM = 1 << 21; | 499 | pub const HWCAP_EVTSTRM = 1 << 21; |
| 495 | 500 | ||
| 501 | pub const Flock = extern struct { | ||
| 502 | l_type: i16, | ||
| 503 | l_whence: i16, | ||
| 504 | __pad0: [4]u8, | ||
| 505 | l_start: off_t, | ||
| 506 | l_len: off_t, | ||
| 507 | l_pid: pid_t, | ||
| 508 | __unused: [4]u8, | ||
| 509 | }; | ||
| 510 | |||
| 496 | pub const msghdr = extern struct { | 511 | pub const msghdr = extern struct { |
| 497 | msg_name: ?*sockaddr, | 512 | msg_name: ?*sockaddr, |
| 498 | msg_namelen: socklen_t, | 513 | msg_namelen: socklen_t, |
lib/std/os/bits/linux/arm64.zig+14| ... | @@ -8,6 +8,7 @@ const iovec = linux.iovec; | ... | @@ -8,6 +8,7 @@ const iovec = linux.iovec; |
| 8 | const iovec_const = linux.iovec_const; | 8 | const iovec_const = linux.iovec_const; |
| 9 | const uid_t = linux.uid_t; | 9 | const uid_t = linux.uid_t; |
| 10 | const gid_t = linux.gid_t; | 10 | const gid_t = linux.gid_t; |
| 11 | const pid_t = linux.pid_t; | ||
| 11 | const stack_t = linux.stack_t; | 12 | const stack_t = linux.stack_t; |
| 12 | const sigset_t = linux.sigset_t; | 13 | const sigset_t = linux.sigset_t; |
| 13 | 14 | ||
| ... | @@ -339,6 +340,10 @@ pub const F_GETLK = 5; | ... | @@ -339,6 +340,10 @@ pub const F_GETLK = 5; |
| 339 | pub const F_SETLK = 6; | 340 | pub const F_SETLK = 6; |
| 340 | pub const F_SETLKW = 7; | 341 | pub const F_SETLKW = 7; |
| 341 | 342 | ||
| 343 | pub const F_RDLCK = 0; | ||
| 344 | pub const F_WRLCK = 1; | ||
| 345 | pub const F_UNLCK = 2; | ||
| 346 | |||
| 342 | pub const F_SETOWN_EX = 15; | 347 | pub const F_SETOWN_EX = 15; |
| 343 | pub const F_GETOWN_EX = 16; | 348 | pub const F_GETOWN_EX = 16; |
| 344 | 349 | ||
| ... | @@ -362,6 +367,15 @@ pub const MAP_NORESERVE = 0x4000; | ... | @@ -362,6 +367,15 @@ pub const MAP_NORESERVE = 0x4000; |
| 362 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; | 367 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; |
| 363 | pub const VDSO_CGT_VER = "LINUX_2.6.39"; | 368 | pub const VDSO_CGT_VER = "LINUX_2.6.39"; |
| 364 | 369 | ||
| 370 | pub const Flock = extern struct { | ||
| 371 | l_type: i16, | ||
| 372 | l_whence: i16, | ||
| 373 | l_start: off_t, | ||
| 374 | l_len: off_t, | ||
| 375 | l_pid: pid_t, | ||
| 376 | __unused: [4]u8, | ||
| 377 | }; | ||
| 378 | |||
| 365 | pub const msghdr = extern struct { | 379 | pub const msghdr = extern struct { |
| 366 | msg_name: ?*sockaddr, | 380 | msg_name: ?*sockaddr, |
| 367 | msg_namelen: socklen_t, | 381 | msg_namelen: socklen_t, |
lib/std/os/bits/linux/i386.zig+10-6| ... | @@ -472,6 +472,10 @@ pub const F_GETLK = 12; | ... | @@ -472,6 +472,10 @@ pub const F_GETLK = 12; |
| 472 | pub const F_SETLK = 13; | 472 | pub const F_SETLK = 13; |
| 473 | pub const F_SETLKW = 14; | 473 | pub const F_SETLKW = 14; |
| 474 | 474 | ||
| 475 | pub const F_RDLCK = 0; | ||
| 476 | pub const F_WRLCK = 1; | ||
| 477 | pub const F_UNLCK = 2; | ||
| 478 | |||
| 475 | pub const F_SETOWN_EX = 15; | 479 | pub const F_SETOWN_EX = 15; |
| 476 | pub const F_GETOWN_EX = 16; | 480 | pub const F_GETOWN_EX = 16; |
| 477 | 481 | ||
| ... | @@ -489,12 +493,12 @@ pub const MMAP2_UNIT = 4096; | ... | @@ -489,12 +493,12 @@ pub const MMAP2_UNIT = 4096; |
| 489 | pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; | 493 | pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; |
| 490 | pub const VDSO_CGT_VER = "LINUX_2.6"; | 494 | pub const VDSO_CGT_VER = "LINUX_2.6"; |
| 491 | 495 | ||
| 492 | pub const flock = extern struct { | 496 | pub const Flock = extern struct { |
| 493 | lock_type: i16, | 497 | l_type: i16, |
| 494 | whence: i16, | 498 | l_whence: i16, |
| 495 | start: off_t, | 499 | l_start: off_t, |
| 496 | len: off_t, | 500 | l_len: off_t, |
| 497 | pid: pid_t, | 501 | l_pid: pid_t, |
| 498 | }; | 502 | }; |
| 499 | 503 | ||
| 500 | pub const msghdr = extern struct { | 504 | pub const msghdr = extern struct { |
lib/std/os/bits/linux/mipsel.zig+15| ... | @@ -5,6 +5,7 @@ const iovec = linux.iovec; | ... | @@ -5,6 +5,7 @@ const iovec = linux.iovec; |
| 5 | const iovec_const = linux.iovec_const; | 5 | const iovec_const = linux.iovec_const; |
| 6 | const uid_t = linux.uid_t; | 6 | const uid_t = linux.uid_t; |
| 7 | const gid_t = linux.gid_t; | 7 | const gid_t = linux.gid_t; |
| 8 | const pid_t = linux.pid_t; | ||
| 8 | 9 | ||
| 9 | pub const SYS_Linux = 4000; | 10 | pub const SYS_Linux = 4000; |
| 10 | pub const SYS_syscall = (SYS_Linux + 0); | 11 | pub const SYS_syscall = (SYS_Linux + 0); |
| ... | @@ -412,6 +413,10 @@ pub const F_GETLK = 33; | ... | @@ -412,6 +413,10 @@ pub const F_GETLK = 33; |
| 412 | pub const F_SETLK = 34; | 413 | pub const F_SETLK = 34; |
| 413 | pub const F_SETLKW = 35; | 414 | pub const F_SETLKW = 35; |
| 414 | 415 | ||
| 416 | pub const F_RDLCK = 0; | ||
| 417 | pub const F_WRLCK = 1; | ||
| 418 | pub const F_UNLCK = 2; | ||
| 419 | |||
| 415 | pub const F_SETOWN_EX = 15; | 420 | pub const F_SETOWN_EX = 15; |
| 416 | pub const F_GETOWN_EX = 16; | 421 | pub const F_GETOWN_EX = 16; |
| 417 | 422 | ||
| ... | @@ -457,6 +462,16 @@ pub const SO_RCVBUFFORCE = 33; | ... | @@ -457,6 +462,16 @@ pub const SO_RCVBUFFORCE = 33; |
| 457 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; | 462 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; |
| 458 | pub const VDSO_CGT_VER = "LINUX_2.6.39"; | 463 | pub const VDSO_CGT_VER = "LINUX_2.6.39"; |
| 459 | 464 | ||
| 465 | pub const Flock = extern struct { | ||
| 466 | l_type: i16, | ||
| 467 | l_whence: i16, | ||
| 468 | __pad0: [4]u8, | ||
| 469 | l_start: off_t, | ||
| 470 | l_len: off_t, | ||
| 471 | l_pid: pid_t, | ||
| 472 | __unused: [4]u8, | ||
| 473 | }; | ||
| 474 | |||
| 460 | pub const blksize_t = i32; | 475 | pub const blksize_t = i32; |
| 461 | pub const nlink_t = u32; | 476 | pub const nlink_t = u32; |
| 462 | pub const time_t = isize; | 477 | pub const time_t = isize; |
lib/std/os/bits/linux/riscv64.zig+14| ... | @@ -2,6 +2,7 @@ | ... | @@ -2,6 +2,7 @@ |
| 2 | const std = @import("../../../std.zig"); | 2 | const std = @import("../../../std.zig"); |
| 3 | const uid_t = std.os.linux.uid_t; | 3 | const uid_t = std.os.linux.uid_t; |
| 4 | const gid_t = std.os.linux.gid_t; | 4 | const gid_t = std.os.linux.gid_t; |
| 5 | const pid_t = std.os.linux.pid_t; | ||
| 5 | 6 | ||
| 6 | pub const SYS_io_setup = 0; | 7 | pub const SYS_io_setup = 0; |
| 7 | pub const SYS_io_destroy = 1; | 8 | pub const SYS_io_destroy = 1; |
| ... | @@ -332,6 +333,10 @@ pub const F_GETOWN = 9; | ... | @@ -332,6 +333,10 @@ pub const F_GETOWN = 9; |
| 332 | pub const F_SETSIG = 10; | 333 | pub const F_SETSIG = 10; |
| 333 | pub const F_GETSIG = 11; | 334 | pub const F_GETSIG = 11; |
| 334 | 335 | ||
| 336 | pub const F_RDLCK = 0; | ||
| 337 | pub const F_WRLCK = 1; | ||
| 338 | pub const F_UNLCK = 2; | ||
| 339 | |||
| 335 | pub const F_SETOWN_EX = 15; | 340 | pub const F_SETOWN_EX = 15; |
| 336 | pub const F_GETOWN_EX = 16; | 341 | pub const F_GETOWN_EX = 16; |
| 337 | 342 | ||
| ... | @@ -350,6 +355,15 @@ pub const timespec = extern struct { | ... | @@ -350,6 +355,15 @@ pub const timespec = extern struct { |
| 350 | tv_nsec: isize, | 355 | tv_nsec: isize, |
| 351 | }; | 356 | }; |
| 352 | 357 | ||
| 358 | pub const Flock = extern struct { | ||
| 359 | l_type: i16, | ||
| 360 | l_whence: i16, | ||
| 361 | l_start: off_t, | ||
| 362 | l_len: off_t, | ||
| 363 | l_pid: pid_t, | ||
| 364 | __unused: [4]u8, | ||
| 365 | }; | ||
| 366 | |||
| 353 | /// Renamed to Stat to not conflict with the stat function. | 367 | /// Renamed to Stat to not conflict with the stat function. |
| 354 | /// atime, mtime, and ctime have functions to return `timespec`, | 368 | /// atime, mtime, and ctime have functions to return `timespec`, |
| 355 | /// because although this is a POSIX API, the layout and names of | 369 | /// because although this is a POSIX API, the layout and names of |
lib/std/os/bits/linux/x86_64.zig+6-6| ... | @@ -460,12 +460,12 @@ pub const F_RDLCK = 0; | ... | @@ -460,12 +460,12 @@ pub const F_RDLCK = 0; |
| 460 | pub const F_WRLCK = 1; | 460 | pub const F_WRLCK = 1; |
| 461 | pub const F_UNLCK = 2; | 461 | pub const F_UNLCK = 2; |
| 462 | 462 | ||
| 463 | pub const flock = extern struct { | 463 | pub const Flock = extern struct { |
| 464 | lock_type: i16, | 464 | l_type: i16, |
| 465 | whence: i16, | 465 | l_whence: i16, |
| 466 | start: off_t, | 466 | l_start: off_t, |
| 467 | len: off_t, | 467 | l_len: off_t, |
| 468 | pid: pid_t, | 468 | l_pid: pid_t, |
| 469 | }; | 469 | }; |
| 470 | 470 | ||
| 471 | pub const msghdr = extern struct { | 471 | pub const msghdr = extern struct { |
lib/std/os/bits/netbsd.zig+12| ... | @@ -22,6 +22,14 @@ pub const dl_phdr_info = extern struct { | ... | @@ -22,6 +22,14 @@ pub const dl_phdr_info = extern struct { |
| 22 | dlpi_phnum: u16, | 22 | dlpi_phnum: u16, |
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | pub const Flock = extern struct { | ||
| 26 | start: off_t, | ||
| 27 | len: off_t, | ||
| 28 | pid: pid_t, | ||
| 29 | lock_type: i16, | ||
| 30 | whence: i16, | ||
| 31 | }; | ||
| 32 | |||
| 25 | pub const msghdr = extern struct { | 33 | pub const msghdr = extern struct { |
| 26 | /// optional address | 34 | /// optional address |
| 27 | msg_name: ?*sockaddr, | 35 | msg_name: ?*sockaddr, |
| ... | @@ -312,6 +320,10 @@ pub const F_GETLK = 7; | ... | @@ -312,6 +320,10 @@ pub const F_GETLK = 7; |
| 312 | pub const F_SETLK = 8; | 320 | pub const F_SETLK = 8; |
| 313 | pub const F_SETLKW = 9; | 321 | pub const F_SETLKW = 9; |
| 314 | 322 | ||
| 323 | pub const F_RDLCK = 1; | ||
| 324 | pub const F_WRLCK = 3; | ||
| 325 | pub const F_UNLCK = 2; | ||
| 326 | |||
| 315 | pub const SEEK_SET = 0; | 327 | pub const SEEK_SET = 0; |
| 316 | pub const SEEK_CUR = 1; | 328 | pub const SEEK_CUR = 1; |
| 317 | pub const SEEK_END = 2; | 329 | pub const SEEK_END = 2; |