summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-03 17:48:51 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-03 17:48:51 +0000
commit381ff055059337befcdf33ef8590ac2c065cb9cc (patch)
treec257a5030ba10b7fc9b7dd1ae16667616bb8dd85 /win32
parent096f7a4c89c9f42872e96268995beed4b64af516 (diff)
* 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
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c31
1 files changed, 16 insertions, 15 deletions
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;
}