mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
add more nuanced platform flags to faccess
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined __unix__
|
#if defined __unix__
|
||||||
|
# include <features.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
@@ -43,11 +44,14 @@ enum faccess_perms {
|
|||||||
FA_R = R_OK, // test for read permissions
|
FA_R = R_OK, // test for read permissions
|
||||||
};
|
};
|
||||||
|
|
||||||
// tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together
|
/* tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together
|
||||||
|
returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */
|
||||||
static inline int faccess(char const* restrict fname, int perms) {
|
static inline int faccess(char const* restrict fname, int perms) {
|
||||||
#if defined __unix__
|
#if defined __unix__ && _POSIX_C_SOURCE >= 200809L
|
||||||
return !access(fname, perms);
|
return !access(fname, perms);
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
return !_access(fname, perms);
|
return !_access(fname, perms);
|
||||||
|
#else
|
||||||
|
# error platform unsupported!
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user