Skip to content

Commit

Permalink
(engine) avoid warning for unused var in get_execpath() for some archs
Browse files Browse the repository at this point in the history
Src-commit: 6572649dc3390ea4c1a8008fe739e70b43b21cec
  • Loading branch information
jfmc committed Jul 22, 2024
1 parent 486fa0d commit 88cdf78
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions core/engine/eng_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,26 +279,31 @@ void engine_init(const char *boot_path, const char *exec_path) {
glb_init_each_time();
}

/* Get executable path (when argv[0] is not reliable) */
char *get_execpath(void) {
char buffer[MAXPATHLEN+1];
size_t size = MAXPATHLEN+1;
static bool_t get_execpath_(char *buffer, size_t size) {
#if defined(LINUX)/*||defined(EMSCRIPTEN)*/
ssize_t len;
if ((len = readlink("/proc/self/exe", buffer, size)) == -1) return NULL;
len = readlink("/proc/self/exe", buffer, size);
return (len != -1);
#elif defined(DARWIN)
uint32_t len = size;
if (_NSGetExecutablePath(buffer, &len) == -1) return NULL;
return (_NSGetExecutablePath(buffer, &len) != -1);
#elif defined(_WIN32) || defined(_WIN64) /* MinGW */
if (GetModuleFileName(NULL, buffer, size) == 0) return NULL;
return (GetModuleFileName(NULL, buffer, size) != 0);
#else
return NULL;
return FALSE;
/* TODO: Missing support for other OS:
- Solaris: getexecname()
- FreeBSD: sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1
- BSD with procfs: readlink /proc/curproc/file
*/
#endif
}

/* Get executable path (when argv[0] is not reliable) */
char *get_execpath(void) {
char buffer[MAXPATHLEN+1];
size_t size = MAXPATHLEN+1;
if (!get_execpath_(buffer, size)) return NULL;
return strdup(buffer);
}

Expand Down

0 comments on commit 88cdf78

Please sign in to comment.