authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-27 05:15:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-27 05:15:24-04:00
logff2c7946128fac8488e393655e1a3371983b7620
tree15119490155b6f5dd5dd047f2194c0318e3a3a51
parent91536813ec5d159ed4bea857621ed10a1216411a

all behavior tests passing for macos

See #273

17 files changed, 488 insertions(+), 333 deletions(-)

CMakeLists.txt+2-1
...@@ -297,9 +297,10 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}")...@@ -297,9 +297,10 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}")
297install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}")297install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}")
298install(FILES "${CMAKE_SOURCE_DIR}/std/os/child_process.zig" DESTINATION "${ZIG_STD_DEST}/os")298install(FILES "${CMAKE_SOURCE_DIR}/std/os/child_process.zig" DESTINATION "${ZIG_STD_DEST}/os")
299install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin.zig" DESTINATION "${ZIG_STD_DEST}/os")299install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin.zig" DESTINATION "${ZIG_STD_DEST}/os")
300install(FILES "${CMAKE_SOURCE_DIR}/std/os/errno.zig" DESTINATION "${ZIG_STD_DEST}/os")300install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin_errno.zig" DESTINATION "${ZIG_STD_DEST}/os")
301install(FILES "${CMAKE_SOURCE_DIR}/std/os/index.zig" DESTINATION "${ZIG_STD_DEST}/os")301install(FILES "${CMAKE_SOURCE_DIR}/std/os/index.zig" DESTINATION "${ZIG_STD_DEST}/os")
302install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux.zig" DESTINATION "${ZIG_STD_DEST}/os")302install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux.zig" DESTINATION "${ZIG_STD_DEST}/os")
303install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_errno.zig" DESTINATION "${ZIG_STD_DEST}/os")
303install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}/os")304install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}/os")
304install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os")305install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os")
305install(FILES "${CMAKE_SOURCE_DIR}/std/os/path.zig" DESTINATION "${ZIG_STD_DEST}/os")306install(FILES "${CMAKE_SOURCE_DIR}/std/os/path.zig" DESTINATION "${ZIG_STD_DEST}/os")
ci/travis_osx_script+3-1
...@@ -12,5 +12,7 @@ cd build...@@ -12,5 +12,7 @@ cd build
12cmake .. -DCMAKE_PREFIX_PATH=$PREFIX_DIR -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $($CC -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=$(echo -n | $CC -E -x c - -v 2>&1 | grep -B1 "End of search list." | head -n1 | cut -c 2- | sed "s/ .*//") -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $($CC -print-file-name=crtbegin.o))12cmake .. -DCMAKE_PREFIX_PATH=$PREFIX_DIR -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $($CC -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=$(echo -n | $CC -E -x c - -v 2>&1 | grep -B1 "End of search list." | head -n1 | cut -c 2- | sed "s/ .*//") -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $($CC -print-file-name=crtbegin.o))
13make VERBOSE=113make VERBOSE=1
14make install14make install
15# TODO get tests passing on macos15# TODO get full test suite passing on macos
16./zig test ../test/behavior.zig
17./zig test ../test/behavior.zig --release-fast
16# ./zig build --build-file ../build.zig test18# ./zig build --build-file ../build.zig test
src/link.cpp+4
...@@ -325,6 +325,10 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -325,6 +325,10 @@ static void construct_linker_job_elf(LinkJob *lj) {
325 lj->args.append(get_libc_static_file(g, "crtend.o"));325 lj->args.append(get_libc_static_file(g, "crtend.o"));
326 lj->args.append(get_libc_file(g, "crtn.o"));326 lj->args.append(get_libc_file(g, "crtn.o"));
327 }327 }
328
329 if (!g->is_native_target) {
330 lj->args.append("--allow-shlib-undefined");
331 }
328}332}
329333
330static bool is_target_cyg_mingw(const ZigTarget *target) {334static bool is_target_cyg_mingw(const ZigTarget *target) {
std/c/darwin.zig+2
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1extern "c" fn __error() -> &c_int;1extern "c" fn __error() -> &c_int;
22
3pub use @import("../os/darwin_errno.zig");
4
3pub const _errno = __error;5pub const _errno = __error;
46
5/// Renamed to Stat to not conflict with the stat function.7/// Renamed to Stat to not conflict with the stat function.
std/c/index.zig-1
...@@ -1,4 +1,3 @@...@@ -1,4 +1,3 @@
1pub use @import("../os/errno.zig");
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const Os = builtin.Os;2const Os = builtin.Os;
43
std/c/linux.zig+2
...@@ -1,3 +1,5 @@...@@ -1,3 +1,5 @@
1pub use @import("../os/linux_errno.zig");
2
1pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) -> c_int;3pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) -> c_int;
2extern "c" fn __errno_location() -> &c_int;4extern "c" fn __errno_location() -> &c_int;
3pub const _errno = __errno_location;5pub const _errno = __errno_location;
std/io.zig+22-23
...@@ -8,7 +8,6 @@ const system = switch(builtin.os) {...@@ -8,7 +8,6 @@ const system = switch(builtin.os) {
8};8};
9const c = @import("c/index.zig");9const c = @import("c/index.zig");
1010
11const errno = @import("os/errno.zig");
12const math = @import("math/index.zig");11const math = @import("math/index.zig");
13const debug = @import("debug.zig");12const debug = @import("debug.zig");
14const assert = debug.assert;13const assert = debug.assert;
...@@ -269,11 +268,11 @@ pub const InStream = struct {...@@ -269,11 +268,11 @@ pub const InStream = struct {
269 const read_err = system.getErrno(amt_read);268 const read_err = system.getErrno(amt_read);
270 if (read_err > 0) {269 if (read_err > 0) {
271 switch (read_err) {270 switch (read_err) {
272 errno.EINTR => continue,271 system.EINTR => continue,
273 errno.EINVAL => unreachable,272 system.EINVAL => unreachable,
274 errno.EFAULT => unreachable,273 system.EFAULT => unreachable,
275 errno.EBADF => return error.BadFd,274 system.EBADF => return error.BadFd,
276 errno.EIO => return error.Io,275 system.EIO => return error.Io,
277 else => return error.Unexpected,276 else => return error.Unexpected,
278 }277 }
279 }278 }
...@@ -335,11 +334,11 @@ pub const InStream = struct {...@@ -335,11 +334,11 @@ pub const InStream = struct {
335 const err = system.getErrno(result);334 const err = system.getErrno(result);
336 if (err > 0) {335 if (err > 0) {
337 return switch (err) {336 return switch (err) {
338 errno.EBADF => error.BadFd,337 system.EBADF => error.BadFd,
339 errno.EINVAL => error.Unseekable,338 system.EINVAL => error.Unseekable,
340 errno.EOVERFLOW => error.Unseekable,339 system.EOVERFLOW => error.Unseekable,
341 errno.ESPIPE => error.Unseekable,340 system.ESPIPE => error.Unseekable,
342 errno.ENXIO => error.Unseekable,341 system.ENXIO => error.Unseekable,
343 else => error.Unexpected,342 else => error.Unexpected,
344 };343 };
345 }344 }
...@@ -355,11 +354,11 @@ pub const InStream = struct {...@@ -355,11 +354,11 @@ pub const InStream = struct {
355 const err = system.getErrno(result);354 const err = system.getErrno(result);
356 if (err > 0) {355 if (err > 0) {
357 return switch (err) {356 return switch (err) {
358 errno.EBADF => error.BadFd,357 system.EBADF => error.BadFd,
359 errno.EINVAL => error.Unseekable,358 system.EINVAL => error.Unseekable,
360 errno.EOVERFLOW => error.Unseekable,359 system.EOVERFLOW => error.Unseekable,
361 errno.ESPIPE => error.Unseekable,360 system.ESPIPE => error.Unseekable,
362 errno.ENXIO => error.Unseekable,361 system.ENXIO => error.Unseekable,
363 else => error.Unexpected,362 else => error.Unexpected,
364 };363 };
365 }364 }
...@@ -375,11 +374,11 @@ pub const InStream = struct {...@@ -375,11 +374,11 @@ pub const InStream = struct {
375 const err = system.getErrno(result);374 const err = system.getErrno(result);
376 if (err > 0) {375 if (err > 0) {
377 return switch (err) {376 return switch (err) {
378 errno.EBADF => error.BadFd,377 system.EBADF => error.BadFd,
379 errno.EINVAL => error.Unseekable,378 system.EINVAL => error.Unseekable,
380 errno.EOVERFLOW => error.Unseekable,379 system.EOVERFLOW => error.Unseekable,
381 errno.ESPIPE => error.Unseekable,380 system.ESPIPE => error.Unseekable,
382 errno.ENXIO => error.Unseekable,381 system.ENXIO => error.Unseekable,
383 else => error.Unexpected,382 else => error.Unexpected,
384 };383 };
385 }384 }
...@@ -394,8 +393,8 @@ pub const InStream = struct {...@@ -394,8 +393,8 @@ pub const InStream = struct {
394 const err = system.getErrno(system.fstat(is.fd, &stat));393 const err = system.getErrno(system.fstat(is.fd, &stat));
395 if (err > 0) {394 if (err > 0) {
396 return switch (err) {395 return switch (err) {
397 errno.EBADF => error.BadFd,396 system.EBADF => error.BadFd,
398 errno.ENOMEM => error.NoMem,397 system.ENOMEM => error.NoMem,
399 else => error.Unexpected,398 else => error.Unexpected,
400 }399 }
401 }400 }
std/net.zig+15-16
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const linux = @import("os/linux.zig");1const linux = @import("os/linux.zig");
2const errno = @import("os/errno.zig");
3const assert = @import("debug.zig").assert;2const assert = @import("debug.zig").assert;
4const endian = @import("endian.zig");3const endian = @import("endian.zig");
54
...@@ -21,10 +20,10 @@ const Connection = struct {...@@ -21,10 +20,10 @@ const Connection = struct {
21 const send_err = linux.getErrno(send_ret);20 const send_err = linux.getErrno(send_ret);
22 switch (send_err) {21 switch (send_err) {
23 0 => return send_ret,22 0 => return send_ret,
24 errno.EINVAL => unreachable,23 linux.EINVAL => unreachable,
25 errno.EFAULT => unreachable,24 linux.EFAULT => unreachable,
26 errno.ECONNRESET => return error.ConnectionReset,25 linux.ECONNRESET => return error.ConnectionReset,
27 errno.EINTR => return error.SigInterrupt,26 linux.EINTR => return error.SigInterrupt,
28 // TODO there are more possible errors27 // TODO there are more possible errors
29 else => return error.Unexpected,28 else => return error.Unexpected,
30 }29 }
...@@ -35,13 +34,13 @@ const Connection = struct {...@@ -35,13 +34,13 @@ const Connection = struct {
35 const recv_err = linux.getErrno(recv_ret);34 const recv_err = linux.getErrno(recv_ret);
36 switch (recv_err) {35 switch (recv_err) {
37 0 => return buf[0..recv_ret],36 0 => return buf[0..recv_ret],
38 errno.EINVAL => unreachable,37 linux.EINVAL => unreachable,
39 errno.EFAULT => unreachable,38 linux.EFAULT => unreachable,
40 errno.ENOTSOCK => return error.NotSocket,39 linux.ENOTSOCK => return error.NotSocket,
41 errno.EINTR => return error.SigInterrupt,40 linux.EINTR => return error.SigInterrupt,
42 errno.ENOMEM => return error.NoMem,41 linux.ENOMEM => return error.NoMem,
43 errno.ECONNREFUSED => return error.ConnectionRefused,42 linux.ECONNREFUSED => return error.ConnectionRefused,
44 errno.EBADF => return error.BadFd,43 linux.EBADF => return error.BadFd,
45 // TODO more error values44 // TODO more error values
46 else => return error.Unexpected,45 else => return error.Unexpected,
47 }46 }
...@@ -50,9 +49,9 @@ const Connection = struct {...@@ -50,9 +49,9 @@ const Connection = struct {
50 pub fn close(c: Connection) -> %void {49 pub fn close(c: Connection) -> %void {
51 switch (linux.getErrno(linux.close(c.socket_fd))) {50 switch (linux.getErrno(linux.close(c.socket_fd))) {
52 0 => return,51 0 => return,
53 errno.EBADF => unreachable,52 linux.EBADF => unreachable,
54 errno.EINTR => return error.SigInterrupt,53 linux.EINTR => return error.SigInterrupt,
55 errno.EIO => return error.Io,54 linux.EIO => return error.Io,
56 else => return error.Unexpected,55 else => return error.Unexpected,
57 }56 }
58 }57 }
...@@ -119,7 +118,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {...@@ -119,7 +118,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
119 const connect_err = linux.getErrno(connect_ret);118 const connect_err = linux.getErrno(connect_ret);
120 if (connect_err > 0) {119 if (connect_err > 0) {
121 switch (connect_err) {120 switch (connect_err) {
122 errno.ETIMEDOUT => return error.TimedOut,121 linux.ETIMEDOUT => return error.TimedOut,
123 else => {122 else => {
124 // TODO figure out possible errors from connect()123 // TODO figure out possible errors from connect()
125 return error.Unexpected;124 return error.Unexpected;
std/os/child_process.zig+4-5
...@@ -3,7 +3,6 @@ const os = @import("index.zig");...@@ -3,7 +3,6 @@ const os = @import("index.zig");
3const posix = os.posix;3const posix = os.posix;
4const mem = @import("../mem.zig");4const mem = @import("../mem.zig");
5const Allocator = mem.Allocator;5const Allocator = mem.Allocator;
6const errno = @import("errno.zig");
7const debug = @import("../debug.zig");6const debug = @import("../debug.zig");
8const assert = debug.assert;7const assert = debug.assert;
9const BufMap = @import("../buf_map.zig").BufMap;8const BufMap = @import("../buf_map.zig").BufMap;
...@@ -56,8 +55,8 @@ pub const ChildProcess = struct {...@@ -56,8 +55,8 @@ pub const ChildProcess = struct {
56 const err = posix.getErrno(posix.waitpid(self.pid, &status, 0));55 const err = posix.getErrno(posix.waitpid(self.pid, &status, 0));
57 if (err > 0) {56 if (err > 0) {
58 switch (err) {57 switch (err) {
59 errno.EINVAL, errno.ECHILD => unreachable,58 posix.EINVAL, posix.ECHILD => unreachable,
60 errno.EINTR => continue,59 posix.EINTR => continue,
61 else => {60 else => {
62 if (self.stdin) |*stdin| { stdin.close(); }61 if (self.stdin) |*stdin| { stdin.close(); }
63 if (self.stdout) |*stdout| { stdout.close(); }62 if (self.stdout) |*stdout| { stdout.close(); }
...@@ -130,7 +129,7 @@ pub const ChildProcess = struct {...@@ -130,7 +129,7 @@ pub const ChildProcess = struct {
130 const pid_err = posix.getErrno(pid);129 const pid_err = posix.getErrno(pid);
131 if (pid_err > 0) {130 if (pid_err > 0) {
132 return switch (pid_err) {131 return switch (pid_err) {
133 errno.EAGAIN, errno.ENOMEM, errno.ENOSYS => error.SystemResources,132 posix.EAGAIN, posix.ENOMEM, posix.ENOSYS => error.SystemResources,
134 else => error.Unexpected,133 else => error.Unexpected,
135 };134 };
136 }135 }
...@@ -209,7 +208,7 @@ fn makePipe() -> %[2]i32 {...@@ -209,7 +208,7 @@ fn makePipe() -> %[2]i32 {
209 const err = posix.getErrno(posix.pipe(&fds));208 const err = posix.getErrno(posix.pipe(&fds));
210 if (err > 0) {209 if (err > 0) {
211 return switch (err) {210 return switch (err) {
212 errno.EMFILE, errno.ENFILE => error.SystemResources,211 posix.EMFILE, posix.ENFILE => error.SystemResources,
213 else => error.Unexpected,212 else => error.Unexpected,
214 }213 }
215 }214 }
std/os/darwin.zig+2
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const c = @import("../c/index.zig");1const c = @import("../c/index.zig");
2const assert = @import("../debug.zig").assert;2const assert = @import("../debug.zig").assert;
33
4pub use @import("darwin_errno.zig");
5
4pub const STDIN_FILENO = 0;6pub const STDIN_FILENO = 0;
5pub const STDOUT_FILENO = 1;7pub const STDOUT_FILENO = 1;
6pub const STDERR_FILENO = 2;8pub const STDERR_FILENO = 2;
std/os/darwin_errno.zig created+142
...@@ -0,0 +1,142 @@
1
2pub const EPERM = 1; /// Operation not permitted
3pub const ENOENT = 2; /// No such file or directory
4pub const ESRCH = 3; /// No such process
5pub const EINTR = 4; /// Interrupted system call
6pub const EIO = 5; /// Input/output error
7pub const ENXIO = 6; /// Device not configured
8pub const E2BIG = 7; /// Argument list too long
9pub const ENOEXEC = 8; /// Exec format error
10pub const EBADF = 9; /// Bad file descriptor
11pub const ECHILD = 10; /// No child processes
12pub const EDEADLK = 11; /// Resource deadlock avoided
13
14pub const ENOMEM = 12; /// Cannot allocate memory
15pub const EACCES = 13; /// Permission denied
16pub const EFAULT = 14; /// Bad address
17pub const ENOTBLK = 15; /// Block device required
18pub const EBUSY = 16; /// Device / Resource busy
19pub const EEXIST = 17; /// File exists
20pub const EXDEV = 18; /// Cross-device link
21pub const ENODEV = 19; /// Operation not supported by device
22pub const ENOTDIR = 20; /// Not a directory
23pub const EISDIR = 21; /// Is a directory
24pub const EINVAL = 22; /// Invalid argument
25pub const ENFILE = 23; /// Too many open files in system
26pub const EMFILE = 24; /// Too many open files
27pub const ENOTTY = 25; /// Inappropriate ioctl for device
28pub const ETXTBSY = 26; /// Text file busy
29pub const EFBIG = 27; /// File too large
30pub const ENOSPC = 28; /// No space left on device
31pub const ESPIPE = 29; /// Illegal seek
32pub const EROFS = 30; /// Read-only file system
33pub const EMLINK = 31; /// Too many links
34pub const EPIPE = 32; /// Broken pipe
35
36// math software
37pub const EDOM = 33; /// Numerical argument out of domain
38pub const ERANGE = 34; /// Result too large
39
40// non-blocking and interrupt i/o
41pub const EAGAIN = 35; /// Resource temporarily unavailable
42pub const EWOULDBLOCK = EAGAIN; /// Operation would block
43pub const EINPROGRESS = 36; /// Operation now in progress
44pub const EALREADY = 37; /// Operation already in progress
45
46// ipc/network software -- argument errors
47pub const ENOTSOCK = 38; /// Socket operation on non-socket
48pub const EDESTADDRREQ = 39; /// Destination address required
49pub const EMSGSIZE = 40; /// Message too long
50pub const EPROTOTYPE = 41; /// Protocol wrong type for socket
51pub const ENOPROTOOPT = 42; /// Protocol not available
52pub const EPROTONOSUPPORT = 43; /// Protocol not supported
53
54pub const ESOCKTNOSUPPORT = 44; /// Socket type not supported
55
56pub const ENOTSUP = 45; /// Operation not supported
57
58pub const EPFNOSUPPORT = 46; /// Protocol family not supported
59pub const EAFNOSUPPORT = 47; /// Address family not supported by protocol family
60pub const EADDRINUSE = 48; /// Address already in use
61pub const EADDRNOTAVAIL = 49; /// Can't assign requested address
62
63// ipc/network software -- operational errors
64pub const ENETDOWN = 50; /// Network is down
65pub const ENETUNREACH = 51; /// Network is unreachable
66pub const ENETRESET = 52; /// Network dropped connection on reset
67pub const ECONNABORTED = 53; /// Software caused connection abort
68pub const ECONNRESET = 54; /// Connection reset by peer
69pub const ENOBUFS = 55; /// No buffer space available
70pub const EISCONN = 56; /// Socket is already connected
71pub const ENOTCONN = 57; /// Socket is not connected
72
73pub const ESHUTDOWN = 58; /// Can't send after socket shutdown
74pub const ETOOMANYREFS = 59; /// Too many references: can't splice
75
76pub const ETIMEDOUT = 60; /// Operation timed out
77pub const ECONNREFUSED = 61; /// Connection refused
78
79pub const ELOOP = 62; /// Too many levels of symbolic links
80pub const ENAMETOOLONG = 63; /// File name too long
81
82pub const EHOSTDOWN = 64; /// Host is down
83pub const EHOSTUNREACH = 65; /// No route to host
84pub const ENOTEMPTY = 66; /// Directory not empty
85
86// quotas & mush
87pub const EPROCLIM = 67; /// Too many processes
88pub const EUSERS = 68; /// Too many users
89pub const EDQUOT = 69; /// Disc quota exceeded
90
91// Network File System
92pub const ESTALE = 70; /// Stale NFS file handle
93pub const EREMOTE = 71; /// Too many levels of remote in path
94pub const EBADRPC = 72; /// RPC struct is bad
95pub const ERPCMISMATCH = 73; /// RPC version wrong
96pub const EPROGUNAVAIL = 74; /// RPC prog. not avail
97pub const EPROGMISMATCH = 75; /// Program version wrong
98pub const EPROCUNAVAIL = 76; /// Bad procedure for program
99
100pub const ENOLCK = 77; /// No locks available
101pub const ENOSYS = 78; /// Function not implemented
102
103pub const EFTYPE = 79; /// Inappropriate file type or format
104pub const EAUTH = 80; /// Authentication error
105pub const ENEEDAUTH = 81; /// Need authenticator
106
107// Intelligent device errors
108pub const EPWROFF = 82; /// Device power is off
109pub const EDEVERR = 83; /// Device error, e.g. paper out
110
111pub const EOVERFLOW = 84; /// Value too large to be stored in data type
112
113// Program loading errors
114pub const EBADEXEC = 85; /// Bad executable
115pub const EBADARCH = 86; /// Bad CPU type in executable
116pub const ESHLIBVERS = 87; /// Shared library version mismatch
117pub const EBADMACHO = 88; /// Malformed Macho file
118
119pub const ECANCELED = 89; /// Operation canceled
120
121pub const EIDRM = 90; /// Identifier removed
122pub const ENOMSG = 91; /// No message of desired type
123pub const EILSEQ = 92; /// Illegal byte sequence
124pub const ENOATTR = 93; /// Attribute not found
125
126pub const EBADMSG = 94; /// Bad message
127pub const EMULTIHOP = 95; /// Reserved
128pub const ENODATA = 96; /// No message available on STREAM
129pub const ENOLINK = 97; /// Reserved
130pub const ENOSR = 98; /// No STREAM resources
131pub const ENOSTR = 99; /// Not a STREAM
132pub const EPROTO = 100; /// Protocol error
133pub const ETIME = 101; /// STREAM ioctl timeout
134
135pub const ENOPOLICY = 103; /// No such policy registered
136
137pub const ENOTRECOVERABLE = 104; /// State not recoverable
138pub const EOWNERDEAD = 105; /// Previous owner died
139
140pub const EQFULL = 106; /// Interface output queue is full
141pub const ELAST = 106; /// Must be equal largest errno
142
std/os/errno.zig deleted-146
...@@ -1,146 +0,0 @@
1pub const EPERM = 1; /// Operation not permitted
2pub const ENOENT = 2; /// No such file or directory
3pub const ESRCH = 3; /// No such process
4pub const EINTR = 4; /// Interrupted system call
5pub const EIO = 5; /// I/O error
6pub const ENXIO = 6; /// No such device or address
7pub const E2BIG = 7; /// Arg list too long
8pub const ENOEXEC = 8; /// Exec format error
9pub const EBADF = 9; /// Bad file number
10pub const ECHILD = 10; /// No child processes
11pub const EAGAIN = 11; /// Try again
12pub const ENOMEM = 12; /// Out of memory
13pub const EACCES = 13; /// Permission denied
14pub const EFAULT = 14; /// Bad address
15pub const ENOTBLK = 15; /// Block device required
16pub const EBUSY = 16; /// Device or resource busy
17pub const EEXIST = 17; /// File exists
18pub const EXDEV = 18; /// Cross-device link
19pub const ENODEV = 19; /// No such device
20pub const ENOTDIR = 20; /// Not a directory
21pub const EISDIR = 21; /// Is a directory
22pub const EINVAL = 22; /// Invalid argument
23pub const ENFILE = 23; /// File table overflow
24pub const EMFILE = 24; /// Too many open files
25pub const ENOTTY = 25; /// Not a typewriter
26pub const ETXTBSY = 26; /// Text file busy
27pub const EFBIG = 27; /// File too large
28pub const ENOSPC = 28; /// No space left on device
29pub const ESPIPE = 29; /// Illegal seek
30pub const EROFS = 30; /// Read-only file system
31pub const EMLINK = 31; /// Too many links
32pub const EPIPE = 32; /// Broken pipe
33pub const EDOM = 33; /// Math argument out of domain of func
34pub const ERANGE = 34; /// Math result not representable
35pub const EDEADLK = 35; /// Resource deadlock would occur
36pub const ENAMETOOLONG = 36; /// File name too long
37pub const ENOLCK = 37; /// No record locks available
38pub const ENOSYS = 38; /// Function not implemented
39pub const ENOTEMPTY = 39; /// Directory not empty
40pub const ELOOP = 40; /// Too many symbolic links encountered
41pub const EWOULDBLOCK = EAGAIN; /// Operation would block
42pub const ENOMSG = 42; /// No message of desired type
43pub const EIDRM = 43; /// Identifier removed
44pub const ECHRNG = 44; /// Channel number out of range
45pub const EL2NSYNC = 45; /// Level 2 not synchronized
46pub const EL3HLT = 46; /// Level 3 halted
47pub const EL3RST = 47; /// Level 3 reset
48pub const ELNRNG = 48; /// Link number out of range
49pub const EUNATCH = 49; /// Protocol driver not attached
50pub const ENOCSI = 50; /// No CSI structure available
51pub const EL2HLT = 51; /// Level 2 halted
52pub const EBADE = 52; /// Invalid exchange
53pub const EBADR = 53; /// Invalid request descriptor
54pub const EXFULL = 54; /// Exchange full
55pub const ENOANO = 55; /// No anode
56pub const EBADRQC = 56; /// Invalid request code
57pub const EBADSLT = 57; /// Invalid slot
58
59pub const EBFONT = 59; /// Bad font file format
60pub const ENOSTR = 60; /// Device not a stream
61pub const ENODATA = 61; /// No data available
62pub const ETIME = 62; /// Timer expired
63pub const ENOSR = 63; /// Out of streams resources
64pub const ENONET = 64; /// Machine is not on the network
65pub const ENOPKG = 65; /// Package not installed
66pub const EREMOTE = 66; /// Object is remote
67pub const ENOLINK = 67; /// Link has been severed
68pub const EADV = 68; /// Advertise error
69pub const ESRMNT = 69; /// Srmount error
70pub const ECOMM = 70; /// Communication error on send
71pub const EPROTO = 71; /// Protocol error
72pub const EMULTIHOP = 72; /// Multihop attempted
73pub const EDOTDOT = 73; /// RFS specific error
74pub const EBADMSG = 74; /// Not a data message
75pub const EOVERFLOW = 75; /// Value too large for defined data type
76pub const ENOTUNIQ = 76; /// Name not unique on network
77pub const EBADFD = 77; /// File descriptor in bad state
78pub const EREMCHG = 78; /// Remote address changed
79pub const ELIBACC = 79; /// Can not access a needed shared library
80pub const ELIBBAD = 80; /// Accessing a corrupted shared library
81pub const ELIBSCN = 81; /// .lib section in a.out corrupted
82pub const ELIBMAX = 82; /// Attempting to link in too many shared libraries
83pub const ELIBEXEC = 83; /// Cannot exec a shared library directly
84pub const EILSEQ = 84; /// Illegal byte sequence
85pub const ERESTART = 85; /// Interrupted system call should be restarted
86pub const ESTRPIPE = 86; /// Streams pipe error
87pub const EUSERS = 87; /// Too many users
88pub const ENOTSOCK = 88; /// Socket operation on non-socket
89pub const EDESTADDRREQ = 89; /// Destination address required
90pub const EMSGSIZE = 90; /// Message too long
91pub const EPROTOTYPE = 91; /// Protocol wrong type for socket
92pub const ENOPROTOOPT = 92; /// Protocol not available
93pub const EPROTONOSUPPORT = 93; /// Protocol not supported
94pub const ESOCKTNOSUPPORT = 94; /// Socket type not supported
95pub const EOPNOTSUPP = 95; /// Operation not supported on transport endpoint
96pub const EPFNOSUPPORT = 96; /// Protocol family not supported
97pub const EAFNOSUPPORT = 97; /// Address family not supported by protocol
98pub const EADDRINUSE = 98; /// Address already in use
99pub const EADDRNOTAVAIL = 99; /// Cannot assign requested address
100pub const ENETDOWN = 100; /// Network is down
101pub const ENETUNREACH = 101; /// Network is unreachable
102pub const ENETRESET = 102; /// Network dropped connection because of reset
103pub const ECONNABORTED = 103; /// Software caused connection abort
104pub const ECONNRESET = 104; /// Connection reset by peer
105pub const ENOBUFS = 105; /// No buffer space available
106pub const EISCONN = 106; /// Transport endpoint is already connected
107pub const ENOTCONN = 107; /// Transport endpoint is not connected
108pub const ESHUTDOWN = 108; /// Cannot send after transport endpoint shutdown
109pub const ETOOMANYREFS = 109; /// Too many references: cannot splice
110pub const ETIMEDOUT = 110; /// Connection timed out
111pub const ECONNREFUSED = 111; /// Connection refused
112pub const EHOSTDOWN = 112; /// Host is down
113pub const EHOSTUNREACH = 113; /// No route to host
114pub const EALREADY = 114; /// Operation already in progress
115pub const EINPROGRESS = 115; /// Operation now in progress
116pub const ESTALE = 116; /// Stale NFS file handle
117pub const EUCLEAN = 117; /// Structure needs cleaning
118pub const ENOTNAM = 118; /// Not a XENIX named type file
119pub const ENAVAIL = 119; /// No XENIX semaphores available
120pub const EISNAM = 120; /// Is a named type file
121pub const EREMOTEIO = 121; /// Remote I/O error
122pub const EDQUOT = 122; /// Quota exceeded
123
124pub const ENOMEDIUM = 123; /// No medium found
125pub const EMEDIUMTYPE = 124; /// Wrong medium type
126
127// nameserver query return codes
128pub const ENSROK = 0; /// DNS server returned answer with no data
129pub const ENSRNODATA = 160; /// DNS server returned answer with no data
130pub const ENSRFORMERR = 161; /// DNS server claims query was misformatted
131pub const ENSRSERVFAIL = 162; /// DNS server returned general failure
132pub const ENSRNOTFOUND = 163; /// Domain name not found
133pub const ENSRNOTIMP = 164; /// DNS server does not implement requested operation
134pub const ENSRREFUSED = 165; /// DNS server refused query
135pub const ENSRBADQUERY = 166; /// Misformatted DNS query
136pub const ENSRBADNAME = 167; /// Misformatted domain name
137pub const ENSRBADFAMILY = 168; /// Unsupported address family
138pub const ENSRBADRESP = 169; /// Misformatted DNS reply
139pub const ENSRCONNREFUSED = 170; /// Could not contact DNS servers
140pub const ENSRTIMEOUT = 171; /// Timeout while contacting DNS servers
141pub const ENSROF = 172; /// End of file
142pub const ENSRFILE = 173; /// Error reading file
143pub const ENSRNOMEM = 174; /// Out of memory
144pub const ENSRDESTRUCTION = 175; /// Application terminated lookup
145pub const ENSRQUERYDOMAINTOOLONG = 176; /// Domain name is too long
146pub const ENSRCNAMELOOP = 177; /// Domain name is too long
std/os/index.zig+133-134
...@@ -23,7 +23,6 @@ pub const page_size = 4 * 1024;...@@ -23,7 +23,6 @@ pub const page_size = 4 * 1024;
23const debug = @import("../debug.zig");23const debug = @import("../debug.zig");
24const assert = debug.assert;24const assert = debug.assert;
2525
26const errno = @import("errno.zig");
27const c = @import("../c/index.zig");26const c = @import("../c/index.zig");
2827
29const mem = @import("../mem.zig");28const mem = @import("../mem.zig");
...@@ -63,9 +62,9 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -63,9 +62,9 @@ pub fn getRandomBytes(buf: []u8) -> %void {
63 const err = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));62 const err = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));
64 if (err > 0) {63 if (err > 0) {
65 return switch (err) {64 return switch (err) {
66 errno.EINVAL => unreachable,65 posix.EINVAL => unreachable,
67 errno.EFAULT => unreachable,66 posix.EFAULT => unreachable,
68 errno.EINTR => continue,67 posix.EINTR => continue,
69 else => error.Unexpected,68 else => error.Unexpected,
70 }69 }
71 }70 }
...@@ -117,7 +116,7 @@ pub coldcc fn abort() -> noreturn {...@@ -117,7 +116,7 @@ pub coldcc fn abort() -> noreturn {
117pub fn posixClose(fd: i32) {116pub fn posixClose(fd: i32) {
118 while (true) {117 while (true) {
119 const err = posix.getErrno(posix.close(fd));118 const err = posix.getErrno(posix.close(fd));
120 if (err == errno.EINTR) {119 if (err == posix.EINTR) {
121 continue;120 continue;
122 } else {121 } else {
123 return;122 return;
...@@ -133,13 +132,13 @@ pub fn posixRead(fd: i32, buf: []u8) -> %void {...@@ -133,13 +132,13 @@ pub fn posixRead(fd: i32, buf: []u8) -> %void {
133 const err = posix.getErrno(amt_written);132 const err = posix.getErrno(amt_written);
134 if (err > 0) {133 if (err > 0) {
135 return switch (err) {134 return switch (err) {
136 errno.EINTR => continue,135 posix.EINTR => continue,
137 errno.EINVAL, errno.EFAULT => unreachable,136 posix.EINVAL, posix.EFAULT => unreachable,
138 errno.EAGAIN => error.WouldBlock,137 posix.EAGAIN => error.WouldBlock,
139 errno.EBADF => error.FileClosed,138 posix.EBADF => error.FileClosed,
140 errno.EIO => error.InputOutput,139 posix.EIO => error.InputOutput,
141 errno.EISDIR => error.IsDir,140 posix.EISDIR => error.IsDir,
142 errno.ENOBUFS, errno.ENOMEM => error.SystemResources,141 posix.ENOBUFS, posix.ENOMEM => error.SystemResources,
143 else => return error.Unexpected,142 else => return error.Unexpected,
144 }143 }
145 }144 }
...@@ -164,17 +163,17 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {...@@ -164,17 +163,17 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
164 const write_err = posix.getErrno(write_ret);163 const write_err = posix.getErrno(write_ret);
165 if (write_err > 0) {164 if (write_err > 0) {
166 return switch (write_err) {165 return switch (write_err) {
167 errno.EINTR => continue,166 posix.EINTR => continue,
168 errno.EINVAL, errno.EFAULT => unreachable,167 posix.EINVAL, posix.EFAULT => unreachable,
169 errno.EAGAIN => error.WouldBlock,168 posix.EAGAIN => error.WouldBlock,
170 errno.EBADF => error.FileClosed,169 posix.EBADF => error.FileClosed,
171 errno.EDESTADDRREQ => error.DestinationAddressRequired,170 posix.EDESTADDRREQ => error.DestinationAddressRequired,
172 errno.EDQUOT => error.DiskQuota,171 posix.EDQUOT => error.DiskQuota,
173 errno.EFBIG => error.FileTooBig,172 posix.EFBIG => error.FileTooBig,
174 errno.EIO => error.InputOutput,173 posix.EIO => error.InputOutput,
175 errno.ENOSPC => error.NoSpaceLeft,174 posix.ENOSPC => error.NoSpaceLeft,
176 errno.EPERM => error.AccessDenied,175 posix.EPERM => error.AccessDenied,
177 errno.EPIPE => error.BrokenPipe,176 posix.EPIPE => error.BrokenPipe,
178 else => error.Unexpected,177 else => error.Unexpected,
179 }178 }
180 }179 }
...@@ -256,23 +255,23 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al...@@ -256,23 +255,23 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al
256 const err = posix.getErrno(result);255 const err = posix.getErrno(result);
257 if (err > 0) {256 if (err > 0) {
258 return switch (err) {257 return switch (err) {
259 errno.EINTR => continue,258 posix.EINTR => continue,
260259
261 errno.EFAULT => unreachable,260 posix.EFAULT => unreachable,
262 errno.EINVAL => unreachable,261 posix.EINVAL => unreachable,
263 errno.EACCES => error.AccessDenied,262 posix.EACCES => error.AccessDenied,
264 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,263 posix.EFBIG, posix.EOVERFLOW => error.FileTooBig,
265 errno.EISDIR => error.IsDir,264 posix.EISDIR => error.IsDir,
266 errno.ELOOP => error.SymLinkLoop,265 posix.ELOOP => error.SymLinkLoop,
267 errno.EMFILE => error.ProcessFdQuotaExceeded,266 posix.EMFILE => error.ProcessFdQuotaExceeded,
268 errno.ENAMETOOLONG => error.NameTooLong,267 posix.ENAMETOOLONG => error.NameTooLong,
269 errno.ENFILE => error.SystemFdQuotaExceeded,268 posix.ENFILE => error.SystemFdQuotaExceeded,
270 errno.ENODEV => error.NoDevice,269 posix.ENODEV => error.NoDevice,
271 errno.ENOENT => error.PathNotFound,270 posix.ENOENT => error.PathNotFound,
272 errno.ENOMEM => error.SystemResources,271 posix.ENOMEM => error.SystemResources,
273 errno.ENOSPC => error.NoSpaceLeft,272 posix.ENOSPC => error.NoSpaceLeft,
274 errno.ENOTDIR => error.NotDir,273 posix.ENOTDIR => error.NotDir,
275 errno.EPERM => error.AccessDenied,274 posix.EPERM => error.AccessDenied,
276 else => error.Unexpected,275 else => error.Unexpected,
277 }276 }
278 }277 }
...@@ -285,9 +284,9 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void {...@@ -285,9 +284,9 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void {
285 const err = posix.getErrno(posix.dup2(old_fd, new_fd));284 const err = posix.getErrno(posix.dup2(old_fd, new_fd));
286 if (err > 0) {285 if (err > 0) {
287 return switch (err) {286 return switch (err) {
288 errno.EBUSY, errno.EINTR => continue,287 posix.EBUSY, posix.EINTR => continue,
289 errno.EMFILE => error.ProcessFdQuotaExceeded,288 posix.EMFILE => error.ProcessFdQuotaExceeded,
290 errno.EINVAL => unreachable,289 posix.EINVAL => unreachable,
291 else => error.Unexpected,290 else => error.Unexpected,
292 };291 };
293 }292 }
...@@ -381,14 +380,14 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con...@@ -381,14 +380,14 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con
381 path_buf[search_path.len + exe_path.len + 1] = 0;380 path_buf[search_path.len + exe_path.len + 1] = 0;
382 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));381 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));
383 assert(err > 0);382 assert(err > 0);
384 if (err == errno.EACCES) {383 if (err == posix.EACCES) {
385 seen_eacces = true;384 seen_eacces = true;
386 } else if (err != errno.ENOENT) {385 } else if (err != posix.ENOENT) {
387 return posixExecveErrnoToErr(err);386 return posixExecveErrnoToErr(err);
388 }387 }
389 }388 }
390 if (seen_eacces) {389 if (seen_eacces) {
391 err = errno.EACCES;390 err = posix.EACCES;
392 }391 }
393 return posixExecveErrnoToErr(err);392 return posixExecveErrnoToErr(err);
394}393}
...@@ -396,15 +395,15 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con...@@ -396,15 +395,15 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con
396fn posixExecveErrnoToErr(err: usize) -> error {395fn posixExecveErrnoToErr(err: usize) -> error {
397 assert(err > 0);396 assert(err > 0);
398 return switch (err) {397 return switch (err) {
399 errno.EFAULT => unreachable,398 posix.EFAULT => unreachable,
400 errno.E2BIG, errno.EMFILE, errno.ENAMETOOLONG, errno.ENFILE, errno.ENOMEM => error.SystemResources,399 posix.E2BIG, posix.EMFILE, posix.ENAMETOOLONG, posix.ENFILE, posix.ENOMEM => error.SystemResources,
401 errno.EACCES, errno.EPERM => error.AccessDenied,400 posix.EACCES, posix.EPERM => error.AccessDenied,
402 errno.EINVAL, errno.ENOEXEC => error.InvalidExe,401 posix.EINVAL, posix.ENOEXEC => error.InvalidExe,
403 errno.EIO, errno.ELOOP => error.FileSystem,402 posix.EIO, posix.ELOOP => error.FileSystem,
404 errno.EISDIR => error.IsDir,403 posix.EISDIR => error.IsDir,
405 errno.ENOENT => error.FileNotFound,404 posix.ENOENT => error.FileNotFound,
406 errno.ENOTDIR => error.NotDir,405 posix.ENOTDIR => error.NotDir,
407 errno.ETXTBSY => error.FileBusy,406 posix.ETXTBSY => error.FileBusy,
408 else => error.Unexpected,407 else => error.Unexpected,
409 };408 };
410}409}
...@@ -464,7 +463,7 @@ pub fn getCwd(allocator: &Allocator) -> %[]u8 {...@@ -464,7 +463,7 @@ pub fn getCwd(allocator: &Allocator) -> %[]u8 {
464 %defer allocator.free(buf);463 %defer allocator.free(buf);
465 while (true) {464 while (true) {
466 const err = posix.getErrno(posix.getcwd(buf.ptr, buf.len));465 const err = posix.getErrno(posix.getcwd(buf.ptr, buf.len));
467 if (err == errno.ERANGE) {466 if (err == posix.ERANGE) {
468 buf = %return allocator.realloc(u8, buf, buf.len * 2);467 buf = %return allocator.realloc(u8, buf, buf.len * 2);
469 continue;468 continue;
470 } else if (err > 0) {469 } else if (err > 0) {
...@@ -490,18 +489,18 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con...@@ -490,18 +489,18 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con
490 const err = posix.getErrno(posix.symlink(existing_buf.ptr, new_buf.ptr));489 const err = posix.getErrno(posix.symlink(existing_buf.ptr, new_buf.ptr));
491 if (err > 0) {490 if (err > 0) {
492 return switch (err) {491 return switch (err) {
493 errno.EFAULT, errno.EINVAL => unreachable,492 posix.EFAULT, posix.EINVAL => unreachable,
494 errno.EACCES, errno.EPERM => error.AccessDenied,493 posix.EACCES, posix.EPERM => error.AccessDenied,
495 errno.EDQUOT => error.DiskQuota,494 posix.EDQUOT => error.DiskQuota,
496 errno.EEXIST => error.PathAlreadyExists,495 posix.EEXIST => error.PathAlreadyExists,
497 errno.EIO => error.FileSystem,496 posix.EIO => error.FileSystem,
498 errno.ELOOP => error.SymLinkLoop,497 posix.ELOOP => error.SymLinkLoop,
499 errno.ENAMETOOLONG => error.NameTooLong,498 posix.ENAMETOOLONG => error.NameTooLong,
500 errno.ENOENT => error.FileNotFound,499 posix.ENOENT => error.FileNotFound,
501 errno.ENOTDIR => error.NotDir,500 posix.ENOTDIR => error.NotDir,
502 errno.ENOMEM => error.SystemResources,501 posix.ENOMEM => error.SystemResources,
503 errno.ENOSPC => error.NoSpaceLeft,502 posix.ENOSPC => error.NoSpaceLeft,
504 errno.EROFS => error.ReadOnlyFileSystem,503 posix.EROFS => error.ReadOnlyFileSystem,
505 else => error.Unexpected,504 else => error.Unexpected,
506 };505 };
507 }506 }
...@@ -549,17 +548,17 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void {...@@ -549,17 +548,17 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void {
549 const err = posix.getErrno(posix.unlink(buf.ptr));548 const err = posix.getErrno(posix.unlink(buf.ptr));
550 if (err > 0) {549 if (err > 0) {
551 return switch (err) {550 return switch (err) {
552 errno.EACCES, errno.EPERM => error.AccessDenied,551 posix.EACCES, posix.EPERM => error.AccessDenied,
553 errno.EBUSY => error.FileBusy,552 posix.EBUSY => error.FileBusy,
554 errno.EFAULT, errno.EINVAL => unreachable,553 posix.EFAULT, posix.EINVAL => unreachable,
555 errno.EIO => error.FileSystem,554 posix.EIO => error.FileSystem,
556 errno.EISDIR => error.IsDir,555 posix.EISDIR => error.IsDir,
557 errno.ELOOP => error.SymLinkLoop,556 posix.ELOOP => error.SymLinkLoop,
558 errno.ENAMETOOLONG => error.NameTooLong,557 posix.ENAMETOOLONG => error.NameTooLong,
559 errno.ENOENT => error.FileNotFound,558 posix.ENOENT => error.FileNotFound,
560 errno.ENOTDIR => error.NotDir,559 posix.ENOTDIR => error.NotDir,
561 errno.ENOMEM => error.SystemResources,560 posix.ENOMEM => error.SystemResources,
562 errno.EROFS => error.ReadOnlyFileSystem,561 posix.EROFS => error.ReadOnlyFileSystem,
563 else => error.Unexpected,562 else => error.Unexpected,
564 };563 };
565 }564 }
...@@ -612,21 +611,21 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)...@@ -612,21 +611,21 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
612 const err = posix.getErrno(posix.rename(old_buf.ptr, new_buf.ptr));611 const err = posix.getErrno(posix.rename(old_buf.ptr, new_buf.ptr));
613 if (err > 0) {612 if (err > 0) {
614 return switch (err) {613 return switch (err) {
615 errno.EACCES, errno.EPERM => error.AccessDenied,614 posix.EACCES, posix.EPERM => error.AccessDenied,
616 errno.EBUSY => error.FileBusy,615 posix.EBUSY => error.FileBusy,
617 errno.EDQUOT => error.DiskQuota,616 posix.EDQUOT => error.DiskQuota,
618 errno.EFAULT, errno.EINVAL => unreachable,617 posix.EFAULT, posix.EINVAL => unreachable,
619 errno.EISDIR => error.IsDir,618 posix.EISDIR => error.IsDir,
620 errno.ELOOP => error.SymLinkLoop,619 posix.ELOOP => error.SymLinkLoop,
621 errno.EMLINK => error.LinkQuotaExceeded,620 posix.EMLINK => error.LinkQuotaExceeded,
622 errno.ENAMETOOLONG => error.NameTooLong,621 posix.ENAMETOOLONG => error.NameTooLong,
623 errno.ENOENT => error.FileNotFound,622 posix.ENOENT => error.FileNotFound,
624 errno.ENOTDIR => error.NotDir,623 posix.ENOTDIR => error.NotDir,
625 errno.ENOMEM => error.SystemResources,624 posix.ENOMEM => error.SystemResources,
626 errno.ENOSPC => error.NoSpaceLeft,625 posix.ENOSPC => error.NoSpaceLeft,
627 errno.EEXIST, errno.ENOTEMPTY => error.PathAlreadyExists,626 posix.EEXIST, posix.ENOTEMPTY => error.PathAlreadyExists,
628 errno.EROFS => error.ReadOnlyFileSystem,627 posix.EROFS => error.ReadOnlyFileSystem,
629 errno.EXDEV => error.RenameAcrossMountPoints,628 posix.EXDEV => error.RenameAcrossMountPoints,
630 else => error.Unexpected,629 else => error.Unexpected,
631 };630 };
632 }631 }
...@@ -642,18 +641,18 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void {...@@ -642,18 +641,18 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void {
642 const err = posix.getErrno(posix.mkdir(path_buf.ptr, 0o755));641 const err = posix.getErrno(posix.mkdir(path_buf.ptr, 0o755));
643 if (err > 0) {642 if (err > 0) {
644 return switch (err) {643 return switch (err) {
645 errno.EACCES, errno.EPERM => error.AccessDenied,644 posix.EACCES, posix.EPERM => error.AccessDenied,
646 errno.EDQUOT => error.DiskQuota,645 posix.EDQUOT => error.DiskQuota,
647 errno.EEXIST => error.PathAlreadyExists,646 posix.EEXIST => error.PathAlreadyExists,
648 errno.EFAULT => unreachable,647 posix.EFAULT => unreachable,
649 errno.ELOOP => error.SymLinkLoop,648 posix.ELOOP => error.SymLinkLoop,
650 errno.EMLINK => error.LinkQuotaExceeded,649 posix.EMLINK => error.LinkQuotaExceeded,
651 errno.ENAMETOOLONG => error.NameTooLong,650 posix.ENAMETOOLONG => error.NameTooLong,
652 errno.ENOENT => error.FileNotFound,651 posix.ENOENT => error.FileNotFound,
653 errno.ENOMEM => error.SystemResources,652 posix.ENOMEM => error.SystemResources,
654 errno.ENOSPC => error.NoSpaceLeft,653 posix.ENOSPC => error.NoSpaceLeft,
655 errno.ENOTDIR => error.NotDir,654 posix.ENOTDIR => error.NotDir,
656 errno.EROFS => error.ReadOnlyFileSystem,655 posix.EROFS => error.ReadOnlyFileSystem,
657 else => error.Unexpected,656 else => error.Unexpected,
658 };657 };
659 }658 }
...@@ -709,16 +708,16 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void {...@@ -709,16 +708,16 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void {
709 const err = posix.getErrno(posix.rmdir(path_buf.ptr));708 const err = posix.getErrno(posix.rmdir(path_buf.ptr));
710 if (err > 0) {709 if (err > 0) {
711 return switch (err) {710 return switch (err) {
712 errno.EACCES, errno.EPERM => error.AccessDenied,711 posix.EACCES, posix.EPERM => error.AccessDenied,
713 errno.EBUSY => error.FileBusy,712 posix.EBUSY => error.FileBusy,
714 errno.EFAULT, errno.EINVAL => unreachable,713 posix.EFAULT, posix.EINVAL => unreachable,
715 errno.ELOOP => error.SymLinkLoop,714 posix.ELOOP => error.SymLinkLoop,
716 errno.ENAMETOOLONG => error.NameTooLong,715 posix.ENAMETOOLONG => error.NameTooLong,
717 errno.ENOENT => error.FileNotFound,716 posix.ENOENT => error.FileNotFound,
718 errno.ENOMEM => error.SystemResources,717 posix.ENOMEM => error.SystemResources,
719 errno.ENOTDIR => error.NotDir,718 posix.ENOTDIR => error.NotDir,
720 errno.EEXIST, errno.ENOTEMPTY => error.DirNotEmpty,719 posix.EEXIST, posix.ENOTEMPTY => error.DirNotEmpty,
721 errno.EROFS => error.ReadOnlyFileSystem,720 posix.EROFS => error.ReadOnlyFileSystem,
722 else => error.Unexpected,721 else => error.Unexpected,
723 };722 };
724 }723 }
...@@ -825,8 +824,8 @@ pub const Dir = struct {...@@ -825,8 +824,8 @@ pub const Dir = struct {
825 const err = linux.getErrno(result);824 const err = linux.getErrno(result);
826 if (err > 0) {825 if (err > 0) {
827 switch (err) {826 switch (err) {
828 errno.EBADF, errno.EFAULT, errno.ENOTDIR => unreachable,827 posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable,
829 errno.EINVAL => {828 posix.EINVAL => {
830 self.buf = %return self.allocator.realloc(u8, self.buf, self.buf.len * 2);829 self.buf = %return self.allocator.realloc(u8, self.buf, self.buf.len * 2);
831 continue;830 continue;
832 },831 },
...@@ -879,14 +878,14 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void {...@@ -879,14 +878,14 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void {
879 const err = posix.getErrno(posix.chdir(path_buf.ptr));878 const err = posix.getErrno(posix.chdir(path_buf.ptr));
880 if (err > 0) {879 if (err > 0) {
881 return switch (err) {880 return switch (err) {
882 errno.EACCES => error.AccessDenied,881 posix.EACCES => error.AccessDenied,
883 errno.EFAULT => unreachable,882 posix.EFAULT => unreachable,
884 errno.EIO => error.FileSystem,883 posix.EIO => error.FileSystem,
885 errno.ELOOP => error.SymLinkLoop,884 posix.ELOOP => error.SymLinkLoop,
886 errno.ENAMETOOLONG => error.NameTooLong,885 posix.ENAMETOOLONG => error.NameTooLong,
887 errno.ENOENT => error.FileNotFound,886 posix.ENOENT => error.FileNotFound,
888 errno.ENOMEM => error.SystemResources,887 posix.ENOMEM => error.SystemResources,
889 errno.ENOTDIR => error.NotDir,888 posix.ENOTDIR => error.NotDir,
890 else => error.Unexpected,889 else => error.Unexpected,
891 };890 };
892 }891 }
...@@ -907,14 +906,14 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {...@@ -907,14 +906,14 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
907 const err = posix.getErrno(ret_val);906 const err = posix.getErrno(ret_val);
908 if (err > 0) {907 if (err > 0) {
909 return switch (err) {908 return switch (err) {
910 errno.EACCES => error.AccessDenied,909 posix.EACCES => error.AccessDenied,
911 errno.EFAULT, errno.EINVAL => unreachable,910 posix.EFAULT, posix.EINVAL => unreachable,
912 errno.EIO => error.FileSystem,911 posix.EIO => error.FileSystem,
913 errno.ELOOP => error.SymLinkLoop,912 posix.ELOOP => error.SymLinkLoop,
914 errno.ENAMETOOLONG => error.NameTooLong,913 posix.ENAMETOOLONG => error.NameTooLong,
915 errno.ENOENT => error.FileNotFound,914 posix.ENOENT => error.FileNotFound,
916 errno.ENOMEM => error.SystemResources,915 posix.ENOMEM => error.SystemResources,
917 errno.ENOTDIR => error.NotDir,916 posix.ENOTDIR => error.NotDir,
918 else => error.Unexpected,917 else => error.Unexpected,
919 };918 };
920 }919 }
std/os/linux.zig+1-1
...@@ -4,7 +4,7 @@ const arch = switch (builtin.arch) {...@@ -4,7 +4,7 @@ const arch = switch (builtin.arch) {
4 builtin.Arch.i386 => @import("linux_i386.zig"),4 builtin.Arch.i386 => @import("linux_i386.zig"),
5 else => @compileError("unsupported arch"),5 else => @compileError("unsupported arch"),
6};6};
7const errno = @import("errno.zig");7pub use @import("linux_errno.zig");
88
9pub const STDIN_FILENO = 0;9pub const STDIN_FILENO = 0;
10pub const STDOUT_FILENO = 1;10pub const STDOUT_FILENO = 1;
std/os/linux_errno.zig created+146
...@@ -0,0 +1,146 @@
1pub const EPERM = 1; /// Operation not permitted
2pub const ENOENT = 2; /// No such file or directory
3pub const ESRCH = 3; /// No such process
4pub const EINTR = 4; /// Interrupted system call
5pub const EIO = 5; /// I/O error
6pub const ENXIO = 6; /// No such device or address
7pub const E2BIG = 7; /// Arg list too long
8pub const ENOEXEC = 8; /// Exec format error
9pub const EBADF = 9; /// Bad file number
10pub const ECHILD = 10; /// No child processes
11pub const EAGAIN = 11; /// Try again
12pub const ENOMEM = 12; /// Out of memory
13pub const EACCES = 13; /// Permission denied
14pub const EFAULT = 14; /// Bad address
15pub const ENOTBLK = 15; /// Block device required
16pub const EBUSY = 16; /// Device or resource busy
17pub const EEXIST = 17; /// File exists
18pub const EXDEV = 18; /// Cross-device link
19pub const ENODEV = 19; /// No such device
20pub const ENOTDIR = 20; /// Not a directory
21pub const EISDIR = 21; /// Is a directory
22pub const EINVAL = 22; /// Invalid argument
23pub const ENFILE = 23; /// File table overflow
24pub const EMFILE = 24; /// Too many open files
25pub const ENOTTY = 25; /// Not a typewriter
26pub const ETXTBSY = 26; /// Text file busy
27pub const EFBIG = 27; /// File too large
28pub const ENOSPC = 28; /// No space left on device
29pub const ESPIPE = 29; /// Illegal seek
30pub const EROFS = 30; /// Read-only file system
31pub const EMLINK = 31; /// Too many links
32pub const EPIPE = 32; /// Broken pipe
33pub const EDOM = 33; /// Math argument out of domain of func
34pub const ERANGE = 34; /// Math result not representable
35pub const EDEADLK = 35; /// Resource deadlock would occur
36pub const ENAMETOOLONG = 36; /// File name too long
37pub const ENOLCK = 37; /// No record locks available
38pub const ENOSYS = 38; /// Function not implemented
39pub const ENOTEMPTY = 39; /// Directory not empty
40pub const ELOOP = 40; /// Too many symbolic links encountered
41pub const EWOULDBLOCK = EAGAIN; /// Operation would block
42pub const ENOMSG = 42; /// No message of desired type
43pub const EIDRM = 43; /// Identifier removed
44pub const ECHRNG = 44; /// Channel number out of range
45pub const EL2NSYNC = 45; /// Level 2 not synchronized
46pub const EL3HLT = 46; /// Level 3 halted
47pub const EL3RST = 47; /// Level 3 reset
48pub const ELNRNG = 48; /// Link number out of range
49pub const EUNATCH = 49; /// Protocol driver not attached
50pub const ENOCSI = 50; /// No CSI structure available
51pub const EL2HLT = 51; /// Level 2 halted
52pub const EBADE = 52; /// Invalid exchange
53pub const EBADR = 53; /// Invalid request descriptor
54pub const EXFULL = 54; /// Exchange full
55pub const ENOANO = 55; /// No anode
56pub const EBADRQC = 56; /// Invalid request code
57pub const EBADSLT = 57; /// Invalid slot
58
59pub const EBFONT = 59; /// Bad font file format
60pub const ENOSTR = 60; /// Device not a stream
61pub const ENODATA = 61; /// No data available
62pub const ETIME = 62; /// Timer expired
63pub const ENOSR = 63; /// Out of streams resources
64pub const ENONET = 64; /// Machine is not on the network
65pub const ENOPKG = 65; /// Package not installed
66pub const EREMOTE = 66; /// Object is remote
67pub const ENOLINK = 67; /// Link has been severed
68pub const EADV = 68; /// Advertise error
69pub const ESRMNT = 69; /// Srmount error
70pub const ECOMM = 70; /// Communication error on send
71pub const EPROTO = 71; /// Protocol error
72pub const EMULTIHOP = 72; /// Multihop attempted
73pub const EDOTDOT = 73; /// RFS specific error
74pub const EBADMSG = 74; /// Not a data message
75pub const EOVERFLOW = 75; /// Value too large for defined data type
76pub const ENOTUNIQ = 76; /// Name not unique on network
77pub const EBADFD = 77; /// File descriptor in bad state
78pub const EREMCHG = 78; /// Remote address changed
79pub const ELIBACC = 79; /// Can not access a needed shared library
80pub const ELIBBAD = 80; /// Accessing a corrupted shared library
81pub const ELIBSCN = 81; /// .lib section in a.out corrupted
82pub const ELIBMAX = 82; /// Attempting to link in too many shared libraries
83pub const ELIBEXEC = 83; /// Cannot exec a shared library directly
84pub const EILSEQ = 84; /// Illegal byte sequence
85pub const ERESTART = 85; /// Interrupted system call should be restarted
86pub const ESTRPIPE = 86; /// Streams pipe error
87pub const EUSERS = 87; /// Too many users
88pub const ENOTSOCK = 88; /// Socket operation on non-socket
89pub const EDESTADDRREQ = 89; /// Destination address required
90pub const EMSGSIZE = 90; /// Message too long
91pub const EPROTOTYPE = 91; /// Protocol wrong type for socket
92pub const ENOPROTOOPT = 92; /// Protocol not available
93pub const EPROTONOSUPPORT = 93; /// Protocol not supported
94pub const ESOCKTNOSUPPORT = 94; /// Socket type not supported
95pub const EOPNOTSUPP = 95; /// Operation not supported on transport endpoint
96pub const EPFNOSUPPORT = 96; /// Protocol family not supported
97pub const EAFNOSUPPORT = 97; /// Address family not supported by protocol
98pub const EADDRINUSE = 98; /// Address already in use
99pub const EADDRNOTAVAIL = 99; /// Cannot assign requested address
100pub const ENETDOWN = 100; /// Network is down
101pub const ENETUNREACH = 101; /// Network is unreachable
102pub const ENETRESET = 102; /// Network dropped connection because of reset
103pub const ECONNABORTED = 103; /// Software caused connection abort
104pub const ECONNRESET = 104; /// Connection reset by peer
105pub const ENOBUFS = 105; /// No buffer space available
106pub const EISCONN = 106; /// Transport endpoint is already connected
107pub const ENOTCONN = 107; /// Transport endpoint is not connected
108pub const ESHUTDOWN = 108; /// Cannot send after transport endpoint shutdown
109pub const ETOOMANYREFS = 109; /// Too many references: cannot splice
110pub const ETIMEDOUT = 110; /// Connection timed out
111pub const ECONNREFUSED = 111; /// Connection refused
112pub const EHOSTDOWN = 112; /// Host is down
113pub const EHOSTUNREACH = 113; /// No route to host
114pub const EALREADY = 114; /// Operation already in progress
115pub const EINPROGRESS = 115; /// Operation now in progress
116pub const ESTALE = 116; /// Stale NFS file handle
117pub const EUCLEAN = 117; /// Structure needs cleaning
118pub const ENOTNAM = 118; /// Not a XENIX named type file
119pub const ENAVAIL = 119; /// No XENIX semaphores available
120pub const EISNAM = 120; /// Is a named type file
121pub const EREMOTEIO = 121; /// Remote I/O error
122pub const EDQUOT = 122; /// Quota exceeded
123
124pub const ENOMEDIUM = 123; /// No medium found
125pub const EMEDIUMTYPE = 124; /// Wrong medium type
126
127// nameserver query return codes
128pub const ENSROK = 0; /// DNS server returned answer with no data
129pub const ENSRNODATA = 160; /// DNS server returned answer with no data
130pub const ENSRFORMERR = 161; /// DNS server claims query was misformatted
131pub const ENSRSERVFAIL = 162; /// DNS server returned general failure
132pub const ENSRNOTFOUND = 163; /// Domain name not found
133pub const ENSRNOTIMP = 164; /// DNS server does not implement requested operation
134pub const ENSRREFUSED = 165; /// DNS server refused query
135pub const ENSRBADQUERY = 166; /// Misformatted DNS query
136pub const ENSRBADNAME = 167; /// Misformatted domain name
137pub const ENSRBADFAMILY = 168; /// Unsupported address family
138pub const ENSRBADRESP = 169; /// Misformatted DNS reply
139pub const ENSRCONNREFUSED = 170; /// Could not contact DNS servers
140pub const ENSRTIMEOUT = 171; /// Timeout while contacting DNS servers
141pub const ENSROF = 172; /// End of file
142pub const ENSRFILE = 173; /// Error reading file
143pub const ENSRNOMEM = 174; /// Out of memory
144pub const ENSRDESTRUCTION = 175; /// Application terminated lookup
145pub const ENSRQUERYDOMAINTOOLONG = 176; /// Domain name is too long
146pub const ENSRCNAMELOOP = 177; /// Domain name is too long
std/special/builtin.zig+7-2
...@@ -30,16 +30,21 @@ export fn __stack_chk_fail() {...@@ -30,16 +30,21 @@ export fn __stack_chk_fail() {
30 @panic("stack smashing detected");30 @panic("stack smashing detected");
31}31}
3232
33const math = @import("../math/index.zig");
34
33export fn fmodf(x: f32, y: f32) -> f32 { generic_fmod(f32, x, y) }35export fn fmodf(x: f32, y: f32) -> f32 { generic_fmod(f32, x, y) }
34export fn fmod(x: f64, y: f64) -> f64 { generic_fmod(f64, x, y) }36export fn fmod(x: f64, y: f64) -> f64 { generic_fmod(f64, x, y) }
3537
36const Log2Int = @import("../math/index.zig").Log2Int;38// TODO add intrinsics for these (and probably the double version too)
39// and have the math stuff use the intrinsic. same as @mod and @rem
40export fn floorf(x: f32) -> f32 { math.floor(x) }
41export fn ceilf(x: f32) -> f32 { math.ceil(x) }
3742
38fn generic_fmod(comptime T: type, x: T, y: T) -> T {43fn generic_fmod(comptime T: type, x: T, y: T) -> T {
39 @setDebugSafety(this, false);44 @setDebugSafety(this, false);
4045
41 const uint = @IntType(false, T.bit_count);46 const uint = @IntType(false, T.bit_count);
42 const log2uint = Log2Int(uint);47 const log2uint = math.Log2Int(uint);
43 const digits = if (T == f32) 23 else 52;48 const digits = if (T == f32) 23 else 52;
44 const exp_bits = if (T == f32) 9 else 12;49 const exp_bits = if (T == f32) 9 else 12;
45 const bits_minus_1 = T.bit_count - 1;50 const bits_minus_1 = T.bit_count - 1;
test/cases/switch.zig+3-3
...@@ -72,7 +72,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {...@@ -72,7 +72,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {
72 SwitchStatmentFoo.C => 3,72 SwitchStatmentFoo.C => 3,
73 SwitchStatmentFoo.D => 4,73 SwitchStatmentFoo.D => 4,
74 };74 };
75 if (val != 3) unreachable;75 assert(val == 3);
76}76}
77const SwitchStatmentFoo = enum {77const SwitchStatmentFoo = enum {
78 A,78 A,
...@@ -95,10 +95,10 @@ const SwitchProngWithVarEnum = enum {...@@ -95,10 +95,10 @@ const SwitchProngWithVarEnum = enum {
95fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) {95fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) {
96 switch(*a) {96 switch(*a) {
97 SwitchProngWithVarEnum.One => |x| {97 SwitchProngWithVarEnum.One => |x| {
98 if (x != 13) unreachable;98 assert(x == 13);
99 },99 },
100 SwitchProngWithVarEnum.Two => |x| {100 SwitchProngWithVarEnum.Two => |x| {
101 if (x != 13.0) unreachable;101 assert(x == 13.0);
102 },102 },
103 SwitchProngWithVarEnum.Meh => |x| {103 SwitchProngWithVarEnum.Meh => |x| {
104 const v: void = x;104 const v: void = x;