| 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 | 681 | var locked = false; |
| 682 | 682 | if (flags.lock) { |
| 683 | 683 | // TODO: integrate async I/O |
| 684 | try os.fcntlFlockBlocking(fd, &os.flock{ | |
| 685 | .lock_type = if (flags.write) os.F_WRLCK else os.F_RDLCK, | |
| 686 | .whence = os.SEEK_SET, | |
| 687 | .start = 0, | |
| 688 | .len = 0, | |
| 689 | .pid = 0, | |
| 690 | }); | |
| 684 | // mem.zeroes is used here because flock's structure can vary across architectures and systems | |
| 685 | var flock = mem.zeroes(os.Flock); | |
| 686 | flock.l_type = if (flags.write) os.F_WRLCK else os.F_RDLCK; | |
| 687 | flock.l_whence = os.SEEK_SET; | |
| 688 | flock.l_start = 0; | |
| 689 | flock.l_len = 0; | |
| 690 | flock.l_pid = 0; | |
| 691 | try os.fcntlFlockBlocking(fd, &flock); | |
| 691 | 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 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 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 | 1145 | const rc = system.fcntl(fd, F_SETLKW, flock_p); |
| 1146 | 1146 | if (rc < 0) { |
| 1147 | 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 | 55 | pub const off_t = i64; |
| 56 | 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 | 66 | /// Renamed to Stat to not conflict with the stat function. |
| 59 | 67 | /// atime, mtime, and ctime have functions to return `timespec`, |
| 60 | 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 | 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 | 64 | pub const msghdr = extern struct { |
| 55 | 65 | /// optional address |
| 56 | 66 | msg_name: ?*sockaddr, |
| ... | ... | @@ -350,6 +360,10 @@ pub const F_GETLK = 5; |
| 350 | 360 | pub const F_SETLK = 6; |
| 351 | 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 | 367 | pub const F_SETOWN_EX = 15; |
| 354 | 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 | 8 | const sigset_t = linux.sigset_t; |
| 9 | 9 | const uid_t = linux.uid_t; |
| 10 | 10 | const gid_t = linux.gid_t; |
| 11 | const pid_t = linux.pid_t; | |
| 11 | 12 | |
| 12 | 13 | pub const SYS_restart_syscall = 0; |
| 13 | 14 | pub const SYS_exit = 1; |
| ... | ... | @@ -446,6 +447,10 @@ pub const F_GETLK = 12; |
| 446 | 447 | pub const F_SETLK = 13; |
| 447 | 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 | 454 | pub const F_SETOWN_EX = 15; |
| 450 | 455 | pub const F_GETOWN_EX = 16; |
| 451 | 456 | |
| ... | ... | @@ -493,6 +498,16 @@ pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT; |
| 493 | 498 | pub const HWCAP_LPAE = 1 << 20; |
| 494 | 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 | 511 | pub const msghdr = extern struct { |
| 497 | 512 | msg_name: ?*sockaddr, |
| 498 | 513 | msg_namelen: socklen_t, |
lib/std/os/bits/linux/arm64.zig+14| ... | ... | @@ -8,6 +8,7 @@ const iovec = linux.iovec; |
| 8 | 8 | const iovec_const = linux.iovec_const; |
| 9 | 9 | const uid_t = linux.uid_t; |
| 10 | 10 | const gid_t = linux.gid_t; |
| 11 | const pid_t = linux.pid_t; | |
| 11 | 12 | const stack_t = linux.stack_t; |
| 12 | 13 | const sigset_t = linux.sigset_t; |
| 13 | 14 | |
| ... | ... | @@ -339,6 +340,10 @@ pub const F_GETLK = 5; |
| 339 | 340 | pub const F_SETLK = 6; |
| 340 | 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 | 347 | pub const F_SETOWN_EX = 15; |
| 343 | 348 | pub const F_GETOWN_EX = 16; |
| 344 | 349 | |
| ... | ... | @@ -362,6 +367,15 @@ pub const MAP_NORESERVE = 0x4000; |
| 362 | 367 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; |
| 363 | 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 | 379 | pub const msghdr = extern struct { |
| 366 | 380 | msg_name: ?*sockaddr, |
| 367 | 381 | msg_namelen: socklen_t, |
lib/std/os/bits/linux/i386.zig+10-6| ... | ... | @@ -472,6 +472,10 @@ pub const F_GETLK = 12; |
| 472 | 472 | pub const F_SETLK = 13; |
| 473 | 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 | 479 | pub const F_SETOWN_EX = 15; |
| 476 | 480 | pub const F_GETOWN_EX = 16; |
| 477 | 481 | |
| ... | ... | @@ -489,12 +493,12 @@ pub const MMAP2_UNIT = 4096; |
| 489 | 493 | pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; |
| 490 | 494 | pub const VDSO_CGT_VER = "LINUX_2.6"; |
| 491 | 495 | |
| 492 | pub const flock = extern struct { | |
| 493 | lock_type: i16, | |
| 494 | whence: i16, | |
| 495 | start: off_t, | |
| 496 | len: off_t, | |
| 497 | pid: pid_t, | |
| 496 | pub const Flock = extern struct { | |
| 497 | l_type: i16, | |
| 498 | l_whence: i16, | |
| 499 | l_start: off_t, | |
| 500 | l_len: off_t, | |
| 501 | l_pid: pid_t, | |
| 498 | 502 | }; |
| 499 | 503 | |
| 500 | 504 | pub const msghdr = extern struct { |
lib/std/os/bits/linux/mipsel.zig+15| ... | ... | @@ -5,6 +5,7 @@ const iovec = linux.iovec; |
| 5 | 5 | const iovec_const = linux.iovec_const; |
| 6 | 6 | const uid_t = linux.uid_t; |
| 7 | 7 | const gid_t = linux.gid_t; |
| 8 | const pid_t = linux.pid_t; | |
| 8 | 9 | |
| 9 | 10 | pub const SYS_Linux = 4000; |
| 10 | 11 | pub const SYS_syscall = (SYS_Linux + 0); |
| ... | ... | @@ -412,6 +413,10 @@ pub const F_GETLK = 33; |
| 412 | 413 | pub const F_SETLK = 34; |
| 413 | 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 | 420 | pub const F_SETOWN_EX = 15; |
| 416 | 421 | pub const F_GETOWN_EX = 16; |
| 417 | 422 | |
| ... | ... | @@ -457,6 +462,16 @@ pub const SO_RCVBUFFORCE = 33; |
| 457 | 462 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; |
| 458 | 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 | 475 | pub const blksize_t = i32; |
| 461 | 476 | pub const nlink_t = u32; |
| 462 | 477 | pub const time_t = isize; |
lib/std/os/bits/linux/riscv64.zig+14| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | const std = @import("../../../std.zig"); |
| 3 | 3 | const uid_t = std.os.linux.uid_t; |
| 4 | 4 | const gid_t = std.os.linux.gid_t; |
| 5 | const pid_t = std.os.linux.pid_t; | |
| 5 | 6 | |
| 6 | 7 | pub const SYS_io_setup = 0; |
| 7 | 8 | pub const SYS_io_destroy = 1; |
| ... | ... | @@ -332,6 +333,10 @@ pub const F_GETOWN = 9; |
| 332 | 333 | pub const F_SETSIG = 10; |
| 333 | 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 | 340 | pub const F_SETOWN_EX = 15; |
| 336 | 341 | pub const F_GETOWN_EX = 16; |
| 337 | 342 | |
| ... | ... | @@ -350,6 +355,15 @@ pub const timespec = extern struct { |
| 350 | 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 | 367 | /// Renamed to Stat to not conflict with the stat function. |
| 354 | 368 | /// atime, mtime, and ctime have functions to return `timespec`, |
| 355 | 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 | 460 | pub const F_WRLCK = 1; |
| 461 | 461 | pub const F_UNLCK = 2; |
| 462 | 462 | |
| 463 | pub const flock = extern struct { | |
| 464 | lock_type: i16, | |
| 465 | whence: i16, | |
| 466 | start: off_t, | |
| 467 | len: off_t, | |
| 468 | pid: pid_t, | |
| 463 | pub const Flock = extern struct { | |
| 464 | l_type: i16, | |
| 465 | l_whence: i16, | |
| 466 | l_start: off_t, | |
| 467 | l_len: off_t, | |
| 468 | l_pid: pid_t, | |
| 469 | 469 | }; |
| 470 | 470 | |
| 471 | 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 | 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 | 33 | pub const msghdr = extern struct { |
| 26 | 34 | /// optional address |
| 27 | 35 | msg_name: ?*sockaddr, |
| ... | ... | @@ -312,6 +320,10 @@ pub const F_GETLK = 7; |
| 312 | 320 | pub const F_SETLK = 8; |
| 313 | 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 | 327 | pub const SEEK_SET = 0; |
| 316 | 328 | pub const SEEK_CUR = 1; |
| 317 | 329 | pub const SEEK_END = 2; |