X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=7a55d94de4e5ebf8ae1881ca330828937a9a4a73;hb=efd0d0abb853018aa3ccc3c727b39bd7f5ba679d;hp=b3edef75f1bbf367d8a8d244ad6ef3b67a3ac8c8;hpb=4311b2aed4570447d0e082334e8b8a6b7da6e9f9;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index b3edef75..7a55d94d 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1306,6 +1306,12 @@ inline void swap_number_pairs(int *x1, int *y1, int *x2, int *y2) #ifndef S_IXOTH #define S_IXOTH S_IXUSR #endif +#ifndef S_IRWXG +#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) +#endif +#ifndef S_ISGID +#define S_ISGID 0 +#endif #endif /* PLATFORM_WIN32 */ /* file permissions for newly written files */ @@ -1343,29 +1349,39 @@ char *getSetupDir() return getUserDataDir(); } -void createDirectory(char *dir, char *text, int permission_class) +static mode_t posix_umask(mode_t mask) { #if defined(PLATFORM_UNIX) + return umask(mask); +#else + return 0; +#endif +} + +static int posix_mkdir(const char *pathname, mode_t mode) +{ +#if defined(PLATFORM_WIN32) + return mkdir(pathname); +#else + return mkdir(pathname, mode); +#endif +} + +void createDirectory(char *dir, char *text, int permission_class) +{ /* leave "other" permissions in umask untouched, but ensure group parts of USERDATA_DIR_MODE are not masked */ mode_t dir_mode = (permission_class == PERMS_PRIVATE ? DIR_PERMS_PRIVATE : DIR_PERMS_PUBLIC); - mode_t normal_umask = umask(0); + mode_t normal_umask = posix_umask(0); mode_t group_umask = ~(dir_mode & S_IRWXG); - umask(normal_umask & group_umask); -#endif + posix_umask(normal_umask & group_umask); if (access(dir, F_OK) != 0) -#if defined(PLATFORM_WIN32) - if (mkdir(dir) != 0) -#else - if (mkdir(dir, dir_mode) != 0) -#endif + if (posix_mkdir(dir, dir_mode) != 0) Error(ERR_WARN, "cannot create %s directory '%s'", text, dir); -#if defined(PLATFORM_UNIX) - umask(normal_umask); /* reset normal umask */ -#endif + posix_umask(normal_umask); /* reset normal umask */ } void InitUserDataDirectory()