1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_4@883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eban 2000-08-09 04:49:18 +00:00
parent bcb17d892e
commit 2a76e78e15
4 changed files with 60 additions and 2 deletions

View file

@ -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;
}

View file

@ -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