From 9953e663a6e3fb91e13731315dd3c332ed24ed94 Mon Sep 17 00:00:00 2001 From: Louis Lenders Date: Mon, 9 May 2011 22:56:23 +0200 Subject: msvcrt: fix utime to correctly handle a NULL-pointer with tests --- dlls/msvcrt/file.c | 4 +++ dlls/msvcrt/tests/file.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 0 deletions(-) diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 84ec729..36a66d1 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2272,6 +2272,10 @@ int CDECL _utime64(const char* path, struct MSVCRT___utimbuf64 *t) int CDECL _utime32(const char* path, struct MSVCRT___utimbuf32 *t) { struct MSVCRT___utimbuf64 t64; + + if (!t) + return _utime64( path, NULL ); + t64.actime = t->actime; t64.modtime = t->modtime; return _utime64( path, &t64 ); diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 0231f72..50d288d 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -24,8 +24,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -38,6 +40,7 @@ static HANDLE proc_handles[2]; static int (__cdecl *p_fopen_s)(FILE**, const char*, const char*); static int (__cdecl *p__wfopen_s)(FILE**, const wchar_t*, const wchar_t*); +static int (__cdecl *p_utime)(const char*, const struct utimbuf*); static void init(void) { @@ -45,6 +48,7 @@ static void init(void) p_fopen_s = (void*)GetProcAddress(hmod, "fopen_s"); p__wfopen_s = (void*)GetProcAddress(hmod, "_wfopen_s"); + p_utime = (void*)GetProcAddress(hmod, "_utime"); } static void test_filbuf( void ) @@ -1522,6 +1526,52 @@ static void test_dup2(void) ok(-1 == _dup2(0, -1), "expected _dup2 to fail when second arg is negative\n" ); } +static void test_utime(void) +{ + int fd; + struct utimbuf ubuf; + struct stat info; + struct tm access_time = {0} , modification_time = {0}; + + fd = open("fd.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE); + ok(fd != -1, "Couldn't create test file\n"); + + /* set access date to Wed Nov 15 00:00:00 2000 */ + access_time.tm_mon = 10; + access_time.tm_mday = 15; + access_time.tm_year = 100; + + /* set modification date to Tue Feb 22 08:00:00 2005 */ + modification_time.tm_hour = 8; + modification_time.tm_mday = 22; + modification_time.tm_mon = 1; + modification_time.tm_year = 105; + + ubuf.actime = mktime(&access_time); + ubuf.modtime = mktime(&modification_time); + + ok(stat("fd.tst", &info) == 0, "file-status information could not be obtained\n"); + + trace("testfile modification time is %s\n", ctime(&info.st_mtime)); + trace("testfile access time is %s\n", ctime(&info.st_atime)); + + ok(p_utime("fd.tst", &ubuf) == 0, "utime failed\n"); + ok(stat("fd.tst", &info) == 0, "file-status information could not be obtained\n"); + + trace("changed the modification time to %s\n", ctime(&info.st_mtime)); + trace("changed the access time to %s\n", ctime(&info.st_atime)); + + /* test with NULL pointer */ + ok(p_utime("fd.tst", NULL) == 0, "utime failed\n"); + ok(stat("fd.tst", &info) == 0, "file-status information could not be obtained\n"); + + trace(" changed the modification time back to %s\n", ctime(&info.st_mtime)); + trace(" changed the access time back to %s\n", ctime(&info.st_atime)); + + ok(close(fd) == 0, "Couldn't close testfile\n"); + ok(unlink("fd.tst") == 0, "Couldn't unlink\n"); +} + START_TEST(file) { int arg_c; @@ -1573,6 +1623,7 @@ START_TEST(file) test_get_osfhandle(); test_setmaxstdio(); test_pipes(arg_v[0]); + test_utime(); /* Wait for the (_P_NOWAIT) spawned processes to finish to make sure the report * file contains lines in the correct order -- 1.7.4.1