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 {...@@ -2177,14 +2177,6 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File {
21772177
2178pub const SelfExePathError = os.ReadLinkError || os.SysCtlError || os.RealPathError;2178pub 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
2188/// `selfExePath` except allocates the result on the heap.2180/// `selfExePath` except allocates the result on the heap.
2189/// Caller owns returned memory.2181/// Caller owns returned memory.
2190pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 {2182pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 {
...@@ -2243,7 +2235,8 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -2243,7 +2235,8 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
2243 .openbsd => {2235 .openbsd => {
2244 // OpenBSD doesn't support getting the path of a running process, so try to guess it2236 // OpenBSD doesn't support getting the path of a running process, so try to guess it
2245 if (os.argv.len >= 1) {2237 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) {
2247 // argv[0] is a path (relative or absolute): use realpath(3) directly2240 // argv[0] is a path (relative or absolute): use realpath(3) directly
2248 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;2241 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
2249 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);2242 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);