summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-09-04 00:03:28 +0000
committerChris Wilson <chris+github@qwirx.com>2006-09-04 00:03:28 +0000
commit3f9f0196e6d437f225cfb14bce8b9b424def09ab (patch)
treed4b96ff1b483f120fb652d9cf399a17079ac7850 /lib
parentb8f9eeceb44b72bbab18ebd0644e1b6cabe624da (diff)
(refs #3)
Emulated chdir, mkdir and unlink should handle file names in UTF-8 as well
Diffstat (limited to 'lib')
-rw-r--r--lib/win32/emu.cpp55
1 files changed, 50 insertions, 5 deletions
diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp
index dc17c1df..423b3632 100644
--- a/lib/win32/emu.cpp
+++ b/lib/win32/emu.cpp
@@ -1402,7 +1402,16 @@ void syslog(int loglevel, const char *frmt, ...)
int emu_chdir(const char* pDirName)
{
- WCHAR* pBuffer = ConvertUtf8ToWideString(pDirName);
+ std::string AbsPathWithUnicode =
+ ConvertPathToAbsoluteUnicode(pDirName);
+
+ if (AbsPathWithUnicode.size() == 0)
+ {
+ // error already logged by ConvertPathToAbsoluteUnicode()
+ return -1;
+ }
+
+ WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
if (!pBuffer) return -1;
int result = SetCurrentDirectoryW(pBuffer);
delete [] pBuffer;
@@ -1420,7 +1429,7 @@ char* emu_getcwd(char* pBuffer, int BufSize)
return NULL;
}
- if (len > BufSize)
+ if ((int)len > BufSize)
{
errno = ENAMETOOLONG;
return NULL;
@@ -1457,7 +1466,16 @@ char* emu_getcwd(char* pBuffer, int BufSize)
int emu_mkdir(const char* pPathName)
{
- WCHAR* pBuffer = ConvertToWideString(pPathName, CP_UTF8);
+ std::string AbsPathWithUnicode =
+ ConvertPathToAbsoluteUnicode(pPathName);
+
+ if (AbsPathWithUnicode.size() == 0)
+ {
+ // error already logged by ConvertPathToAbsoluteUnicode()
+ return -1;
+ }
+
+ WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
if (!pBuffer)
{
return -1;
@@ -1477,18 +1495,45 @@ int emu_mkdir(const char* pPathName)
int emu_unlink(const char* pFileName)
{
- WCHAR* pBuffer = ConvertToWideString(pFileName, CP_UTF8);
+ std::string AbsPathWithUnicode =
+ ConvertPathToAbsoluteUnicode(pFileName);
+
+ if (AbsPathWithUnicode.size() == 0)
+ {
+ // error already logged by ConvertPathToAbsoluteUnicode()
+ return -1;
+ }
+
+ WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
if (!pBuffer)
{
return -1;
}
BOOL result = DeleteFileW(pBuffer);
+ DWORD err = GetLastError();
delete [] pBuffer;
if (!result)
{
- errno = EACCES;
+ 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 delete file "
+ "'%s': error %d", pFileName, (int)err);
+ errno = ENOSYS;
+ }
return -1;
}