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-04-20 19:14:14 +0200
commit77885eb2cbc3c4134742adc81876ca323ccbe102 (patch)
treeee7d4b2df3c230ee064341f9f117519402709261
parentec2e3e4eb749022ce426a4847482c7a386fbf718 (diff)
downloadbusybox-w32-77885eb2cbc3c4134742adc81876ca323ccbe102.tar.gz
busybox-w32-77885eb2cbc3c4134742adc81876ca323ccbe102.tar.bz2
busybox-w32-77885eb2cbc3c4134742adc81876ca323ccbe102.zip
win32: Replace rename() (WHY?)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
-rw-r--r--win32/mingw.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 191ac75f0..7b998623a 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];