[Box Backup-commit] COMMIT r2389 - box/trunk/lib/win32

boxbackup-dev at boxbackup.org boxbackup-dev at boxbackup.org
Sun Nov 30 21:54:55 GMT 2008


Author: chris
Date: 2008-11-30 21:54:55 +0000 (Sun, 30 Nov 2008)
New Revision: 2389

Modified:
   box/trunk/lib/win32/emu.cpp
   box/trunk/lib/win32/emu.h
Log:
openfile() stores its Windows error code (from GetLastError() or
synthetic) in winerrno, to enable better error handling outside.


Modified: box/trunk/lib/win32/emu.cpp
===================================================================
--- box/trunk/lib/win32/emu.cpp	2008-11-30 21:53:14 UTC (rev 2388)
+++ box/trunk/lib/win32/emu.cpp	2008-11-30 21:54:55 UTC (rev 2389)
@@ -31,6 +31,8 @@
 static bool gFinishTimer;
 static CRITICAL_SECTION gLock;
 
+DWORD winerrno;
+
 typedef struct 
 {
 	int countDown;
@@ -285,11 +287,12 @@
 
 	if (len == 0)
 	{
+		winerrno = GetLastError();
 		if (logErrors)
 		{
 			::syslog(LOG_WARNING, 
 				"Failed to convert string to wide string: "
-				"%s", GetErrorMessage(GetLastError()).c_str());
+				"%s", GetErrorMessage(winerrno).c_str());
 		}
 		errno = EINVAL;
 		return NULL;
@@ -305,6 +308,7 @@
 				"Failed to convert string to wide string: "
 				"out of memory");
 		}
+		winerrno = ERROR_OUTOFMEMORY;
 		errno = ENOMEM;
 		return NULL;
 	}
@@ -321,11 +325,12 @@
 
 	if (len == 0)
 	{
+		winerrno = GetLastError();
 		if (logErrors)
 		{
 			::syslog(LOG_WARNING, 
 				"Failed to convert string to wide string: "
-				"%s", GetErrorMessage(GetLastError()).c_str());
+				"%s", GetErrorMessage(winerrno).c_str());
 		}
 		errno = EACCES;
 		delete [] buffer;
@@ -519,6 +524,7 @@
 			"Failed to open '%s': path too long", 
 			pFileName);
 		errno = ENAMETOOLONG;
+		winerrno = ERROR_INVALID_NAME;
 		tmpStr = "";
 		return tmpStr;
 	}
@@ -594,6 +600,8 @@
 // --------------------------------------------------------------------------
 HANDLE openfile(const char *pFileName, int flags, int mode)
 {
+	winerrno = ERROR_INVALID_FUNCTION;
+
 	std::string AbsPathWithUnicode = 
 		ConvertPathToAbsoluteUnicode(pFileName);
 	
@@ -667,7 +675,8 @@
 
 	if (hdir == INVALID_HANDLE_VALUE)
 	{
-		switch(GetLastError())
+		winerrno = GetLastError();
+		switch(winerrno)
 		{
 			case ERROR_SHARING_VIOLATION:
 			errno = EBUSY;
@@ -684,6 +693,7 @@
 		return INVALID_HANDLE_VALUE;
 	}
 
+	winerrno = NO_ERROR;
 	return hdir;
 }
 

Modified: box/trunk/lib/win32/emu.h
===================================================================
--- box/trunk/lib/win32/emu.h	2008-11-30 21:53:14 UTC (rev 2388)
+++ box/trunk/lib/win32/emu.h	2008-11-30 21:54:55 UTC (rev 2389)
@@ -245,6 +245,7 @@
 // local constant to open file exclusively without shared access
 #define O_LOCK 0x10000
 
+extern DWORD winerrno; /* used to report errors from openfile() */
 HANDLE openfile(const char *filename, int flags, int mode);
 
 #define LOG_DEBUG LOG_INFO




More information about the Boxbackup-commit mailing list