@@ -279,26 +279,31 @@ void engine_init(const char *boot_path, const char *exec_path) {
279
279
glb_init_each_time ();
280
280
}
281
281
282
- /* Get executable path (when argv[0] is not reliable) */
283
- char * get_execpath (void ) {
284
- char buffer [MAXPATHLEN + 1 ];
285
- size_t size = MAXPATHLEN + 1 ;
282
+ static bool_t get_execpath_ (char * buffer , size_t size ) {
286
283
#if defined(LINUX )/*||defined(EMSCRIPTEN)*/
287
284
ssize_t len ;
288
- if ((len = readlink ("/proc/self/exe" , buffer , size )) == -1 ) return NULL ;
285
+ len = readlink ("/proc/self/exe" , buffer , size );
286
+ return (len != -1 );
289
287
#elif defined(DARWIN )
290
288
uint32_t len = size ;
291
- if (_NSGetExecutablePath (buffer , & len ) == -1 ) return NULL ;
289
+ return (_NSGetExecutablePath (buffer , & len ) != -1 );
292
290
#elif defined(_WIN32 ) || defined(_WIN64 ) /* MinGW */
293
- if (GetModuleFileName (NULL , buffer , size ) == 0 ) return NULL ;
291
+ return (GetModuleFileName (NULL , buffer , size ) != 0 );
294
292
#else
295
- return NULL ;
293
+ return FALSE ;
296
294
/* TODO: Missing support for other OS:
297
295
- Solaris: getexecname()
298
296
- FreeBSD: sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1
299
297
- BSD with procfs: readlink /proc/curproc/file
300
298
*/
301
299
#endif
300
+ }
301
+
302
+ /* Get executable path (when argv[0] is not reliable) */
303
+ char * get_execpath (void ) {
304
+ char buffer [MAXPATHLEN + 1 ];
305
+ size_t size = MAXPATHLEN + 1 ;
306
+ if (!get_execpath_ (buffer , size )) return NULL ;
302
307
return strdup (buffer );
303
308
}
304
309
0 commit comments