| ... | ... | @@ -112,6 +112,30 @@ pub coldcc fn abort() -> noreturn { |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | /// Exits the program cleanly with the specified status code. |
| 116 | pub coldcc fn exit(status: i32) -> noreturn { |
| 117 | if (builtin.link_libc) { |
| 118 | c.exit(status); |
| 119 | } |
| 120 | switch (builtin.os) { |
| 121 | Os.linux, Os.darwin, Os.macosx, Os.ios => { |
| 122 | posix.exit(status) |
| 123 | }, |
| 124 | Os.windows => { |
| 125 | // Map a possibly negative status code to a non-negative status for the systems default |
| 126 | // integer width. |
| 127 | const p_status = if (@sizeOf(c_uint) < @sizeOf(u32)) { |
| 128 | @truncate(c_uint, @bitCast(u32, status)) |
| 129 | } else { |
| 130 | c_uint(@bitCast(u32, status)) |
| 131 | }; |
| 132 | |
| 133 | windows.ExitProcess(p_status) |
| 134 | }, |
| 135 | else => @compileError("Unsupported OS"), |
| 136 | } |
| 137 | } |
| 138 | |
| 115 | 139 | /// Calls POSIX close, and keeps trying if it gets interrupted. |
| 116 | 140 | pub fn posixClose(fd: i32) { |
| 117 | 141 | while (true) { |