Created
July 19, 2018 19:24
-
-
Save W4RH4WK/cd1d2442e4be6fd1036f3bde3189977e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <libgen.h> | |
#include <linux/limits.h> | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
static const char MARKER_FILE[] = "build.ninja"; | |
static bool exe_in_build_dir(void) | |
{ | |
char exe_path[PATH_MAX + 1]; | |
ssize_t n = readlink("/proc/self/exe", exe_path, PATH_MAX); | |
if (n == -1) { | |
return false; | |
} | |
exe_path[n] = '\0'; | |
char path[PATH_MAX + sizeof(MARKER_FILE) + 1]; | |
snprintf(path, sizeof(path), "%s/%s", dirname(exe_path), MARKER_FILE); | |
return access(path, F_OK) == 0; | |
} | |
const char* resource_path(void) | |
{ | |
if (exe_in_build_dir()) { | |
return "@BUILD_DIR@"; | |
} else { | |
return "@INSTALL_DIR@"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef RESOURCE_PATH_H | |
#define RESOURCE_PATH_H | |
const char* resource_path(void); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment