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}")
297297install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}")
298298install(FILES "${CMAKE_SOURCE_DIR}/std/os/child_process.zig" DESTINATION "${ZIG_STD_DEST}/os")
299299install(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")
301301install(FILES "${CMAKE_SOURCE_DIR}/std/os/index.zig" DESTINATION "${ZIG_STD_DEST}/os")
302302install(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")
303304install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}/os")
304305install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os")
305306install(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
1212cmake .. -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))
1313make VERBOSE=1
1414make install
15# TODO get tests passing on macos
15# TODO get full test suite passing on macos
16./zig test ../test/behavior.zig
17./zig test ../test/behavior.zig --release-fast
1618# ./zig build --build-file ../build.zig test
src/link.cpp+4
......@@ -325,6 +325,10 @@ static void construct_linker_job_elf(LinkJob *lj) {
325325 lj->args.append(get_libc_static_file(g, "crtend.o"));
326326 lj->args.append(get_libc_file(g, "crtn.o"));
327327 }
328
329 if (!g->is_native_target) {
330 lj->args.append("--allow-shlib-undefined");
331 }
328332}
329333
330334static bool is_target_cyg_mingw(const ZigTarget *target) {
std/c/darwin.zig+2
......@@ -1,5 +1,7 @@
11extern "c" fn __error() -> &c_int;
22
3pub use @import("../os/darwin_errno.zig");
4
35pub const _errno = __error;
46
57/// Renamed to Stat to not conflict with the stat function.
std/c/index.zig-1
......@@ -1,4 +1,3 @@
1pub use @import("../os/errno.zig");
21const builtin = @import("builtin");
32const Os = builtin.Os;
43
std/c/linux.zig+2
......@@ -1,3 +1,5 @@
1pub use @import("../os/linux_errno.zig");
2
13pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) -> c_int;
24extern "c" fn __errno_location() -> &c_int;
35pub const _errno = __errno_location;
std/io.zig+22-23
......@@ -8,7 +8,6 @@ const system = switch(builtin.os) {
88};
99const c = @import("c/index.zig");
1010
11const errno = @import("os/errno.zig");
1211const math = @import("math/index.zig");
1312const debug = @import("debug.zig");
1413const assert = debug.assert;
......@@ -269,11 +268,11 @@ pub const InStream = struct {
269268 const read_err = system.getErrno(amt_read);
270269 if (read_err > 0) {
271270 switch (read_err) {
272 errno.EINTR => continue,
273 errno.EINVAL => unreachable,
274 errno.EFAULT => unreachable,
275 errno.EBADF => return error.BadFd,
276 errno.EIO => return error.Io,
271 system.EINTR => continue,
272 system.EINVAL => unreachable,
273 system.EFAULT => unreachable,
274 system.EBADF => return error.BadFd,
275 system.EIO => return error.Io,
277276 else => return error.Unexpected,
278277 }
279278 }
......@@ -335,11 +334,11 @@ pub const InStream = struct {
335334 const err = system.getErrno(result);
336335 if (err > 0) {
337336 return switch (err) {
338 errno.EBADF => error.BadFd,
339 errno.EINVAL => error.Unseekable,
340 errno.EOVERFLOW => error.Unseekable,
341 errno.ESPIPE => error.Unseekable,
342 errno.ENXIO => error.Unseekable,
337 system.EBADF => error.BadFd,
338 system.EINVAL => error.Unseekable,
339 system.EOVERFLOW => error.Unseekable,
340 system.ESPIPE => error.Unseekable,
341 system.ENXIO => error.Unseekable,
343342 else => error.Unexpected,
344343 };
345344 }
......@@ -355,11 +354,11 @@ pub const InStream = struct {
355354 const err = system.getErrno(result);
356355 if (err > 0) {
357356 return switch (err) {
358 errno.EBADF => error.BadFd,
359 errno.EINVAL => error.Unseekable,
360 errno.EOVERFLOW => error.Unseekable,
361 errno.ESPIPE => error.Unseekable,
362 errno.ENXIO => error.Unseekable,
357 system.EBADF => error.BadFd,
358 system.EINVAL => error.Unseekable,
359 system.EOVERFLOW => error.Unseekable,
360 system.ESPIPE => error.Unseekable,
361 system.ENXIO => error.Unseekable,
363362 else => error.Unexpected,
364363 };
365364 }
......@@ -375,11 +374,11 @@ pub const InStream = struct {
375374 const err = system.getErrno(result);
376375 if (err > 0) {
377376 return switch (err) {
378 errno.EBADF => error.BadFd,
379 errno.EINVAL => error.Unseekable,
380 errno.EOVERFLOW => error.Unseekable,
381 errno.ESPIPE => error.Unseekable,
382 errno.ENXIO => error.Unseekable,
377 system.EBADF => error.BadFd,
378 system.EINVAL => error.Unseekable,
379 system.EOVERFLOW => error.Unseekable,
380 system.ESPIPE => error.Unseekable,
381 system.ENXIO => error.Unseekable,
383382 else => error.Unexpected,
384383 };
385384 }
......@@ -394,8 +393,8 @@ pub const InStream = struct {
394393 const err = system.getErrno(system.fstat(is.fd, &stat));
395394 if (err > 0) {
396395 return switch (err) {
397 errno.EBADF => error.BadFd,
398 errno.ENOMEM => error.NoMem,
396 system.EBADF => error.BadFd,
397 system.ENOMEM => error.NoMem,
399398 else => error.Unexpected,
400399 }
401400 }
std/net.zig+15-16
......@@ -1,5 +1,4 @@
11const linux = @import("os/linux.zig");
2const errno = @import("os/errno.zig");
32const assert = @import("debug.zig").assert;
43const endian = @import("endian.zig");
54
......@@ -21,10 +20,10 @@ const Connection = struct {
2120 const send_err = linux.getErrno(send_ret);
2221 switch (send_err) {
2322 0 => return send_ret,
24 errno.EINVAL => unreachable,
25 errno.EFAULT => unreachable,
26 errno.ECONNRESET => return error.ConnectionReset,
27 errno.EINTR => return error.SigInterrupt,
23 linux.EINVAL => unreachable,
24 linux.EFAULT => unreachable,
25 linux.ECONNRESET => return error.ConnectionReset,
26 linux.EINTR => return error.SigInterrupt,
2827 // TODO there are more possible errors
2928 else => return error.Unexpected,
3029 }
......@@ -35,13 +34,13 @@ const Connection = struct {
3534 const recv_err = linux.getErrno(recv_ret);
3635 switch (recv_err) {
3736 0 => return buf[0..recv_ret],
38 errno.EINVAL => unreachable,
39 errno.EFAULT => unreachable,
40 errno.ENOTSOCK => return error.NotSocket,
41 errno.EINTR => return error.SigInterrupt,
42 errno.ENOMEM => return error.NoMem,
43 errno.ECONNREFUSED => return error.ConnectionRefused,
44 errno.EBADF => return error.BadFd,
37 linux.EINVAL => unreachable,
38 linux.EFAULT => unreachable,
39 linux.ENOTSOCK => return error.NotSocket,
40 linux.EINTR => return error.SigInterrupt,
41 linux.ENOMEM => return error.NoMem,
42 linux.ECONNREFUSED => return error.ConnectionRefused,
43 linux.EBADF => return error.BadFd,
4544 // TODO more error values
4645 else => return error.Unexpected,
4746 }
......@@ -50,9 +49,9 @@ const Connection = struct {
5049 pub fn close(c: Connection) -> %void {
5150 switch (linux.getErrno(linux.close(c.socket_fd))) {
5251 0 => return,
53 errno.EBADF => unreachable,
54 errno.EINTR => return error.SigInterrupt,
55 errno.EIO => return error.Io,
52 linux.EBADF => unreachable,
53 linux.EINTR => return error.SigInterrupt,
54 linux.EIO => return error.Io,
5655 else => return error.Unexpected,
5756 }
5857 }
......@@ -119,7 +118,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
119118 const connect_err = linux.getErrno(connect_ret);
120119 if (connect_err > 0) {
121120 switch (connect_err) {
122 errno.ETIMEDOUT => return error.TimedOut,
121 linux.ETIMEDOUT => return error.TimedOut,
123122 else => {
124123 // TODO figure out possible errors from connect()
125124 return error.Unexpected;
std/os/child_process.zig+4-5
......@@ -3,7 +3,6 @@ const os = @import("index.zig");
33const posix = os.posix;
44const mem = @import("../mem.zig");
55const Allocator = mem.Allocator;
6const errno = @import("errno.zig");
76const debug = @import("../debug.zig");
87const assert = debug.assert;
98const BufMap = @import("../buf_map.zig").BufMap;
......@@ -56,8 +55,8 @@ pub const ChildProcess = struct {
5655 const err = posix.getErrno(posix.waitpid(self.pid, &status, 0));
5756 if (err > 0) {
5857 switch (err) {
59 errno.EINVAL, errno.ECHILD => unreachable,
60 errno.EINTR => continue,
58 posix.EINVAL, posix.ECHILD => unreachable,
59 posix.EINTR => continue,
6160 else => {
6261 if (self.stdin) |*stdin| { stdin.close(); }
6362 if (self.stdout) |*stdout| { stdout.close(); }
......@@ -130,7 +129,7 @@ pub const ChildProcess = struct {
130129 const pid_err = posix.getErrno(pid);
131130 if (pid_err > 0) {
132131 return switch (pid_err) {
133 errno.EAGAIN, errno.ENOMEM, errno.ENOSYS => error.SystemResources,
132 posix.EAGAIN, posix.ENOMEM, posix.ENOSYS => error.SystemResources,
134133 else => error.Unexpected,
135134 };
136135 }
......@@ -209,7 +208,7 @@ fn makePipe() -> %[2]i32 {
209208 const err = posix.getErrno(posix.pipe(&fds));
210209 if (err > 0) {
211210 return switch (err) {
212 errno.EMFILE, errno.ENFILE => error.SystemResources,
211 posix.EMFILE, posix.ENFILE => error.SystemResources,
213212 else => error.Unexpected,
214213 }
215214 }
std/os/darwin.zig+2
......@@ -1,6 +1,8 @@
11const c = @import("../c/index.zig");
22const assert = @import("../debug.zig").assert;
33
4pub use @import("darwin_errno.zig");
5
46pub const STDIN_FILENO = 0;
57pub const STDOUT_FILENO = 1;
68pub 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;
2323const debug = @import("../debug.zig");
2424const assert = debug.assert;
2525
26const errno = @import("errno.zig");
2726const c = @import("../c/index.zig");
2827
2928const mem = @import("../mem.zig");
......@@ -63,9 +62,9 @@ pub fn getRandomBytes(buf: []u8) -> %void {
6362 const err = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));
6463 if (err > 0) {
6564 return switch (err) {
66 errno.EINVAL => unreachable,
67 errno.EFAULT => unreachable,
68 errno.EINTR => continue,
65 posix.EINVAL => unreachable,
66 posix.EFAULT => unreachable,
67 posix.EINTR => continue,
6968 else => error.Unexpected,
7069 }
7170 }
......@@ -117,7 +116,7 @@ pub coldcc fn abort() -> noreturn {
117116pub fn posixClose(fd: i32) {
118117 while (true) {
119118 const err = posix.getErrno(posix.close(fd));
120 if (err == errno.EINTR) {
119 if (err == posix.EINTR) {
121120 continue;
122121 } else {
123122 return;
......@@ -133,13 +132,13 @@ pub fn posixRead(fd: i32, buf: []u8) -> %void {
133132 const err = posix.getErrno(amt_written);
134133 if (err > 0) {
135134 return switch (err) {
136 errno.EINTR => continue,
137 errno.EINVAL, errno.EFAULT => unreachable,
138 errno.EAGAIN => error.WouldBlock,
139 errno.EBADF => error.FileClosed,
140 errno.EIO => error.InputOutput,
141 errno.EISDIR => error.IsDir,
142 errno.ENOBUFS, errno.ENOMEM => error.SystemResources,
135 posix.EINTR => continue,
136 posix.EINVAL, posix.EFAULT => unreachable,
137 posix.EAGAIN => error.WouldBlock,
138 posix.EBADF => error.FileClosed,
139 posix.EIO => error.InputOutput,
140 posix.EISDIR => error.IsDir,
141 posix.ENOBUFS, posix.ENOMEM => error.SystemResources,
143142 else => return error.Unexpected,
144143 }
145144 }
......@@ -164,17 +163,17 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
164163 const write_err = posix.getErrno(write_ret);
165164 if (write_err > 0) {
166165 return switch (write_err) {
167 errno.EINTR => continue,
168 errno.EINVAL, errno.EFAULT => unreachable,
169 errno.EAGAIN => error.WouldBlock,
170 errno.EBADF => error.FileClosed,
171 errno.EDESTADDRREQ => error.DestinationAddressRequired,
172 errno.EDQUOT => error.DiskQuota,
173 errno.EFBIG => error.FileTooBig,
174 errno.EIO => error.InputOutput,
175 errno.ENOSPC => error.NoSpaceLeft,
176 errno.EPERM => error.AccessDenied,
177 errno.EPIPE => error.BrokenPipe,
166 posix.EINTR => continue,
167 posix.EINVAL, posix.EFAULT => unreachable,
168 posix.EAGAIN => error.WouldBlock,
169 posix.EBADF => error.FileClosed,
170 posix.EDESTADDRREQ => error.DestinationAddressRequired,
171 posix.EDQUOT => error.DiskQuota,
172 posix.EFBIG => error.FileTooBig,
173 posix.EIO => error.InputOutput,
174 posix.ENOSPC => error.NoSpaceLeft,
175 posix.EPERM => error.AccessDenied,
176 posix.EPIPE => error.BrokenPipe,
178177 else => error.Unexpected,
179178 }
180179 }
......@@ -256,23 +255,23 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al
256255 const err = posix.getErrno(result);
257256 if (err > 0) {
258257 return switch (err) {
259 errno.EINTR => continue,
260
261 errno.EFAULT => unreachable,
262 errno.EINVAL => unreachable,
263 errno.EACCES => error.AccessDenied,
264 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,
265 errno.EISDIR => error.IsDir,
266 errno.ELOOP => error.SymLinkLoop,
267 errno.EMFILE => error.ProcessFdQuotaExceeded,
268 errno.ENAMETOOLONG => error.NameTooLong,
269 errno.ENFILE => error.SystemFdQuotaExceeded,
270 errno.ENODEV => error.NoDevice,
271 errno.ENOENT => error.PathNotFound,
272 errno.ENOMEM => error.SystemResources,
273 errno.ENOSPC => error.NoSpaceLeft,
274 errno.ENOTDIR => error.NotDir,
275 errno.EPERM => error.AccessDenied,
258 posix.EINTR => continue,
259
260 posix.EFAULT => unreachable,
261 posix.EINVAL => unreachable,
262 posix.EACCES => error.AccessDenied,
263 posix.EFBIG, posix.EOVERFLOW => error.FileTooBig,
264 posix.EISDIR => error.IsDir,
265 posix.ELOOP => error.SymLinkLoop,
266 posix.EMFILE => error.ProcessFdQuotaExceeded,
267 posix.ENAMETOOLONG => error.NameTooLong,
268 posix.ENFILE => error.SystemFdQuotaExceeded,
269 posix.ENODEV => error.NoDevice,
270 posix.ENOENT => error.PathNotFound,
271 posix.ENOMEM => error.SystemResources,
272 posix.ENOSPC => error.NoSpaceLeft,
273 posix.ENOTDIR => error.NotDir,
274 posix.EPERM => error.AccessDenied,
276275 else => error.Unexpected,
277276 }
278277 }
......@@ -285,9 +284,9 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void {
285284 const err = posix.getErrno(posix.dup2(old_fd, new_fd));
286285 if (err > 0) {
287286 return switch (err) {
288 errno.EBUSY, errno.EINTR => continue,
289 errno.EMFILE => error.ProcessFdQuotaExceeded,
290 errno.EINVAL => unreachable,
287 posix.EBUSY, posix.EINTR => continue,
288 posix.EMFILE => error.ProcessFdQuotaExceeded,
289 posix.EINVAL => unreachable,
291290 else => error.Unexpected,
292291 };
293292 }
......@@ -381,14 +380,14 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con
381380 path_buf[search_path.len + exe_path.len + 1] = 0;
382381 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));
383382 assert(err > 0);
384 if (err == errno.EACCES) {
383 if (err == posix.EACCES) {
385384 seen_eacces = true;
386 } else if (err != errno.ENOENT) {
385 } else if (err != posix.ENOENT) {
387386 return posixExecveErrnoToErr(err);
388387 }
389388 }
390389 if (seen_eacces) {
391 err = errno.EACCES;
390 err = posix.EACCES;
392391 }
393392 return posixExecveErrnoToErr(err);
394393}
......@@ -396,15 +395,15 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con
396395fn posixExecveErrnoToErr(err: usize) -> error {
397396 assert(err > 0);
398397 return switch (err) {
399 errno.EFAULT => unreachable,
400 errno.E2BIG, errno.EMFILE, errno.ENAMETOOLONG, errno.ENFILE, errno.ENOMEM => error.SystemResources,
401 errno.EACCES, errno.EPERM => error.AccessDenied,
402 errno.EINVAL, errno.ENOEXEC => error.InvalidExe,
403 errno.EIO, errno.ELOOP => error.FileSystem,
404 errno.EISDIR => error.IsDir,
405 errno.ENOENT => error.FileNotFound,
406 errno.ENOTDIR => error.NotDir,
407 errno.ETXTBSY => error.FileBusy,
398 posix.EFAULT => unreachable,
399 posix.E2BIG, posix.EMFILE, posix.ENAMETOOLONG, posix.ENFILE, posix.ENOMEM => error.SystemResources,
400 posix.EACCES, posix.EPERM => error.AccessDenied,
401 posix.EINVAL, posix.ENOEXEC => error.InvalidExe,
402 posix.EIO, posix.ELOOP => error.FileSystem,
403 posix.EISDIR => error.IsDir,
404 posix.ENOENT => error.FileNotFound,
405 posix.ENOTDIR => error.NotDir,
406 posix.ETXTBSY => error.FileBusy,
408407 else => error.Unexpected,
409408 };
410409}
......@@ -464,7 +463,7 @@ pub fn getCwd(allocator: &Allocator) -> %[]u8 {
464463 %defer allocator.free(buf);
465464 while (true) {
466465 const err = posix.getErrno(posix.getcwd(buf.ptr, buf.len));
467 if (err == errno.ERANGE) {
466 if (err == posix.ERANGE) {
468467 buf = %return allocator.realloc(u8, buf, buf.len * 2);
469468 continue;
470469 } else if (err > 0) {
......@@ -490,18 +489,18 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con
490489 const err = posix.getErrno(posix.symlink(existing_buf.ptr, new_buf.ptr));
491490 if (err > 0) {
492491 return switch (err) {
493 errno.EFAULT, errno.EINVAL => unreachable,
494 errno.EACCES, errno.EPERM => error.AccessDenied,
495 errno.EDQUOT => error.DiskQuota,
496 errno.EEXIST => error.PathAlreadyExists,
497 errno.EIO => error.FileSystem,
498 errno.ELOOP => error.SymLinkLoop,
499 errno.ENAMETOOLONG => error.NameTooLong,
500 errno.ENOENT => error.FileNotFound,
501 errno.ENOTDIR => error.NotDir,
502 errno.ENOMEM => error.SystemResources,
503 errno.ENOSPC => error.NoSpaceLeft,
504 errno.EROFS => error.ReadOnlyFileSystem,
492 posix.EFAULT, posix.EINVAL => unreachable,
493 posix.EACCES, posix.EPERM => error.AccessDenied,
494 posix.EDQUOT => error.DiskQuota,
495 posix.EEXIST => error.PathAlreadyExists,
496 posix.EIO => error.FileSystem,
497 posix.ELOOP => error.SymLinkLoop,
498 posix.ENAMETOOLONG => error.NameTooLong,
499 posix.ENOENT => error.FileNotFound,
500 posix.ENOTDIR => error.NotDir,
501 posix.ENOMEM => error.SystemResources,
502 posix.ENOSPC => error.NoSpaceLeft,
503 posix.EROFS => error.ReadOnlyFileSystem,
505504 else => error.Unexpected,
506505 };
507506 }
......@@ -549,17 +548,17 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void {
549548 const err = posix.getErrno(posix.unlink(buf.ptr));
550549 if (err > 0) {
551550 return switch (err) {
552 errno.EACCES, errno.EPERM => error.AccessDenied,
553 errno.EBUSY => error.FileBusy,
554 errno.EFAULT, errno.EINVAL => unreachable,
555 errno.EIO => error.FileSystem,
556 errno.EISDIR => error.IsDir,
557 errno.ELOOP => error.SymLinkLoop,
558 errno.ENAMETOOLONG => error.NameTooLong,
559 errno.ENOENT => error.FileNotFound,
560 errno.ENOTDIR => error.NotDir,
561 errno.ENOMEM => error.SystemResources,
562 errno.EROFS => error.ReadOnlyFileSystem,
551 posix.EACCES, posix.EPERM => error.AccessDenied,
552 posix.EBUSY => error.FileBusy,
553 posix.EFAULT, posix.EINVAL => unreachable,
554 posix.EIO => error.FileSystem,
555 posix.EISDIR => error.IsDir,
556 posix.ELOOP => error.SymLinkLoop,
557 posix.ENAMETOOLONG => error.NameTooLong,
558 posix.ENOENT => error.FileNotFound,
559 posix.ENOTDIR => error.NotDir,
560 posix.ENOMEM => error.SystemResources,
561 posix.EROFS => error.ReadOnlyFileSystem,
563562 else => error.Unexpected,
564563 };
565564 }
......@@ -612,21 +611,21 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
612611 const err = posix.getErrno(posix.rename(old_buf.ptr, new_buf.ptr));
613612 if (err > 0) {
614613 return switch (err) {
615 errno.EACCES, errno.EPERM => error.AccessDenied,
616 errno.EBUSY => error.FileBusy,
617 errno.EDQUOT => error.DiskQuota,
618 errno.EFAULT, errno.EINVAL => unreachable,
619 errno.EISDIR => error.IsDir,
620 errno.ELOOP => error.SymLinkLoop,
621 errno.EMLINK => error.LinkQuotaExceeded,
622 errno.ENAMETOOLONG => error.NameTooLong,
623 errno.ENOENT => error.FileNotFound,
624 errno.ENOTDIR => error.NotDir,
625 errno.ENOMEM => error.SystemResources,
626 errno.ENOSPC => error.NoSpaceLeft,
627 errno.EEXIST, errno.ENOTEMPTY => error.PathAlreadyExists,
628 errno.EROFS => error.ReadOnlyFileSystem,
629 errno.EXDEV => error.RenameAcrossMountPoints,
614 posix.EACCES, posix.EPERM => error.AccessDenied,
615 posix.EBUSY => error.FileBusy,
616 posix.EDQUOT => error.DiskQuota,
617 posix.EFAULT, posix.EINVAL => unreachable,
618 posix.EISDIR => error.IsDir,
619 posix.ELOOP => error.SymLinkLoop,
620 posix.EMLINK => error.LinkQuotaExceeded,
621 posix.ENAMETOOLONG => error.NameTooLong,
622 posix.ENOENT => error.FileNotFound,
623 posix.ENOTDIR => error.NotDir,
624 posix.ENOMEM => error.SystemResources,
625 posix.ENOSPC => error.NoSpaceLeft,
626 posix.EEXIST, posix.ENOTEMPTY => error.PathAlreadyExists,
627 posix.EROFS => error.ReadOnlyFileSystem,
628 posix.EXDEV => error.RenameAcrossMountPoints,
630629 else => error.Unexpected,
631630 };
632631 }
......@@ -642,18 +641,18 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void {
642641 const err = posix.getErrno(posix.mkdir(path_buf.ptr, 0o755));
643642 if (err > 0) {
644643 return switch (err) {
645 errno.EACCES, errno.EPERM => error.AccessDenied,
646 errno.EDQUOT => error.DiskQuota,
647 errno.EEXIST => error.PathAlreadyExists,
648 errno.EFAULT => unreachable,
649 errno.ELOOP => error.SymLinkLoop,
650 errno.EMLINK => error.LinkQuotaExceeded,
651 errno.ENAMETOOLONG => error.NameTooLong,
652 errno.ENOENT => error.FileNotFound,
653 errno.ENOMEM => error.SystemResources,
654 errno.ENOSPC => error.NoSpaceLeft,
655 errno.ENOTDIR => error.NotDir,
656 errno.EROFS => error.ReadOnlyFileSystem,
644 posix.EACCES, posix.EPERM => error.AccessDenied,
645 posix.EDQUOT => error.DiskQuota,
646 posix.EEXIST => error.PathAlreadyExists,
647 posix.EFAULT => unreachable,
648 posix.ELOOP => error.SymLinkLoop,
649 posix.EMLINK => error.LinkQuotaExceeded,
650 posix.ENAMETOOLONG => error.NameTooLong,
651 posix.ENOENT => error.FileNotFound,
652 posix.ENOMEM => error.SystemResources,
653 posix.ENOSPC => error.NoSpaceLeft,
654 posix.ENOTDIR => error.NotDir,
655 posix.EROFS => error.ReadOnlyFileSystem,
657656 else => error.Unexpected,
658657 };
659658 }
......@@ -709,16 +708,16 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void {
709708 const err = posix.getErrno(posix.rmdir(path_buf.ptr));
710709 if (err > 0) {
711710 return switch (err) {
712 errno.EACCES, errno.EPERM => error.AccessDenied,
713 errno.EBUSY => error.FileBusy,
714 errno.EFAULT, errno.EINVAL => unreachable,
715 errno.ELOOP => error.SymLinkLoop,
716 errno.ENAMETOOLONG => error.NameTooLong,
717 errno.ENOENT => error.FileNotFound,
718 errno.ENOMEM => error.SystemResources,
719 errno.ENOTDIR => error.NotDir,
720 errno.EEXIST, errno.ENOTEMPTY => error.DirNotEmpty,
721 errno.EROFS => error.ReadOnlyFileSystem,
711 posix.EACCES, posix.EPERM => error.AccessDenied,
712 posix.EBUSY => error.FileBusy,
713 posix.EFAULT, posix.EINVAL => unreachable,
714 posix.ELOOP => error.SymLinkLoop,
715 posix.ENAMETOOLONG => error.NameTooLong,
716 posix.ENOENT => error.FileNotFound,
717 posix.ENOMEM => error.SystemResources,
718 posix.ENOTDIR => error.NotDir,
719 posix.EEXIST, posix.ENOTEMPTY => error.DirNotEmpty,
720 posix.EROFS => error.ReadOnlyFileSystem,
722721 else => error.Unexpected,
723722 };
724723 }
......@@ -825,8 +824,8 @@ pub const Dir = struct {
825824 const err = linux.getErrno(result);
826825 if (err > 0) {
827826 switch (err) {
828 errno.EBADF, errno.EFAULT, errno.ENOTDIR => unreachable,
829 errno.EINVAL => {
827 posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable,
828 posix.EINVAL => {
830829 self.buf = %return self.allocator.realloc(u8, self.buf, self.buf.len * 2);
831830 continue;
832831 },
......@@ -879,14 +878,14 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void {
879878 const err = posix.getErrno(posix.chdir(path_buf.ptr));
880879 if (err > 0) {
881880 return switch (err) {
882 errno.EACCES => error.AccessDenied,
883 errno.EFAULT => unreachable,
884 errno.EIO => error.FileSystem,
885 errno.ELOOP => error.SymLinkLoop,
886 errno.ENAMETOOLONG => error.NameTooLong,
887 errno.ENOENT => error.FileNotFound,
888 errno.ENOMEM => error.SystemResources,
889 errno.ENOTDIR => error.NotDir,
881 posix.EACCES => error.AccessDenied,
882 posix.EFAULT => unreachable,
883 posix.EIO => error.FileSystem,
884 posix.ELOOP => error.SymLinkLoop,
885 posix.ENAMETOOLONG => error.NameTooLong,
886 posix.ENOENT => error.FileNotFound,
887 posix.ENOMEM => error.SystemResources,
888 posix.ENOTDIR => error.NotDir,
890889 else => error.Unexpected,
891890 };
892891 }
......@@ -907,14 +906,14 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
907906 const err = posix.getErrno(ret_val);
908907 if (err > 0) {
909908 return switch (err) {
910 errno.EACCES => error.AccessDenied,
911 errno.EFAULT, errno.EINVAL => unreachable,
912 errno.EIO => error.FileSystem,
913 errno.ELOOP => error.SymLinkLoop,
914 errno.ENAMETOOLONG => error.NameTooLong,
915 errno.ENOENT => error.FileNotFound,
916 errno.ENOMEM => error.SystemResources,
917 errno.ENOTDIR => error.NotDir,
909 posix.EACCES => error.AccessDenied,
910 posix.EFAULT, posix.EINVAL => unreachable,
911 posix.EIO => error.FileSystem,
912 posix.ELOOP => error.SymLinkLoop,
913 posix.ENAMETOOLONG => error.NameTooLong,
914 posix.ENOENT => error.FileNotFound,
915 posix.ENOMEM => error.SystemResources,
916 posix.ENOTDIR => error.NotDir,
918917 else => error.Unexpected,
919918 };
920919 }
std/os/linux.zig+1-1
......@@ -4,7 +4,7 @@ const arch = switch (builtin.arch) {
44 builtin.Arch.i386 => @import("linux_i386.zig"),
55 else => @compileError("unsupported arch"),
66};
7const errno = @import("errno.zig");
7pub use @import("linux_errno.zig");
88
99pub const STDIN_FILENO = 0;
1010pub 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() {
3030 @panic("stack smashing detected");
3131}
3232
33const math = @import("../math/index.zig");
34
3335export fn fmodf(x: f32, y: f32) -> f32 { generic_fmod(f32, x, y) }
3436export 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
3843fn generic_fmod(comptime T: type, x: T, y: T) -> T {
3944 @setDebugSafety(this, false);
4045
4146 const uint = @IntType(false, T.bit_count);
42 const log2uint = Log2Int(uint);
47 const log2uint = math.Log2Int(uint);
4348 const digits = if (T == f32) 23 else 52;
4449 const exp_bits = if (T == f32) 9 else 12;
4550 const bits_minus_1 = T.bit_count - 1;
test/cases/switch.zig+3-3
......@@ -72,7 +72,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {
7272 SwitchStatmentFoo.C => 3,
7373 SwitchStatmentFoo.D => 4,
7474 };
75 if (val != 3) unreachable;
75 assert(val == 3);
7676}
7777const SwitchStatmentFoo = enum {
7878 A,
......@@ -95,10 +95,10 @@ const SwitchProngWithVarEnum = enum {
9595fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) {
9696 switch(*a) {
9797 SwitchProngWithVarEnum.One => |x| {
98 if (x != 13) unreachable;
98 assert(x == 13);
9999 },
100100 SwitchProngWithVarEnum.Two => |x| {
101 if (x != 13.0) unreachable;
101 assert(x == 13.0);
102102 },
103103 SwitchProngWithVarEnum.Meh => |x| {
104104 const v: void = x;