summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2011-07-26 11:07:08 +0000
committerroot <root>2011-07-26 11:07:08 +0000
commitc18752d00052e3284b84db29bdadb42f83a9dcec (patch)
tree34a52b00ebed502464d7cf9cef92e2a811615460
parentf5975d60cfe2e7d1b6c259f5ad800a823ee682c3 (diff)
better rename()
-rw-r--r--ecb.h3
-rw-r--r--eio.c32
2 files changed, 34 insertions, 1 deletions
diff --git a/ecb.h b/ecb.h
index 36f04fd..75f1237 100644
--- a/ecb.h
+++ b/ecb.h
@@ -88,7 +88,8 @@
#define ECB_MEMORY_FENCE do { } while (0)
#define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
#define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
- #elif defined(_WIN32) && defined(MemoryBarrier)
+ #elif defined(_WIN32)
+ #include <WinNT.h>
#define ECB_MEMORY_FENCE MemoryBarrier ()
#define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
#define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
diff --git a/eio.c b/eio.c
index 30c7f75..6759ea5 100644
--- a/eio.c
+++ b/eio.c
@@ -131,6 +131,37 @@ static void eio_destroy (eio_req *req);
#define statvfs(path,buf) EIO_ENOSYS ()
#define fstatvfs(fd,buf) EIO_ENOSYS ()
+ /* rename() uses MoveFile, which fails to overwrite */
+ #define rename(old,neu) eio__rename (old, neu)
+
+ static int
+ eio__rename (const char *old, const char *neu)
+ {
+ if (MoveFileEx (old, neu, MOVEFILE_REPLACE_EXISTING))
+ return 0;
+
+ /* should steal _dosmaperr */
+ switch (GetLastError ())
+ {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ case ERROR_INVALID_DRIVE:
+ case ERROR_NO_MORE_FILES:
+ case ERROR_BAD_NETPATH:
+ case ERROR_BAD_NET_NAME:
+ case ERROR_BAD_PATHNAME:
+ case ERROR_FILENAME_EXCED_RANGE:
+ errno = ENOENT;
+ break;
+
+ default:
+ errno = EACCES;
+ break;
+ }
+
+ return -1;
+ }
+
/* we could even stat and see if it exists */
static int
symlink (const char *old, const char *neu)
@@ -1676,6 +1707,7 @@ eio__scandir (eio_req *req, etp_worker *self)
{
dirp = 0;
+ /* should steal _dosmaperr */
switch (GetLastError ())
{
case ERROR_FILE_NOT_FOUND: