char fullpath[PATH_MAX];
snprintf(fullpath, PATH_MAX, "%s/%s", dir, bin);
- if (realpath(fullpath, ret) == NULL)
- return (1);
+ if (!realpath(fullpath, ret))
+ return 1;
if (stat(fullpath, &sb) != 0)
- return (1);
+ return 1;
- return (0);
+ return 0;
}
static char *
/* First approach: absolute path. */
if (bin[0] == '/') {
if (test_dir(ret, "/", bin) == 0)
- return (ret);
- return (NULL);
+ return ret;
+ return nullptr;
}
/* Second approach: relative path. */
- if (strchr(bin, '/') != NULL) {
+ if (strchr(bin, '/')) {
char cwd[PATH_MAX];
- if (getcwd(cwd, PATH_MAX) == NULL)
- return (NULL);
+ if (!getcwd(cwd, PATH_MAX))
+ return nullptr;
if (test_dir(ret, cwd, bin) == 0)
- return (ret);
- return (NULL);
+ return ret;
+ return nullptr;
}
/* Third approach: $PATH */
- if ((pv = getenv("PATH")) == NULL)
- return (NULL);
+ if ((pv = getenv("PATH")) == nullptr)
+ return nullptr;
s = pv = strdup(pv);
- if (pv == NULL)
- return (NULL);
- while ((t = strsep(&s, ":")) != NULL) {
+ if (!pv)
+ return nullptr;
+ while ((t = strsep(&s, ":")) != nullptr) {
if (test_dir(ret, t, bin) == 0) {
free(pv);
- return (ret);
+ return ret;
}
}
free(pv);
- return (NULL);
+ return nullptr;
}
#endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__
return std::string(exe_path, len);
} else {
// Fall back to the classical detection.
- if (getprogpath(exe_path, argv0) != NULL)
- return exe_path;
+ if (getprogpath(exe_path, argv0))
+ return exe_path;
}
#elif defined(HAVE_DLFCN_H)
// Use dladdr to get executable path if available.