authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2017-09-10 05:48:44+12:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-09 13:48:44-04:00
log67a31befa672890e23ef530fa4376a787edff892
treef05e45ad3628acfb469fa9f2c4d43a64c894088f
parent850a1d205484055cc2dd194370fb54631b915528

Add exit function (#450)


1 files changed, 24 insertions(+), 0 deletions(-)

std/os/index.zig+24
......@@ -112,6 +112,30 @@ pub coldcc fn abort() -> noreturn {
112112 }
113113}
114114
115/// Exits the program cleanly with the specified status code.
116pub 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
115139/// Calls POSIX close, and keeps trying if it gets interrupted.
116140pub fn posixClose(fd: i32) {
117141 while (true) {