@@ -100,41 +100,36 @@ jeload(void* callbacks) -> J {
100
100
auto
101
101
jepath (char * arg, char * lib) -> void {
102
102
uint32_t const sz = 4000 ;
103
- uint32_t len = sz; // Cant be const for function call _NSGetExecutablePath
104
103
105
104
// C strings need to be used for POSIX APIs and macOS APIs
106
- auto arg2 = new char [sz];
107
- auto arg3 = new char [sz];
108
- // Return for readlinks
109
- int n;
105
+ auto const arg2 = std::unique_ptr<char []>(new char [sz]);
106
+ auto const arg3 = std::unique_ptr<char []>(new char [sz]);
110
107
111
108
// try host dependent way to get path to executable
112
109
// use arg if they fail (arg command in PATH won't work)
113
110
#ifdef __MACH__
114
111
// Returns 0 if path was copied, otherwise -1 if failed.
115
- if (_NSGetExecutablePath (arg2, &len) != 0 ) strcat (arg2, arg);
112
+ if (uint32_t len = sz; _NSGetExecutablePath (arg2. get () , &len) != 0 ) strcat (arg2. get () , arg);
116
113
#else
117
- n = readlink (" /proc/self/exe" , arg2, sz);
118
- if (n == -1 )
119
- strcpy (arg2, arg);
120
- else
121
- arg2[n] = 0 ;
114
+ {
115
+ auto const n = readlink (" /proc/self/exe" , arg2, sz);
116
+ if (n == -1 )
117
+ strcpy (arg2, arg);
118
+ else
119
+ arg2[n] = 0 ;
120
+ }
122
121
#endif
123
122
// arg2 is path (abs or relative) to executable or soft link
124
- n = readlink (arg2, arg3, sz);
125
-
123
+ auto const n = readlink (arg2.get (), arg3.get (), sz);
126
124
if (n == -1 )
127
- strcpy (arg3, arg2);
125
+ strcpy (arg3. get () , arg2. get () );
128
126
else
129
127
arg3[n] = 0 ;
130
128
131
- if (' /' == * arg3)
132
- path = arg3;
129
+ if (' /' == arg3[ 0 ] )
130
+ path = arg3. get () ;
133
131
else
134
- path = std::filesystem::current_path () / arg3;
135
- // Now append path_temp to path, as all POSIX and macOS API calls are done, and free up arg2, arg3, path_temp.
136
- delete[] arg2;
137
- delete[] arg3;
132
+ path = std::filesystem::current_path () / arg3.get ();
138
133
139
134
path.remove_filename ();
140
135
0 commit comments