Skip to content

Commit

Permalink
Windows: Wrap posix access()
Browse files Browse the repository at this point in the history
Testing for existence (XOK) will cause
exception in Windows.

Signed-off-by: Jorgen Lundman <lundman@lundman.net>
  • Loading branch information
lundman committed Dec 12, 2023
1 parent d2b239c commit 6543412
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/libspl/include/os/windows/wosix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 */
16 changes: 16 additions & 0 deletions lib/libspl/os/windows/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1855,3 +1855,19 @@ 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)
return (ENOENT);

#undef access
return (access(name, mode));
}

0 comments on commit 6543412

Please sign in to comment.