From 2a76e78e152820f1bb71781666cb3115537d4a7f Mon Sep 17 00:00:00 2001 From: eban Date: Wed, 9 Aug 2000 04:49:18 +0000 Subject: eban git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_4@883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ version.h | 4 ++-- win32/win32.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ win32/win32.h | 6 ++++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 564c0757f3..e29737df9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Aug 9 13:24:25 2000 WATANABE Hirofumi + + * win32/win32.[ch]: emulate rename(2). + Mon Aug 7 13:59:12 2000 Yukihiro Matsumoto * regex.c (re_match): check for stack depth was needed. diff --git a/version.h b/version.h index 5e4482b63c..a94f01181a 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.4.6" -#define RUBY_RELEASE_DATE "2000-08-01" +#define RUBY_RELEASE_DATE "2000-08-09" #define RUBY_VERSION_CODE 146 -#define RUBY_RELEASE_CODE 20000801 +#define RUBY_RELEASE_CODE 20000809 diff --git a/win32/win32.c b/win32/win32.c index 0b2b3a97d4..538d7578b2 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2371,3 +2371,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; +} diff --git a/win32/win32.h b/win32/win32.h index c44cf73b07..0e363c4364 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -200,6 +200,7 @@ extern struct protoent * mygetprotobynumber(int); extern struct servent * mygetservbyname(char *, char *); extern struct servent * mygetservbyport(int, char *); extern char *win32_getenv(const char *); +extern int myrename(const char *, const char *); extern int chown(const char *, int, int); extern int link(char *, char *); @@ -401,4 +402,9 @@ extern char *mystrerror(int); #endif #define getenv win32_getenv +#ifdef rename +#undef rename +#endif +#define rename myrename + #endif -- cgit v1.2.1