From 98299e7787146e1572cd2038654dbbcf84fa32d1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 12 Mar 2023 00:34:11 -0700 Subject: [PATCH] add std.process.cleanExit --- lib/std/process.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/std/process.zig b/lib/std/process.zig index 8652dd1bbc..d9bf09ee2a 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1204,3 +1204,16 @@ fn totalSystemMemoryLinux() !usize { const kilobytes = try std.fmt.parseInt(usize, int_text, 10); return kilobytes * 1024; } + +/// Indicate that we are now terminating with a successful exit code. +/// In debug builds, this is a no-op, so that the calling code's +/// cleanup mechanisms are tested and so that external tools that +/// check for resource leaks can be accurate. In release builds, this +/// calls exit(0), and does not return. +pub fn cleanExit() void { + if (builtin.mode == .Debug) { + return; + } else { + exit(0); + } +}