| author | |
| committer | |
| log | 78549d1e109a922e63b52b3d4a445217ca997c9c |
| tree | e3f87575c3089013deecfa27015c959e399ca0bb |
| parent | 89d4ac628959fe301ee93b88fdc66ab1988d5f33 |
3 files changed, 75 insertions(+), 0 deletions(-)
lib/libc/mingw/misc/mingw-access.c created+54| ... | @@ -0,0 +1,54 @@ | ||
| 1 | /** | ||
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | ||
| 3 | * This file is part of the mingw-w64 runtime package. | ||
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | ||
| 5 | */ | ||
| 6 | #include <windows.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <io.h> | ||
| 9 | |||
| 10 | int __cdecl __mingw_access(const char *fname, int mode); | ||
| 11 | |||
| 12 | int __cdecl __mingw_access(const char *fname, int mode) | ||
| 13 | { | ||
| 14 | DWORD attr; | ||
| 15 | |||
| 16 | if (fname == NULL || (mode & ~(F_OK | X_OK | W_OK | R_OK))) | ||
| 17 | { | ||
| 18 | errno = EINVAL; | ||
| 19 | return -1; | ||
| 20 | } | ||
| 21 | |||
| 22 | attr = GetFileAttributesA(fname); | ||
| 23 | if (attr == INVALID_FILE_ATTRIBUTES) | ||
| 24 | { | ||
| 25 | switch (GetLastError()) | ||
| 26 | { | ||
| 27 | case ERROR_FILE_NOT_FOUND: | ||
| 28 | case ERROR_PATH_NOT_FOUND: | ||
| 29 | errno = ENOENT; | ||
| 30 | break; | ||
| 31 | case ERROR_ACCESS_DENIED: | ||
| 32 | errno = EACCES; | ||
| 33 | break; | ||
| 34 | default: | ||
| 35 | errno = EINVAL; | ||
| 36 | } | ||
| 37 | return -1; | ||
| 38 | } | ||
| 39 | |||
| 40 | if (attr & FILE_ATTRIBUTE_DIRECTORY) | ||
| 41 | { | ||
| 42 | /* All directories have read & write access */ | ||
| 43 | return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK)) | ||
| 47 | { | ||
| 48 | /* no write permission on file */ | ||
| 49 | errno = EACCES; | ||
| 50 | return -1; | ||
| 51 | } | ||
| 52 | else | ||
| 53 | return 0; | ||
| 54 | } | ||
lib/libc/mingw/misc/ucrt-access.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | /** | ||
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | ||
| 3 | * This file is part of the mingw-w64 runtime package. | ||
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <io.h> | ||
| 8 | |||
| 9 | int __cdecl __mingw_access(const char *fname, int mode); | ||
| 10 | |||
| 11 | int __cdecl access(const char *fname, int mode) | ||
| 12 | { | ||
| 13 | /* On UCRT, unconditionally forward access to __mingw_access. UCRT's | ||
| 14 | * access() function return an error if passed the X_OK constant, | ||
| 15 | * while msvcrt.dll's access() doesn't. (It's reported that msvcrt.dll's | ||
| 16 | * access() also returned errors on X_OK in the version shipped in Vista, | ||
| 17 | * but in recent tests it's no longer the case.) */ | ||
| 18 | return __mingw_access(fname, mode); | ||
| 19 | } | ||
src/mingw.zig+2| ... | @@ -697,6 +697,7 @@ const mingwex_generic_src = [_][]const u8{ | ... | @@ -697,6 +697,7 @@ const mingwex_generic_src = [_][]const u8{ |
| 697 | "misc" ++ path.sep_str ++ "mbrtowc.c", | 697 | "misc" ++ path.sep_str ++ "mbrtowc.c", |
| 698 | "misc" ++ path.sep_str ++ "mbsinit.c", | 698 | "misc" ++ path.sep_str ++ "mbsinit.c", |
| 699 | "misc" ++ path.sep_str ++ "mempcpy.c", | 699 | "misc" ++ path.sep_str ++ "mempcpy.c", |
| 700 | "misc" ++ path.sep_str ++ "mingw-access.c", | ||
| 700 | "misc" ++ path.sep_str ++ "mingw-aligned-malloc.c", | 701 | "misc" ++ path.sep_str ++ "mingw-aligned-malloc.c", |
| 701 | "misc" ++ path.sep_str ++ "mingw_getsp.S", | 702 | "misc" ++ path.sep_str ++ "mingw_getsp.S", |
| 702 | "misc" ++ path.sep_str ++ "mingw_matherr.c", | 703 | "misc" ++ path.sep_str ++ "mingw_matherr.c", |
| ... | @@ -716,6 +717,7 @@ const mingwex_generic_src = [_][]const u8{ | ... | @@ -716,6 +717,7 @@ const mingwex_generic_src = [_][]const u8{ |
| 716 | "misc" ++ path.sep_str ++ "tfind.c", | 717 | "misc" ++ path.sep_str ++ "tfind.c", |
| 717 | "misc" ++ path.sep_str ++ "tsearch.c", | 718 | "misc" ++ path.sep_str ++ "tsearch.c", |
| 718 | "misc" ++ path.sep_str ++ "twalk.c", | 719 | "misc" ++ path.sep_str ++ "twalk.c", |
| 720 | "misc" ++ path.sep_str ++ "ucrt-access.c", | ||
| 719 | "misc" ++ path.sep_str ++ "wcrtomb.c", | 721 | "misc" ++ path.sep_str ++ "wcrtomb.c", |
| 720 | "misc" ++ path.sep_str ++ "wcsnlen.c", | 722 | "misc" ++ path.sep_str ++ "wcsnlen.c", |
| 721 | "misc" ++ path.sep_str ++ "wcstof.c", | 723 | "misc" ++ path.sep_str ++ "wcstof.c", |