1 #include <windows.h>
2 #include <malloc.h>
3 #include <errno.h>
4 #include <msvcrt.h>
5 #include <io.h>
6
7 static errno_t __cdecl _int_access_s (const char *, int);
8 static errno_t __cdecl _stub (const char *, int);
9
10 errno_t __cdecl (*__MINGW_IMP_SYMBOL(_access_s))(const char *, int) =
11 _stub;
12
13 static errno_t __cdecl
_stub(const char * s,int m)14 _stub (const char *s, int m)
15 {
16 errno_t __cdecl (*f)(const char *, int) = __MINGW_IMP_SYMBOL(_access_s);
17
18 if (f == _stub)
19 {
20 f = (errno_t __cdecl (*)(const char *, int))
21 GetProcAddress (__mingw_get_msvcrt_handle (), "_access_s");
22 if (!f)
23 f = _int_access_s;
24 __MINGW_IMP_SYMBOL(_access_s) = f;
25 }
26 return (*f)(s, m);
27 }
28
29 errno_t __cdecl
_access_s(const char * s,int m)30 _access_s (const char *s, int m)
31 {
32 return _stub (s, m);
33 }
34
35 static errno_t __cdecl
_int_access_s(const char * s,int m)36 _int_access_s (const char *s, int m)
37 {
38 if (!s || (m & ~6) != 0)
39 {
40 _access (NULL, m);
41 return EINVAL;
42 }
43 if (!_access (s, m))
44 return 0;
45 return errno;
46 }
47