aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-04-14 06:57:27 +0200
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-10 19:28:27 +1000
commitf630faee2045fa28c61a3cea760ab8a9b65c1bb3 (patch)
tree18d8ddef8d0ba0f5055294a3401d6ca3a674ae16
parentcd506ae1ad813efcfa89b6373fe3e76e3c4dd9a4 (diff)
downloadbusybox-w32-f630faee2045fa28c61a3cea760ab8a9b65c1bb3.tar.gz
busybox-w32-f630faee2045fa28c61a3cea760ab8a9b65c1bb3.tar.bz2
busybox-w32-f630faee2045fa28c61a3cea760ab8a9b65c1bb3.zip
win32: Replace rename() (WHY?)
-rw-r--r--include/mingw.h2
-rw-r--r--win32/mingw.c34
2 files changed, 36 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h
index ed718fb5d..c2953c390 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -121,7 +121,9 @@ NOIMPL(sigfillset,int *mask UNUSED_PARAM);
121 121
122int fdprintf(int fd, const char *format, ...); 122int fdprintf(int fd, const char *format, ...);
123FILE* mingw_fopen(const char *filename, const char *mode); 123FILE* mingw_fopen(const char *filename, const char *mode);
124int mingw_rename(const char*, const char*);
124#define fopen mingw_fopen 125#define fopen mingw_fopen
126#define rename mingw_rename
125 127
126/* 128/*
127 * ANSI emulation wrappers 129 * ANSI emulation wrappers
diff --git a/win32/mingw.c b/win32/mingw.c
index 61f786287..eeb96db83 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -476,6 +476,40 @@ char *mingw_getcwd(char *pointer, int len)
476 return ret; 476 return ret;
477} 477}
478 478
479#undef rename
480int mingw_rename(const char *pold, const char *pnew)
481{
482 DWORD attrs;
483
484 /*
485 * Try native rename() first to get errno right.
486 * It is based on MoveFile(), which cannot overwrite existing files.
487 */
488 if (!rename(pold, pnew))
489 return 0;
490 if (errno != EEXIST)
491 return -1;
492 if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING))
493 return 0;
494 /* TODO: translate more errors */
495 if (GetLastError() == ERROR_ACCESS_DENIED &&
496 (attrs = GetFileAttributes(pnew)) != INVALID_FILE_ATTRIBUTES) {
497 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
498 errno = EISDIR;
499 return -1;
500 }
501 if ((attrs & FILE_ATTRIBUTE_READONLY) &&
502 SetFileAttributes(pnew, attrs & ~FILE_ATTRIBUTE_READONLY)) {
503 if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING))
504 return 0;
505 /* revert file attributes on failure */
506 SetFileAttributes(pnew, attrs);
507 }
508 }
509 errno = EACCES;
510 return -1;
511}
512
479struct passwd *getpwuid(int uid) 513struct passwd *getpwuid(int uid)
480{ 514{
481 static char user_name[100]; 515 static char user_name[100];