authorgravatar for raulgrell@gmail.comRaul Leal <raulgrell@gmail.com> 2019-12-17 20:43:49+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-17 15:43:49-05:00
log62c817420df0420e20756b2c3a4ec99db3b5649d
tree76c11dd168ae2eced1904a1012eb0a54df279eaa
parentb242c2ac103cbb251751dcf94f665e57b9551156

[#3844 + #3767] update std.c and std.os.linux to use null-terminated pointer types (#3900)

* #3844 update std.c functions to use null-terminated pointer types * check linux functions * fix callsites * fix io test * Add allocPrintCstr function to remove other cast

4 files changed, 73 insertions(+), 109 deletions(-)

lib/std/c.zig+26-28
...@@ -56,9 +56,7 @@ pub fn versionCheck(glibc_version: builtin.Version) type {...@@ -56,9 +56,7 @@ pub fn versionCheck(glibc_version: builtin.Version) type {
56 };56 };
57}57}
5858
59// TODO https://github.com/ziglang/zig/issues/265 on this whole file59pub extern "c" fn fopen(filename: [*:0]const u8, modes: [*:0]const u8) ?*FILE;
60
61pub extern "c" fn fopen(filename: [*]const u8, modes: [*]const u8) ?*FILE;
62pub extern "c" fn fclose(stream: *FILE) c_int;60pub extern "c" fn fclose(stream: *FILE) c_int;
63pub extern "c" fn fwrite(ptr: [*]const u8, size_of_type: usize, item_count: usize, stream: *FILE) usize;61pub extern "c" fn fwrite(ptr: [*]const u8, size_of_type: usize, item_count: usize, stream: *FILE) usize;
64pub extern "c" fn fread(ptr: [*]u8, size_of_type: usize, item_count: usize, stream: *FILE) usize;62pub extern "c" fn fread(ptr: [*]u8, size_of_type: usize, item_count: usize, stream: *FILE) usize;
...@@ -71,8 +69,8 @@ pub extern "c" fn close(fd: fd_t) c_int;...@@ -71,8 +69,8 @@ pub extern "c" fn close(fd: fd_t) c_int;
71pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;69pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
72pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;70pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
73pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;71pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
74pub extern "c" fn open(path: [*]const u8, oflag: c_uint, ...) c_int;72pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;
75pub extern "c" fn openat(fd: c_int, path: [*]const u8, oflag: c_uint, ...) c_int;73pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: c_uint, ...) c_int;
76pub extern "c" fn raise(sig: c_int) c_int;74pub extern "c" fn raise(sig: c_int) c_int;
77pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;75pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
78pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;76pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
...@@ -80,40 +78,40 @@ pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;...@@ -80,40 +78,40 @@ pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;
80pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: u64) isize;78pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: u64) isize;
81pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;79pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
82pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: u64) isize;80pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: u64) isize;
83pub extern "c" fn stat(noalias path: [*]const u8, noalias buf: *Stat) c_int;81pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
84pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;82pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
85pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize;83pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize;
86pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: u64) *c_void;84pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: u64) *c_void;
87pub extern "c" fn munmap(addr: *align(page_size) c_void, len: usize) c_int;85pub extern "c" fn munmap(addr: *align(page_size) c_void, len: usize) c_int;
88pub extern "c" fn mprotect(addr: *align(page_size) c_void, len: usize, prot: c_uint) c_int;86pub extern "c" fn mprotect(addr: *align(page_size) c_void, len: usize, prot: c_uint) c_int;
89pub extern "c" fn unlink(path: [*]const u8) c_int;87pub extern "c" fn unlink(path: [*:0]const u8) c_int;
90pub extern "c" fn unlinkat(dirfd: fd_t, path: [*]const u8, flags: c_uint) c_int;88pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int;
91pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;89pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
92pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_uint, options: c_uint) c_int;90pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_uint, options: c_uint) c_int;
93pub extern "c" fn fork() c_int;91pub extern "c" fn fork() c_int;
94pub extern "c" fn access(path: [*]const u8, mode: c_uint) c_int;92pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) c_int;
95pub extern "c" fn pipe(fds: *[2]fd_t) c_int;93pub extern "c" fn pipe(fds: *[2]fd_t) c_int;
96pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;94pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
97pub extern "c" fn mkdir(path: [*]const u8, mode: c_uint) c_int;95pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int;
98pub extern "c" fn symlink(existing: [*]const u8, new: [*]const u8) c_int;96pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;
99pub extern "c" fn rename(old: [*]const u8, new: [*]const u8) c_int;97pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;
100pub extern "c" fn chdir(path: [*]const u8) c_int;98pub extern "c" fn chdir(path: [*:0]const u8) c_int;
101pub extern "c" fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) c_int;99pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int;
102pub extern "c" fn dup(fd: fd_t) c_int;100pub extern "c" fn dup(fd: fd_t) c_int;
103pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;101pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
104pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize;102pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
105pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;103pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
106pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int;104pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int;
107pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;105pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
108pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;106pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
109pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;107pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
110pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;108pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
111pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;109pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
112pub extern "c" fn rmdir(path: [*]const u8) c_int;110pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
113pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;111pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
114pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;112pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
115pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;113pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
116pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;114pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
117115
118pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;116pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;
119pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;117pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
...@@ -158,9 +156,9 @@ pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize...@@ -158,9 +156,9 @@ pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize
158156
159// Deprecated157// Deprecated
160pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int;158pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int;
161pub extern "c" fn utimes(path: [*]const u8, times: *[2]timeval) c_int;159pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
162160
163pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*]const u8, times: *[2]timespec, flags: u32) c_int;161pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
164pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;162pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
165163
166pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int;164pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int;
...@@ -181,8 +179,8 @@ pub extern "c" fn kevent(...@@ -181,8 +179,8 @@ pub extern "c" fn kevent(
181) c_int;179) c_int;
182180
183pub extern "c" fn getaddrinfo(181pub extern "c" fn getaddrinfo(
184 noalias node: [*]const u8,182 noalias node: [*:0]const u8,
185 noalias service: [*]const u8,183 noalias service: [*:0]const u8,
186 noalias hints: *const addrinfo,184 noalias hints: *const addrinfo,
187 noalias res: **addrinfo,185 noalias res: **addrinfo,
188) c_int;186) c_int;
...@@ -199,15 +197,15 @@ pub extern "c" fn getnameinfo(...@@ -199,15 +197,15 @@ pub extern "c" fn getnameinfo(
199 flags: u32,197 flags: u32,
200) c_int;198) c_int;
201199
202pub extern "c" fn gai_strerror(errcode: c_int) [*]const u8;200pub extern "c" fn gai_strerror(errcode: c_int) [*:0]const u8;
203201
204pub extern "c" fn poll(fds: [*]pollfd, nfds: nfds_t, timeout: c_int) c_int;202pub extern "c" fn poll(fds: [*]pollfd, nfds: nfds_t, timeout: c_int) c_int;
205203
206pub extern "c" fn dn_expand(204pub extern "c" fn dn_expand(
207 msg: [*]const u8,205 msg: [*:0]const u8,
208 eomorig: [*]const u8,206 eomorig: [*:0]const u8,
209 comp_dn: [*]const u8,207 comp_dn: [*:0]const u8,
210 exp_dn: [*]u8,208 exp_dn: [*:0]u8,
211 length: c_int,209 length: c_int,
212) c_int;210) c_int;
213211
lib/std/cstr.zig+4-4
...@@ -9,7 +9,7 @@ pub const line_sep = switch (builtin.os) {...@@ -9,7 +9,7 @@ pub const line_sep = switch (builtin.os) {
9 else => "\n",9 else => "\n",
10};10};
1111
12pub fn cmp(a: [*]const u8, b: [*]const u8) i8 {12pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {
13 var index: usize = 0;13 var index: usize = 0;
14 while (a[index] == b[index] and a[index] != 0) : (index += 1) {}14 while (a[index] == b[index] and a[index] != 0) : (index += 1) {}
15 if (a[index] > b[index]) {15 if (a[index] > b[index]) {
...@@ -33,7 +33,7 @@ fn testCStrFnsImpl() void {...@@ -33,7 +33,7 @@ fn testCStrFnsImpl() void {
3333
34/// Returns a mutable slice with 1 more byte of length which is a null byte.34/// Returns a mutable slice with 1 more byte of length which is a null byte.
35/// Caller owns the returned memory.35/// Caller owns the returned memory.
36pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![]u8 {36pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {
37 const result = try allocator.alloc(u8, slice.len + 1);37 const result = try allocator.alloc(u8, slice.len + 1);
38 mem.copy(u8, result, slice);38 mem.copy(u8, result, slice);
39 result[slice.len] = 0;39 result[slice.len] = 0;
...@@ -43,7 +43,7 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![]u8 {...@@ -43,7 +43,7 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![]u8 {
43pub const NullTerminated2DArray = struct {43pub const NullTerminated2DArray = struct {
44 allocator: *mem.Allocator,44 allocator: *mem.Allocator,
45 byte_count: usize,45 byte_count: usize,
46 ptr: ?[*]?[*]u8,46 ptr: ?[*:null]?[*:0]u8,
4747
48 /// Takes N lists of strings, concatenates the lists together, and adds a null terminator48 /// Takes N lists of strings, concatenates the lists together, and adds a null terminator
49 /// Caller must deinit result49 /// Caller must deinit result
...@@ -83,7 +83,7 @@ pub const NullTerminated2DArray = struct {...@@ -83,7 +83,7 @@ pub const NullTerminated2DArray = struct {
83 return NullTerminated2DArray{83 return NullTerminated2DArray{
84 .allocator = allocator,84 .allocator = allocator,
85 .byte_count = byte_count,85 .byte_count = byte_count,
86 .ptr = @ptrCast(?[*]?[*]u8, buf.ptr),86 .ptr = @ptrCast(?[*:null]?[*:0]u8, buf.ptr),
87 };87 };
88 }88 }
8989
lib/std/net.zig+5-1
...@@ -451,7 +451,11 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -451,7 +451,11 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
451 .next = null,451 .next = null,
452 };452 };
453 var res: *os.addrinfo = undefined;453 var res: *os.addrinfo = undefined;
454 switch (os.system.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res)) {454 switch (os.system.getaddrinfo(
455 name_c.ptr,
456 @ptrCast([*:0]const u8, port_c.ptr),
457 &hints,
458 &res)) {
455 0 => {},459 0 => {},
456 c.EAI_ADDRFAMILY => return error.HostLacksNetworkAddresses,460 c.EAI_ADDRFAMILY => return error.HostLacksNetworkAddresses,
457 c.EAI_AGAIN => return error.TemporaryNameServerFailure,461 c.EAI_AGAIN => return error.TemporaryNameServerFailure,
lib/std/os/linux.zig+38-76
...@@ -65,18 +65,15 @@ pub fn dup3(old: i32, new: i32, flags: u32) usize {...@@ -65,18 +65,15 @@ pub fn dup3(old: i32, new: i32, flags: u32) usize {
65 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);65 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);
66}66}
6767
68// TODO https://github.com/ziglang/zig/issues/26568pub fn chdir(path: [*:0]const u8) usize {
69pub fn chdir(path: [*]const u8) usize {
70 return syscall1(SYS_chdir, @ptrToInt(path));69 return syscall1(SYS_chdir, @ptrToInt(path));
71}70}
7271
73// TODO https://github.com/ziglang/zig/issues/26572pub fn chroot(path: [*:0]const u8) usize {
74pub fn chroot(path: [*]const u8) usize {
75 return syscall1(SYS_chroot, @ptrToInt(path));73 return syscall1(SYS_chroot, @ptrToInt(path));
76}74}
7775
78// TODO https://github.com/ziglang/zig/issues/26576pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) usize {
79pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
80 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));77 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
81}78}
8279
...@@ -101,8 +98,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {...@@ -101,8 +98,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
101 return utimensat(fd, null, times, 0);98 return utimensat(fd, null, times, 0);
102}99}
103100
104// TODO https://github.com/ziglang/zig/issues/265101pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, flags: u32) usize {
105pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize {
106 return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);102 return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
107}103}
108104
...@@ -140,7 +136,7 @@ pub fn inotify_init1(flags: u32) usize {...@@ -140,7 +136,7 @@ pub fn inotify_init1(flags: u32) usize {
140 return syscall1(SYS_inotify_init1, flags);136 return syscall1(SYS_inotify_init1, flags);
141}137}
142138
143pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize {139pub fn inotify_add_watch(fd: i32, pathname: [*:0]const u8, mask: u32) usize {
144 return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);140 return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);
145}141}
146142
...@@ -148,8 +144,7 @@ pub fn inotify_rm_watch(fd: i32, wd: i32) usize {...@@ -148,8 +144,7 @@ pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
148 return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));144 return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));
149}145}
150146
151// TODO https://github.com/ziglang/zig/issues/265147pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
152pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
153 if (@hasDecl(@This(), "SYS_readlink")) {148 if (@hasDecl(@This(), "SYS_readlink")) {
154 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);149 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
155 } else {150 } else {
...@@ -157,13 +152,11 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz...@@ -157,13 +152,11 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz
157 }152 }
158}153}
159154
160// TODO https://github.com/ziglang/zig/issues/265155pub fn readlinkat(dirfd: i32, noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
161pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
162 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);156 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
163}157}
164158
165// TODO https://github.com/ziglang/zig/issues/265159pub fn mkdir(path: [*:0]const u8, mode: u32) usize {
166pub fn mkdir(path: [*]const u8, mode: u32) usize {
167 if (@hasDecl(@This(), "SYS_mkdir")) {160 if (@hasDecl(@This(), "SYS_mkdir")) {
168 return syscall2(SYS_mkdir, @ptrToInt(path), mode);161 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
169 } else {162 } else {
...@@ -171,23 +164,19 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {...@@ -171,23 +164,19 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {
171 }164 }
172}165}
173166
174// TODO https://github.com/ziglang/zig/issues/265167pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize {
175pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize {
176 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);168 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);
177}169}
178170
179// TODO https://github.com/ziglang/zig/issues/265171pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: [*:0]const u8, flags: u32, data: usize) usize {
180pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: u32, data: usize) usize {
181 return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);172 return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);
182}173}
183174
184// TODO https://github.com/ziglang/zig/issues/265175pub fn umount(special: [*:0]const u8) usize {
185pub fn umount(special: [*]const u8) usize {
186 return syscall2(SYS_umount2, @ptrToInt(special), 0);176 return syscall2(SYS_umount2, @ptrToInt(special), 0);
187}177}
188178
189// TODO https://github.com/ziglang/zig/issues/265179pub fn umount2(special: [*:0]const u8, flags: u32) usize {
190pub fn umount2(special: [*]const u8, flags: u32) usize {
191 return syscall2(SYS_umount2, @ptrToInt(special), flags);180 return syscall2(SYS_umount2, @ptrToInt(special), flags);
192}181}
193182
...@@ -307,8 +296,7 @@ pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, f...@@ -307,8 +296,7 @@ pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, f
307 );296 );
308}297}
309298
310// TODO https://github.com/ziglang/zig/issues/265299pub fn rmdir(path: [*:0]const u8) usize {
311pub fn rmdir(path: [*]const u8) usize {
312 if (@hasDecl(@This(), "SYS_rmdir")) {300 if (@hasDecl(@This(), "SYS_rmdir")) {
313 return syscall1(SYS_rmdir, @ptrToInt(path));301 return syscall1(SYS_rmdir, @ptrToInt(path));
314 } else {302 } else {
...@@ -316,8 +304,7 @@ pub fn rmdir(path: [*]const u8) usize {...@@ -316,8 +304,7 @@ pub fn rmdir(path: [*]const u8) usize {
316 }304 }
317}305}
318306
319// TODO https://github.com/ziglang/zig/issues/265307pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize {
320pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
321 if (@hasDecl(@This(), "SYS_symlink")) {308 if (@hasDecl(@This(), "SYS_symlink")) {
322 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));309 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
323 } else {310 } else {
...@@ -325,18 +312,15 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {...@@ -325,18 +312,15 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
325 }312 }
326}313}
327314
328// TODO https://github.com/ziglang/zig/issues/265315pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) usize {
329pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize {
330 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));316 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
331}317}
332318
333// TODO https://github.com/ziglang/zig/issues/265
334pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {319pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
335 return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);320 return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
336}321}
337322
338// TODO https://github.com/ziglang/zig/issues/265323pub fn access(path: [*:0]const u8, mode: u32) usize {
339pub fn access(path: [*]const u8, mode: u32) usize {
340 if (@hasDecl(@This(), "SYS_access")) {324 if (@hasDecl(@This(), "SYS_access")) {
341 return syscall2(SYS_access, @ptrToInt(path), mode);325 return syscall2(SYS_access, @ptrToInt(path), mode);
342 } else {326 } else {
...@@ -344,8 +328,7 @@ pub fn access(path: [*]const u8, mode: u32) usize {...@@ -344,8 +328,7 @@ pub fn access(path: [*]const u8, mode: u32) usize {
344 }328 }
345}329}
346330
347// TODO https://github.com/ziglang/zig/issues/265331pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
348pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
349 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);332 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);
350}333}
351334
...@@ -371,8 +354,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {...@@ -371,8 +354,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
371 return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);354 return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
372}355}
373356
374// TODO https://github.com/ziglang/zig/issues/265357pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {
375pub fn rename(old: [*]const u8, new: [*]const u8) usize {
376 if (@hasDecl(@This(), "SYS_rename")) {358 if (@hasDecl(@This(), "SYS_rename")) {
377 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));359 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
378 } else if (@hasDecl(@This(), "SYS_renameat")) {360 } else if (@hasDecl(@This(), "SYS_renameat")) {
...@@ -403,8 +385,7 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const...@@ -403,8 +385,7 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
403 }385 }
404}386}
405387
406// TODO https://github.com/ziglang/zig/issues/265388pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize {
407pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize {
408 return syscall5(389 return syscall5(
409 SYS_renameat2,390 SYS_renameat2,
410 @bitCast(usize, @as(isize, oldfd)),391 @bitCast(usize, @as(isize, oldfd)),
...@@ -415,8 +396,7 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const...@@ -415,8 +396,7 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
415 );396 );
416}397}
417398
418// TODO https://github.com/ziglang/zig/issues/265399pub fn open(path: [*:0]const u8, flags: u32, perm: usize) usize {
419pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
420 if (@hasDecl(@This(), "SYS_open")) {400 if (@hasDecl(@This(), "SYS_open")) {
421 return syscall3(SYS_open, @ptrToInt(path), flags, perm);401 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
422 } else {402 } else {
...@@ -430,13 +410,11 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {...@@ -430,13 +410,11 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
430 }410 }
431}411}
432412
433// TODO https://github.com/ziglang/zig/issues/265413pub fn create(path: [*:0]const u8, perm: usize) usize {
434pub fn create(path: [*]const u8, perm: usize) usize {
435 return syscall2(SYS_creat, @ptrToInt(path), perm);414 return syscall2(SYS_creat, @ptrToInt(path), perm);
436}415}
437416
438// TODO https://github.com/ziglang/zig/issues/265417pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: usize) usize {
439pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize {
440 // dirfd could be negative, for example AT_FDCWD is -100418 // dirfd could be negative, for example AT_FDCWD is -100
441 return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);419 return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
442}420}
...@@ -490,8 +468,7 @@ pub fn kill(pid: i32, sig: i32) usize {...@@ -490,8 +468,7 @@ pub fn kill(pid: i32, sig: i32) usize {
490 return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));468 return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));
491}469}
492470
493// TODO https://github.com/ziglang/zig/issues/265471pub fn unlink(path: [*:0]const u8) usize {
494pub fn unlink(path: [*]const u8) usize {
495 if (@hasDecl(@This(), "SYS_unlink")) {472 if (@hasDecl(@This(), "SYS_unlink")) {
496 return syscall1(SYS_unlink, @ptrToInt(path));473 return syscall1(SYS_unlink, @ptrToInt(path));
497 } else {474 } else {
...@@ -499,8 +476,7 @@ pub fn unlink(path: [*]const u8) usize {...@@ -499,8 +476,7 @@ pub fn unlink(path: [*]const u8) usize {
499 }476 }
500}477}
501478
502// TODO https://github.com/ziglang/zig/issues/265479pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize {
503pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize {
504 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);480 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);
505}481}
506482
...@@ -903,8 +879,7 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize {...@@ -903,8 +879,7 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize {
903 }879 }
904}880}
905881
906// TODO https://github.com/ziglang/zig/issues/265882pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
907pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
908 if (@hasDecl(@This(), "SYS_stat64")) {883 if (@hasDecl(@This(), "SYS_stat64")) {
909 return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf));884 return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
910 } else {885 } else {
...@@ -912,8 +887,7 @@ pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {...@@ -912,8 +887,7 @@ pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
912 }887 }
913}888}
914889
915// TODO https://github.com/ziglang/zig/issues/265890pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
916pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
917 if (@hasDecl(@This(), "SYS_lstat64")) {891 if (@hasDecl(@This(), "SYS_lstat64")) {
918 return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));892 return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
919 } else {893 } else {
...@@ -921,8 +895,7 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {...@@ -921,8 +895,7 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
921 }895 }
922}896}
923897
924// TODO https://github.com/ziglang/zig/issues/265898pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
925pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
926 if (@hasDecl(@This(), "SYS_fstatat64")) {899 if (@hasDecl(@This(), "SYS_fstatat64")) {
927 return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);900 return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
928 } else {901 } else {
...@@ -944,13 +917,11 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S...@@ -944,13 +917,11 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
944 return @bitCast(usize, @as(isize, -ENOSYS));917 return @bitCast(usize, @as(isize, -ENOSYS));
945}918}
946919
947// TODO https://github.com/ziglang/zig/issues/265920pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
948pub fn listxattr(path: [*]const u8, list: [*]u8, size: usize) usize {
949 return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size);921 return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size);
950}922}
951923
952// TODO https://github.com/ziglang/zig/issues/265924pub fn llistxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
953pub fn llistxattr(path: [*]const u8, list: [*]u8, size: usize) usize {
954 return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size);925 return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size);
955}926}
956927
...@@ -958,48 +929,39 @@ pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize {...@@ -958,48 +929,39 @@ pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize {
958 return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size);929 return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size);
959}930}
960931
961// TODO https://github.com/ziglang/zig/issues/265932pub fn getxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize {
962pub fn getxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize {
963 return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);933 return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
964}934}
965935
966// TODO https://github.com/ziglang/zig/issues/265936pub fn lgetxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize {
967pub fn lgetxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize {
968 return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);937 return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
969}938}
970939
971// TODO https://github.com/ziglang/zig/issues/265940pub fn fgetxattr(fd: usize, name: [*:0]const u8, value: [*]u8, size: usize) usize {
972pub fn fgetxattr(fd: usize, name: [*]const u8, value: [*]u8, size: usize) usize {
973 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);941 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
974}942}
975943
976// TODO https://github.com/ziglang/zig/issues/265944pub fn setxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
977pub fn setxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
978 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);945 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
979}946}
980947
981// TODO https://github.com/ziglang/zig/issues/265948pub fn lsetxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
982pub fn lsetxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
983 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);949 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
984}950}
985951
986// TODO https://github.com/ziglang/zig/issues/265952pub fn fsetxattr(fd: usize, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
987pub fn fsetxattr(fd: usize, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
988 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);953 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
989}954}
990955
991// TODO https://github.com/ziglang/zig/issues/265956pub fn removexattr(path: [*:0]const u8, name: [*:0]const u8) usize {
992pub fn removexattr(path: [*]const u8, name: [*]const u8) usize {
993 return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name));957 return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name));
994}958}
995959
996// TODO https://github.com/ziglang/zig/issues/265960pub fn lremovexattr(path: [*:0]const u8, name: [*:0]const u8) usize {
997pub fn lremovexattr(path: [*]const u8, name: [*]const u8) usize {
998 return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name));961 return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name));
999}962}
1000963
1001// TODO https://github.com/ziglang/zig/issues/265964pub fn fremovexattr(fd: usize, name: [*:0]const u8) usize {
1002pub fn fremovexattr(fd: usize, name: [*]const u8) usize {
1003 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));965 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));
1004}966}
1005967