summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-03-24 22:53:45 +0000
committerChris Wilson <chris+github@qwirx.com>2007-03-24 22:53:45 +0000
commit198d823a23f6fbece6a4792c6d7f7f787555ae1e (patch)
tree88b776b8bd0552f31ab0b841606a14024d461c46 /lib
parent96070af8205f85db802a7aed81979e7f2cf92d29 (diff)
Add emulated rename() with path conversion. (refs #3, merges [1436] and
[1438])
Diffstat (limited to 'lib')
-rw-r--r--lib/win32/emu.cpp66
-rw-r--r--lib/win32/emu.h2
2 files changed, 68 insertions, 0 deletions
diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp
index 112b1c9f..0aedffc7 100644
--- a/lib/win32/emu.cpp
+++ b/lib/win32/emu.cpp
@@ -1609,6 +1609,72 @@ int emu_unlink(const char* pFileName)
return 0;
}
+int emu_rename(const char* pOldFileName, const char* pNewFileName)
+{
+ std::string OldPathWithUnicode =
+ ConvertPathToAbsoluteUnicode(pOldFileName);
+
+ if (OldPathWithUnicode.size() == 0)
+ {
+ // error already logged by ConvertPathToAbsoluteUnicode()
+ return -1;
+ }
+
+ WCHAR* pOldBuffer = ConvertUtf8ToWideString(OldPathWithUnicode.c_str());
+ if (!pOldBuffer)
+ {
+ return -1;
+ }
+
+ std::string NewPathWithUnicode =
+ ConvertPathToAbsoluteUnicode(pNewFileName);
+
+ if (NewPathWithUnicode.size() == 0)
+ {
+ // error already logged by ConvertPathToAbsoluteUnicode()
+ delete [] pOldBuffer;
+ return -1;
+ }
+
+ WCHAR* pNewBuffer = ConvertUtf8ToWideString(NewPathWithUnicode.c_str());
+ if (!pNewBuffer)
+ {
+ delete [] pOldBuffer;
+ return -1;
+ }
+
+ BOOL result = MoveFileW(pOldBuffer, pNewBuffer);
+ DWORD err = GetLastError();
+ delete [] pOldBuffer;
+ delete [] pNewBuffer;
+
+ if (!result)
+ {
+ if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND)
+ {
+ errno = ENOENT;
+ }
+ else if (err == ERROR_SHARING_VIOLATION)
+ {
+ errno = EBUSY;
+ }
+ else if (err == ERROR_ACCESS_DENIED)
+ {
+ errno = EACCES;
+ }
+ else
+ {
+ ::syslog(LOG_WARNING, "Failed to rename file "
+ "'%s' to '%s': %s", pOldFileName, pNewFileName,
+ GetErrorMessage(err).c_str());
+ errno = ENOSYS;
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
int console_read(char* pBuffer, size_t BufferSize)
{
HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
diff --git a/lib/win32/emu.h b/lib/win32/emu.h
index a4af6e64..ec6c0918 100644
--- a/lib/win32/emu.h
+++ b/lib/win32/emu.h
@@ -337,6 +337,7 @@ int emu_stat (const char* pName, struct stat* st);
int emu_utimes (const char* pName, const struct timeval[]);
int emu_chmod (const char* pName, mode_t mode);
char* emu_getcwd (char* pBuffer, int BufSize);
+int emu_rename (const char* pOldName, const char* pNewName);
#define chdir(directory) emu_chdir (directory)
#define mkdir(path, mode) emu_mkdir (path)
@@ -347,6 +348,7 @@ char* emu_getcwd (char* pBuffer, int BufSize);
#define utimes(buffer, times) emu_utimes (buffer, times)
#define chmod(file, mode) emu_chmod (file, mode)
#define getcwd(buffer, size) emu_getcwd (buffer, size)
+#define rename(oldname, newname) emu_rename (oldname, newname)
int statfs(const char * name, struct statfs * s);