diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 4 | ||||
-rw-r--r-- | src/game.h | 2 | ||||
-rw-r--r-- | src/main.c | 21 |
3 files changed, 20 insertions, 7 deletions
@@ -30,13 +30,13 @@ _db_game_is_dir(const struct dirent *entry) } int -db_games_find(char ***games) +db_games_find(const char *games_dir, char ***games) { struct dirent **entries; int n; int i; - n = scandir("games", &entries, &_db_game_is_dir, alphasort); + n = scandir(games_dir, &entries, &_db_game_is_dir, alphasort); *games = calloc(n, sizeof(**games)); if (*games == NULL) { @@ -20,6 +20,6 @@ #ifndef DB_GAME_H_ #define DB_GAME_H_ -int db_games_find(char ***games); +int db_games_find(const char *games_dir, char ***games); #endif /* DB_GAME_H_ */ @@ -1,15 +1,28 @@ +#include <libgen.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "game.h" int main(int argc, char *argv[]) { - char **games; - int n; - int i; + char *program_dir; + const char *games_dir; + char **games; + int n; + int i; - n = db_games_find(&games); + program_dir = realpath(dirname(argv[0]), NULL); + if (strcmp(program_dir, ABS_BUILDDIR) == 0) { + /* Running in place */ + games_dir = ABS_BUILDDIR "/games"; + } else { + /* Running from installation */ + games_dir = GAMESDIR; + } + free(program_dir); + n = db_games_find(games_dir, &games); printf("%d games:\n", n); for (i = 0; i < n; ++i) { printf("\t%s\n", games[i]); |