diff options
author | eban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-08-09 04:26:06 +0000 |
---|---|---|
committer | eban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-08-09 04:26:06 +0000 |
commit | 2eb957394cc2120ba77e6a3bf367d029a148ca3a (patch) | |
tree | 8203ce8ed2cc35bcfd59157fb953bd8681e3bd45 /win32/win32.c | |
parent | fab656fc05988c2fed6e6697575d112606ec38be (diff) | |
download | ruby-2eb957394cc2120ba77e6a3bf367d029a148ca3a.tar.gz ruby-2eb957394cc2120ba77e6a3bf367d029a148ca3a.tar.xz ruby-2eb957394cc2120ba77e6a3bf367d029a148ca3a.zip |
eban
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r-- | win32/win32.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c index 7d589ec59..d7f12d3f0 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2432,3 +2432,51 @@ win32_getenv(const char *name) return curitem; } + +int +myrename(const char *oldpath, const char *newpath) +{ + int res = 0; + int oldatts; + int newatts; + + oldatts = GetFileAttributes(oldpath); + newatts = GetFileAttributes(newpath); + + if (oldatts == -1) { + printf("file to move doesn't exist"); + return -1; + } + + if (newatts != -1 && newatts & FILE_ATTRIBUTE_READONLY) + SetFileAttributesA(newpath, newatts & ~ FILE_ATTRIBUTE_READONLY); + + if (!MoveFile(oldpath, newpath)) + res = -1; + + if (res == 0 || (GetLastError() != ERROR_ALREADY_EXISTS + && GetLastError() != ERROR_FILE_EXISTS)) + goto done; + + if (IsWinNT()) { + if (MoveFileEx(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) + res = 0; + } else { + for (;;) { + if (!DeleteFile(newpath) && GetLastError() != ERROR_FILE_NOT_FOUND) + break; + else if (MoveFile(oldpath, newpath)) { + res = 0; + break; + } + } + } + +done: + if (res) + errno = GetLastError(); + else + SetFileAttributes(newpath, oldatts); + + return res; +} |