zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7439eb5e99ba98bbdb2a0d0d71535e57d13f3c6e (tree)
parent dc9472964325743e3f9e7f3cedfb942b5f44ad14
Author: David CARLIER <devnexen@gmail.com>
Date:   Mon, 24 Apr 2023 20:35:51 +0100

std.os: selfExePath implementation for haiku

Diffstat:
Mlib/std/fs.zig | 11++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/std/fs.zig b/lib/std/fs.zig @@ -2913,6 +2913,7 @@ pub const OpenSelfExeError = error{ /// On Windows, file paths cannot contain these characters: /// '/', '*', '?', '"', '<', '>', '|' BadPathName, + Overflow, Unexpected, } || os.OpenError || SelfExePathError || os.FlockError; @@ -2991,7 +2992,15 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { // TODO could this slice from 0 to out_len instead? return mem.sliceTo(out_buffer, 0); }, - .openbsd, .haiku => { + .haiku => { + // The only possible issue when looking for the self image path is + // when the buffer is too short. + // TODO replace with proper constants + if (os.find_path(null, 1000, null, out_buffer.ptr, out_buffer.len) != 0) + return error.Overflow; + return mem.sliceTo(out_buffer, 0); + }, + .openbsd => { // OpenBSD doesn't support getting the path of a running process, so try to guess it if (os.argv.len == 0) return error.FileNotFound;