diff --git a/lib/libspl/include/os/windows/wosix.h b/lib/libspl/include/os/windows/wosix.h index 4ea7f409f6ef..b94ee01106f4 100644 --- a/lib/libspl/include/os/windows/wosix.h +++ b/lib/libspl/include/os/windows/wosix.h @@ -95,6 +95,8 @@ extern FILE *wosix_freopen(const char *path, const char *mode, FILE *stream); /* Technically not needed, but handle mode */ extern FILE *wosix_fopen(const char *name, const char *mode); +extern int wosix_access(const char *name, int mode); + /* * Thin wrapper for the POSIX IO calls, to translate to HANDLEs * @@ -168,4 +170,5 @@ extern FILE *wosix_fopen(const char *name, const char *mode); #define mmap wosix_mmap #define munmap wosix_munmap #define fopen wosix_fopen +#define access wosix_access #endif /* WOSIX_HEADER */ diff --git a/lib/libspl/os/windows/posix.c b/lib/libspl/os/windows/posix.c index 158f2c55f34d..5bec552c0d97 100644 --- a/lib/libspl/os/windows/posix.c +++ b/lib/libspl/os/windows/posix.c @@ -1855,3 +1855,27 @@ timer_settime(timer_t, int, const struct itimerspec *__restrict, { return (0); } + +int +wosix_access(const char *name, int mode) +{ + DWORD dwAttrib = GetFileAttributes(name); + boolean_t isFile; + + isFile = (dwAttrib != INVALID_FILE_ATTRIBUTES && + !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); + + if (!isFile) { + errno = ENOENT; + return (-1); + } + + /* Windows does not have X_OK (execute), and it assert()s */ + if (mode == X_OK) + return (0); + + mode &= ~X_OK; + +#undef access + return (access(name, mode)); +}