authorgravatar for semarie@online.frSébastien Marie <semarie@online.fr> 2020-10-11 08:23:37+00:00
committergravatar for semarie@online.frSébastien Marie <semarie@online.fr> 2020-10-11 08:23:37+00:00
log78a7543056112a1df8951712a746b9adb59787af
tree03e8fd6f18e858a53834cbe6f8102bda1a64f0ca
parentf33a610c84313255477cc04d930b02ad984118ae

openbsd: use mem.span() + mem.indexOf() instead of defining custom function


1 files changed, 2 insertions(+), 9 deletions(-)

lib/std/fs.zig+2-9
......@@ -2177,14 +2177,6 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File {
21772177
21782178pub const SelfExePathError = os.ReadLinkError || os.SysCtlError || os.RealPathError;
21792179
2180fn str_containsZ(s: [*:0]const u8, c: u8) bool {
2181 var i: usize = 0;
2182 while (s[i] != '\x00' and s[i] != c) {
2183 i += 1;
2184 }
2185 return (s[i] == '/');
2186}
2187
21882180/// `selfExePath` except allocates the result on the heap.
21892181/// Caller owns returned memory.
21902182pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 {
......@@ -2243,7 +2235,8 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
22432235 .openbsd => {
22442236 // OpenBSD doesn't support getting the path of a running process, so try to guess it
22452237 if (os.argv.len >= 1) {
2246 if (str_containsZ(os.argv[0], '/')) {
2238 const argv0 = mem.span(os.argv[0]);
2239 if (mem.indexOf(u8, argv0, "/") != null) {
22472240 // argv[0] is a path (relative or absolute): use realpath(3) directly
22482241 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
22492242 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);