| ... | ... | @@ -665,6 +665,13 @@ pub const F_GETOWN_EX = 16; |
| 665 | 665 | |
| 666 | 666 | pub const F_GETOWNER_UIDS = 17; |
| 667 | 667 | |
| 668 | pub const AT_FDCWD = -100; |
| 669 | pub const AT_SYMLINK_NOFOLLOW = 0x100; |
| 670 | pub const AT_REMOVEDIR = 0x200; |
| 671 | pub const AT_SYMLINK_FOLLOW = 0x400; |
| 672 | pub const AT_NO_AUTOMOUNT = 0x800; |
| 673 | pub const AT_EMPTY_PATH = 0x1000; |
| 674 | |
| 668 | 675 | pub fn S_ISREG(m: u32) bool { |
| 669 | 676 | return m & S_IFMT == S_IFREG; |
| 670 | 677 | } |
| ... | ... | @@ -738,7 +745,11 @@ pub fn getErrno(r: usize) usize { |
| 738 | 745 | } |
| 739 | 746 | |
| 740 | 747 | pub fn dup2(old: i32, new: i32) usize { |
| 741 | | return syscall2(SYS_dup2, @intCast(usize, old), @intCast(usize, new)); |
| 748 | return dup3(old, new, 0); |
| 749 | } |
| 750 | |
| 751 | pub fn dup3(old: i32, new: i32, flags: u32) usize { |
| 752 | return syscall3(SYS_dup3, @intCast(usize, old), @intCast(usize, new), flags); |
| 742 | 753 | } |
| 743 | 754 | |
| 744 | 755 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -757,7 +768,7 @@ pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[* |
| 757 | 768 | } |
| 758 | 769 | |
| 759 | 770 | pub fn fork() usize { |
| 760 | | return syscall0(SYS_fork); |
| 771 | return clone2(SIGCHLD, 0); |
| 761 | 772 | } |
| 762 | 773 | |
| 763 | 774 | pub fn futex_wait(uaddr: usize, futex_op: u32, val: i32, timeout: ?*timespec) usize { |
| ... | ... | @@ -772,8 +783,8 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { |
| 772 | 783 | return syscall2(SYS_getcwd, @ptrToInt(buf), size); |
| 773 | 784 | } |
| 774 | 785 | |
| 775 | | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { |
| 776 | | return syscall3(SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); |
| 786 | pub fn getdents64(fd: i32, dirp: [*]u8, count: usize) usize { |
| 787 | return syscall3(SYS_getdents64, @intCast(usize, fd), @ptrToInt(dirp), count); |
| 777 | 788 | } |
| 778 | 789 | |
| 779 | 790 | pub fn inotify_init1(flags: u32) usize { |
| ... | ... | @@ -795,16 +806,26 @@ pub fn isatty(fd: i32) bool { |
| 795 | 806 | |
| 796 | 807 | // TODO https://github.com/ziglang/zig/issues/265 |
| 797 | 808 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 798 | | return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 809 | return readlinkat(AT_FDCWD, path, buf_ptr, buf_len); |
| 810 | } |
| 811 | |
| 812 | // TODO https://github.com/ziglang/zig/issues/265 |
| 813 | pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 814 | return syscall4(SYS_readlinkat, @intCast(usize, dirfd), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 799 | 815 | } |
| 800 | 816 | |
| 801 | 817 | // TODO https://github.com/ziglang/zig/issues/265 |
| 802 | 818 | pub fn mkdir(path: [*]const u8, mode: u32) usize { |
| 803 | | return syscall2(SYS_mkdir, @ptrToInt(path), mode); |
| 819 | return mkdirat(AT_FDCWD, path, mode); |
| 820 | } |
| 821 | |
| 822 | // TODO https://github.com/ziglang/zig/issues/265 |
| 823 | pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize { |
| 824 | return syscall3(SYS_mkdirat, @intCast(usize, dirfd), @ptrToInt(path), mode); |
| 804 | 825 | } |
| 805 | 826 | |
| 806 | 827 | // TODO https://github.com/ziglang/zig/issues/265 |
| 807 | | pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: usize, data: usize) usize { |
| 828 | pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: u32, data: usize) usize { |
| 808 | 829 | return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data); |
| 809 | 830 | } |
| 810 | 831 | |
| ... | ... | @@ -840,28 +861,38 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us |
| 840 | 861 | |
| 841 | 862 | // TODO https://github.com/ziglang/zig/issues/265 |
| 842 | 863 | pub fn rmdir(path: [*]const u8) usize { |
| 843 | | return syscall1(SYS_rmdir, @ptrToInt(path)); |
| 864 | return unlinkat(AT_FDCWD, path, AT_REMOVEDIR); |
| 844 | 865 | } |
| 845 | 866 | |
| 846 | 867 | // TODO https://github.com/ziglang/zig/issues/265 |
| 847 | 868 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { |
| 848 | | return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); |
| 869 | return symlinkat(existing, AT_FDCWD, new); |
| 849 | 870 | } |
| 850 | 871 | |
| 872 | // TODO https://github.com/ziglang/zig/issues/265 |
| 873 | pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize { |
| 874 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @intCast(usize, newfd), @ptrToInt(newpath)); |
| 875 | } |
| 876 | |
| 877 | // TODO https://github.com/ziglang/zig/issues/265 |
| 851 | 878 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { |
| 852 | 879 | return syscall4(SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset); |
| 853 | 880 | } |
| 854 | 881 | |
| 855 | 882 | // TODO https://github.com/ziglang/zig/issues/265 |
| 856 | 883 | pub fn access(path: [*]const u8, mode: u32) usize { |
| 857 | | return syscall2(SYS_access, @ptrToInt(path), mode); |
| 884 | return faccessat(AT_FDCWD, path, mode); |
| 885 | } |
| 886 | |
| 887 | pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize { |
| 888 | return syscall3(SYS_faccessat, @intCast(usize, dirfd), @ptrToInt(path), mode); |
| 858 | 889 | } |
| 859 | 890 | |
| 860 | 891 | pub fn pipe(fd: *[2]i32) usize { |
| 861 | 892 | return pipe2(fd, 0); |
| 862 | 893 | } |
| 863 | 894 | |
| 864 | | pub fn pipe2(fd: *[2]i32, flags: usize) usize { |
| 895 | pub fn pipe2(fd: *[2]i32, flags: u32) usize { |
| 865 | 896 | return syscall2(SYS_pipe2, @ptrToInt(fd), flags); |
| 866 | 897 | } |
| 867 | 898 | |
| ... | ... | @@ -875,12 +906,17 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 875 | 906 | |
| 876 | 907 | // TODO https://github.com/ziglang/zig/issues/265 |
| 877 | 908 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { |
| 878 | | return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); |
| 909 | return renameat2(AT_FDCWD, old, AT_FDCWD, new, 0); |
| 910 | } |
| 911 | |
| 912 | // TODO https://github.com/ziglang/zig/issues/265 |
| 913 | pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize { |
| 914 | return syscall5(SYS_renameat2, @intCast(usize, oldfd), @ptrToInt(oldpath), @intCast(usize, newfd), @ptrToInt(newpath), flags); |
| 879 | 915 | } |
| 880 | 916 | |
| 881 | 917 | // TODO https://github.com/ziglang/zig/issues/265 |
| 882 | 918 | pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { |
| 883 | | return syscall3(SYS_open, @ptrToInt(path), flags, perm); |
| 919 | return openat(AT_FDCWD, path, flags, perm); |
| 884 | 920 | } |
| 885 | 921 | |
| 886 | 922 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -889,7 +925,7 @@ pub fn create(path: [*]const u8, perm: usize) usize { |
| 889 | 925 | } |
| 890 | 926 | |
| 891 | 927 | // TODO https://github.com/ziglang/zig/issues/265 |
| 892 | | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { |
| 928 | pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize { |
| 893 | 929 | return syscall4(SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); |
| 894 | 930 | } |
| 895 | 931 | |
| ... | ... | @@ -899,7 +935,7 @@ pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: |
| 899 | 935 | } |
| 900 | 936 | |
| 901 | 937 | /// See also `clone` (from the arch-specific include) |
| 902 | | pub fn clone2(flags: usize, child_stack_ptr: usize) usize { |
| 938 | pub fn clone2(flags: u32, child_stack_ptr: usize) usize { |
| 903 | 939 | return syscall2(SYS_clone, flags, child_stack_ptr); |
| 904 | 940 | } |
| 905 | 941 | |
| ... | ... | @@ -917,7 +953,7 @@ pub fn exit(status: i32) noreturn { |
| 917 | 953 | } |
| 918 | 954 | |
| 919 | 955 | pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { |
| 920 | | return syscall3(SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags)); |
| 956 | return syscall3(SYS_getrandom, @ptrToInt(buf), count, flags); |
| 921 | 957 | } |
| 922 | 958 | |
| 923 | 959 | pub fn kill(pid: i32, sig: i32) usize { |
| ... | ... | @@ -926,7 +962,12 @@ pub fn kill(pid: i32, sig: i32) usize { |
| 926 | 962 | |
| 927 | 963 | // TODO https://github.com/ziglang/zig/issues/265 |
| 928 | 964 | pub fn unlink(path: [*]const u8) usize { |
| 929 | | return syscall1(SYS_unlink, @ptrToInt(path)); |
| 965 | return unlinkat(AT_FDCWD, path, 0); |
| 966 | } |
| 967 | |
| 968 | // TODO https://github.com/ziglang/zig/issues/265 |
| 969 | pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { |
| 970 | return syscall3(SYS_unlinkat, @intCast(usize, dirfd), @ptrToInt(path), flags); |
| 930 | 971 | } |
| 931 | 972 | |
| 932 | 973 | pub fn waitpid(pid: i32, status: *i32, options: i32) usize { |
| ... | ... | @@ -1230,17 +1271,22 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: |
| 1230 | 1271 | } |
| 1231 | 1272 | |
| 1232 | 1273 | pub fn fstat(fd: i32, stat_buf: *Stat) usize { |
| 1233 | | return syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); |
| 1274 | return fstatat(fd, c"", stat_buf, AT_EMPTY_PATH); |
| 1234 | 1275 | } |
| 1235 | 1276 | |
| 1236 | 1277 | // TODO https://github.com/ziglang/zig/issues/265 |
| 1237 | 1278 | pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 1238 | | return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf)); |
| 1279 | return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT); |
| 1239 | 1280 | } |
| 1240 | 1281 | |
| 1241 | 1282 | // TODO https://github.com/ziglang/zig/issues/265 |
| 1242 | 1283 | pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 1243 | | return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); |
| 1284 | return fstatat(AF_FDCWD, pathname, statbuf, AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT); |
| 1285 | } |
| 1286 | |
| 1287 | // TODO https://github.com/ziglang/zig/issues/265 |
| 1288 | pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { |
| 1289 | return syscall4(SYS_fstatat, @intCast(usize, dirfd), @ptrToInt(path), @ptrToInt(stat_buf), flags); |
| 1244 | 1290 | } |
| 1245 | 1291 | |
| 1246 | 1292 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -1331,7 +1377,18 @@ pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize { |
| 1331 | 1377 | } |
| 1332 | 1378 | |
| 1333 | 1379 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { |
| 1334 | | return syscall4(SYS_epoll_wait, @intCast(usize, epoll_fd), @ptrToInt(events), @intCast(usize, maxevents), @intCast(usize, timeout)); |
| 1380 | return epoll_pwait(epoll_fd, events, maxevents, timeout, null); |
| 1381 | } |
| 1382 | |
| 1383 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { |
| 1384 | return syscall6(SYS_epoll_pwait, |
| 1385 | @intCast(usize, epoll_fd), |
| 1386 | @ptrToInt(events), |
| 1387 | @intCast(usize, maxevents), |
| 1388 | @intCast(usize, timeout), |
| 1389 | @ptrToInt(sigmask), |
| 1390 | @sizeOf(sigset_t) |
| 1391 | ); |
| 1335 | 1392 | } |
| 1336 | 1393 | |
| 1337 | 1394 | pub fn eventfd(count: u32, flags: u32) usize { |
| ... | ... | @@ -1339,7 +1396,7 @@ pub fn eventfd(count: u32, flags: u32) usize { |
| 1339 | 1396 | } |
| 1340 | 1397 | |
| 1341 | 1398 | pub fn timerfd_create(clockid: i32, flags: u32) usize { |
| 1342 | | return syscall2(SYS_timerfd_create, @intCast(usize, clockid), @intCast(usize, flags)); |
| 1399 | return syscall2(SYS_timerfd_create, @intCast(usize, clockid), flags); |
| 1343 | 1400 | } |
| 1344 | 1401 | |
| 1345 | 1402 | pub const itimerspec = extern struct { |
| ... | ... | @@ -1352,7 +1409,7 @@ pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { |
| 1352 | 1409 | } |
| 1353 | 1410 | |
| 1354 | 1411 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { |
| 1355 | | return syscall4(SYS_timerfd_settime, @intCast(usize, fd), @intCast(usize, flags), @ptrToInt(new_value), @ptrToInt(old_value)); |
| 1412 | return syscall4(SYS_timerfd_settime, @intCast(usize, fd), flags, @ptrToInt(new_value), @ptrToInt(old_value)); |
| 1356 | 1413 | } |
| 1357 | 1414 | |
| 1358 | 1415 | pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; |
| ... | ... | @@ -1462,7 +1519,7 @@ pub const cap_user_data_t = extern struct { |
| 1462 | 1519 | }; |
| 1463 | 1520 | |
| 1464 | 1521 | pub fn unshare(flags: usize) usize { |
| 1465 | | return syscall1(SYS_unshare, @intCast(usize, flags)); |
| 1522 | return syscall1(SYS_unshare, flags); |
| 1466 | 1523 | } |
| 1467 | 1524 | |
| 1468 | 1525 | pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize { |
| ... | ... | @@ -1481,6 +1538,14 @@ pub const inotify_event = extern struct { |
| 1481 | 1538 | //name: [?]u8, |
| 1482 | 1539 | }; |
| 1483 | 1540 | |
| 1541 | pub const dirent64 = extern struct { |
| 1542 | d_ino: u64, |
| 1543 | d_off: u64, |
| 1544 | d_reclen: u16, |
| 1545 | d_type: u8, |
| 1546 | d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173 |
| 1547 | }; |
| 1548 | |
| 1484 | 1549 | test "import" { |
| 1485 | 1550 | if (builtin.os == builtin.Os.linux) { |
| 1486 | 1551 | _ = @import("test.zig"); |