msvcrt: _[w]access_s returns an error code.

This commit is contained in:
Vincent Povirk 2013-08-21 15:13:36 -05:00 committed by Alexandre Julliard
parent 6ea59b9157
commit 5f2e48f737
2 changed files with 92 additions and 6 deletions

View File

@ -111,6 +111,7 @@ static int (__cdecl *p_vswprintf_l)(wchar_t*, const wchar_t*, _locale_t, __ms_va
static FILE* (__cdecl *p_fopen)(const char*, const char*);
static int (__cdecl *p_fclose)(FILE*);
static int (__cdecl *p_unlink)(const char*);
static int (__cdecl *p_access_s)(const char*, int);
static void (__cdecl *p_lock_file)(FILE*);
static void (__cdecl *p_unlock_file)(FILE*);
static int (__cdecl *p_fileno)(FILE*);
@ -298,6 +299,7 @@ static BOOL init(void)
SET(p_fopen, "fopen");
SET(p_fclose, "fclose");
SET(p_unlink, "_unlink");
SET(p_access_s, "_access_s");
SET(p_lock_file, "_lock_file");
SET(p_unlock_file, "_unlock_file");
SET(p_fileno, "_fileno");
@ -1217,6 +1219,85 @@ static void test_byteswap(void)
ok(ret == 0, "ret = %lx\n", ret);
}
static void test_access_s(void)
{
FILE *f;
int res;
f = p_fopen("test_file", "w");
ok(f != NULL, "unable to create test file\n");
if(!f)
return;
p_fclose(f);
errno = 0xdeadbeef;
res = p_access_s("test_file", 0);
ok(res == 0, "got %x\n", res);
ok(errno == 0xdeadbeef, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 2);
ok(res == 0, "got %x\n", res);
ok(errno == 0xdeadbeef, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 4);
ok(res == 0, "got %x\n", res);
ok(errno == 0xdeadbeef, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 6);
ok(res == 0, "got %x\n", res);
ok(errno == 0xdeadbeef, "got %x\n", res);
SetFileAttributesA("test_file", FILE_ATTRIBUTE_READONLY);
errno = 0xdeadbeef;
res = p_access_s("test_file", 0);
ok(res == 0, "got %x\n", res);
ok(errno == 0xdeadbeef, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 2);
ok(res == EACCES, "got %x\n", res);
ok(errno == EACCES, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 4);
ok(res == 0, "got %x\n", res);
ok(errno == 0xdeadbeef, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 6);
ok(res == EACCES, "got %x\n", res);
ok(errno == EACCES, "got %x\n", res);
SetFileAttributesA("test_file", FILE_ATTRIBUTE_NORMAL);
p_unlink("test_file");
errno = 0xdeadbeef;
res = p_access_s("test_file", 0);
ok(res == ENOENT, "got %x\n", res);
ok(errno == ENOENT, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 2);
ok(res == ENOENT, "got %x\n", res);
ok(errno == ENOENT, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 4);
ok(res == ENOENT, "got %x\n", res);
ok(errno == ENOENT, "got %x\n", res);
errno = 0xdeadbeef;
res = p_access_s("test_file", 6);
ok(res == ENOENT, "got %x\n", res);
ok(errno == ENOENT, "got %x\n", res);
}
START_TEST(msvcr90)
{
if(!init())
@ -1242,4 +1323,5 @@ START_TEST(msvcr90)
test__vswprintf_l();
test_nonblocking_file_access();
test_byteswap();
test_access_s();
}

View File

@ -715,10 +715,12 @@ int CDECL MSVCRT__access(const char *filename, int mode)
*/
int CDECL _access_s(const char *filename, int mode)
{
if (!MSVCRT_CHECK_PMT(filename != NULL)) return -1;
if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return -1;
if (!MSVCRT_CHECK_PMT(filename != NULL)) return *MSVCRT__errno();
if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return *MSVCRT__errno();
return MSVCRT__access(filename, mode);
if (MSVCRT__access(filename, mode) == -1)
return *MSVCRT__errno();
return 0;
}
/*********************************************************************
@ -748,10 +750,12 @@ int CDECL MSVCRT__waccess(const MSVCRT_wchar_t *filename, int mode)
*/
int CDECL _waccess_s(const MSVCRT_wchar_t *filename, int mode)
{
if (!MSVCRT_CHECK_PMT(filename != NULL)) return -1;
if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return -1;
if (!MSVCRT_CHECK_PMT(filename != NULL)) return *MSVCRT__errno();
if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return *MSVCRT__errno();
return MSVCRT__waccess(filename, mode);
if (MSVCRT__waccess(filename, mode) == -1)
return *MSVCRT__errno();
return 0;
}
/*********************************************************************