1 // 2 // access.cpp 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // The _access() and _access_s() functions, which test file accessibility. 7 // 8 #include <corecrt_internal.h> 9 #include <io.h> 10 #include <corecrt_internal_win32_buffer.h> 11 12 // See _waccess_s for information about this function's behavior. 13 extern "C" errno_t __cdecl _access_s(char const* const path, int const access_mode) 14 { 15 if (path == nullptr) { 16 return _waccess_s(nullptr, access_mode); 17 } 18 19 __crt_internal_win32_buffer<wchar_t> wide_path; 20 21 errno_t const cvt = __acrt_mbs_to_wcs_cp(path, wide_path, __acrt_get_utf8_acp_compatibility_codepage()); 22 23 if (cvt != 0) { 24 return -1; 25 } 26 27 return _waccess_s(wide_path.data(), access_mode); 28 } 29 30 // The same as _access_s, but transforms all errors into a -1 return value. 31 extern "C" int __cdecl _access(char const* const path, int const access_mode) 32 { 33 return _access_s(path, access_mode) == 0 ? 0 : -1; 34 } 35