From 381ff055059337befcdf33ef8590ac2c065cb9cc Mon Sep 17 00:00:00 2001 From: usa Date: Sun, 3 Aug 2003 17:48:51 +0000 Subject: * win32/win32.c (rb_w32_utime): never use utime() of C runtime. [ruby-talk:77782] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'win32') diff --git a/win32/win32.c b/win32/win32.c index b871bafd62..7527d29706 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -3178,7 +3178,7 @@ unixtime_to_filetime(time_t time, FILETIME *ft) int rb_w32_utime(const char *path, struct utimbuf *times) { - HANDLE hDir; + HANDLE hFile; SYSTEMTIME st; FILETIME atime, mtime; struct tm *tm; @@ -3188,9 +3188,6 @@ rb_w32_utime(const char *path, struct utimbuf *times) if (rb_w32_stat(path, &stat)) { return -1; } - if (!(stat.st_mode & S_IFDIR) || IsWin95()) { - return utime(path, times); - } if (unixtime_to_filetime(times->actime, &atime)) { return -1; @@ -3199,17 +3196,21 @@ rb_w32_utime(const char *path, struct utimbuf *times) return -1; } - hDir = CreateFile(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, 0); - if (hDir == INVALID_HANDLE_VALUE) { - errno = map_errno(); - return -1; - } - if (!SetFileTime(hDir, NULL, &atime, &mtime)) { - errno = map_errno(); - ret = -1; - } - CloseHandle(hDir); + RUBY_CRITICAL({ + hFile = CreateFile(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, + IsWin95() ? 0 : FILE_FLAG_BACKUP_SEMANTICS, 0); + if (hFile == INVALID_HANDLE_VALUE) { + errno = map_errno(); + ret = -1; + } + else { + if (!SetFileTime(hFile, NULL, &atime, &mtime)) { + errno = map_errno(); + ret = -1; + } + CloseHandle(hFile); + } + }); return ret; } -- cgit v1.2.3