@@ -100,39 +100,34 @@ jepath(char* arg, char* lib) -> void {
100100 uint32_t const sz = 4000 ;
101101
102102 // C strings need to be used for POSIX APIs and macOS APIs
103- auto arg2 = new char [sz];
104- auto arg3 = new char [sz];
105- // Return for readlinks
106- int n;
103+ auto const arg2 = std::unique_ptr<char []>(new char [sz]);
104+ auto const arg3 = std::unique_ptr<char []>(new char [sz]);
107105
108106// try host dependent way to get path to executable
109107// use arg if they fail (arg command in PATH won't work)
110108#ifdef __MACH__
111- uint32_t len = sz; // Cant be const for function call _NSGetExecutablePath
112109 // Returns 0 if path was copied, otherwise -1 if failed.
113- if (_NSGetExecutablePath (arg2, &len) != 0 ) strcat (arg2, arg);
110+ if (uint32_t len = sz; _NSGetExecutablePath (arg2. get () , &len) != 0 ) strcat (arg2. get () , arg);
114111#else
115- n = readlink (" /proc/self/exe" , arg2, sz);
116- if (n == -1 )
117- strcpy (arg2, arg);
118- else
119- arg2[n] = 0 ;
112+ {
113+ auto const n = readlink (" /proc/self/exe" , arg2, sz);
114+ if (n == -1 )
115+ strcpy (arg2, arg);
116+ else
117+ arg2[n] = 0 ;
118+ }
120119#endif
121120 // arg2 is path (abs or relative) to executable or soft link
122- n = readlink (arg2, arg3, sz);
123-
121+ auto const n = readlink (arg2.get (), arg3.get (), sz);
124122 if (n == -1 )
125- strcpy (arg3, arg2);
123+ strcpy (arg3. get () , arg2. get () );
126124 else
127125 arg3[n] = 0 ;
128126
129- if (' /' == * arg3)
130- path = arg3;
127+ if (' /' == arg3[ 0 ] )
128+ path = arg3. get () ;
131129 else
132- path = std::filesystem::current_path () / arg3;
133- // Now append path_temp to path, as all POSIX and macOS API calls are done, and free up arg2, arg3, path_temp.
134- delete[] arg2;
135- delete[] arg3;
130+ path = std::filesystem::current_path () / arg3.get ();
136131
137132 path.remove_filename ();
138133
0 commit comments