Skip to content

Commit

Permalink
fix call to stat() on mingw
Browse files Browse the repository at this point in the history
  • Loading branch information
LizzyFleckenstein03 committed Aug 3, 2024
1 parent b14c8e6 commit a824d80
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

void dragonblocks_init(int argc)
Expand All @@ -11,8 +12,16 @@ void dragonblocks_init(int argc)
pthread_setname_np(pthread_self(), "main");
#endif // __GLIBC__

// stat() does not properly handle trailing slashes on dirs on MinGW in some cases
// strip trailing slashes
size_t len = strlen(ASSET_PATH);
char stat_path[len+1];
strcpy(stat_path, ASSET_PATH);
while (len > 0 && stat_path[len-1] == '/')
stat_path[--len] = '\0';

struct stat sb;
if (stat(ASSET_PATH, &sb) != 0 || !S_ISDIR(sb.st_mode)) {
if (stat(stat_path, &sb) != 0 || !S_ISDIR(sb.st_mode)) {
fprintf(stderr, "[error] asset directory not found at %s, "
"invoke game from correct path\n", ASSET_PATH);
exit(EXIT_FAILURE);
Expand Down

0 comments on commit a824d80

Please sign in to comment.