[Box Backup-dev] COMMIT r277 - box/chris/win32/vc2005-compile-fixes/lib/common
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Thu, 22 Dec 2005 22:34:31 +0000 (GMT)
Author: chris
Date: 2005-12-22 22:34:28 +0000 (Thu, 22 Dec 2005)
New Revision: 277
Modified:
box/chris/win32/vc2005-compile-fixes/lib/common/Guards.h
Log:
* Guards.h
- Reverted bad win32 fixes
Modified: box/chris/win32/vc2005-compile-fixes/lib/common/Guards.h
===================================================================
--- box/chris/win32/vc2005-compile-fixes/lib/common/Guards.h 2005-12-22 22:29:45 UTC (rev 276)
+++ box/chris/win32/vc2005-compile-fixes/lib/common/Guards.h 2005-12-22 22:34:28 UTC (rev 277)
@@ -26,24 +26,12 @@
#include "MemLeakFindOn.h"
-#ifdef WIN32
- #define INVALID_FILE NULL
- typedef HANDLE tOSFileHandle;
-#else
- #define INVALID_FILE -1
- typedef int tOSFileHandle;
-#endif
-
template <int flags = O_RDONLY, int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)>
class FileHandleGuard
{
public:
FileHandleGuard(const char *filename)
-#ifdef WIN32
- : mOSFileHandle(::openfile(filename, flags, mode))
-#else
: mOSFileHandle(::open(filename, flags, mode))
-#endif
{
if(mOSFileHandle < 0)
{
@@ -53,7 +41,7 @@
~FileHandleGuard()
{
- if(mOSFileHandle == INVALID_FILE)
+ if(mOSFileHandle >= 0)
{
Close();
}
@@ -61,28 +49,24 @@
void Close()
{
- if(mOSFileHandle == INVALID_FILE)
+ if(mOSFileHandle < 0)
{
THROW_EXCEPTION(CommonException, FileAlreadyClosed)
}
-#ifdef WIN32
- if(::CloseHandle(mOSFileHandle) == 0)
-#else
if(::close(mOSFileHandle) != 0)
-#endif
{
THROW_EXCEPTION(CommonException, OSFileCloseError)
}
- mOSFileHandle = INVALID_FILE;
+ mOSFileHandle = -1;
}
operator int() const
{
- return (int)mOSFileHandle;
+ return mOSFileHandle;
}
private:
- tOSFileHandle mOSFileHandle;
+ int mOSFileHandle;
};
template<typename type>