[Box Backup-dev] COMMIT r447 - box/chris/win32/vc2005-compile-fixes/lib/win32
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sun, 12 Feb 2006 16:02:45 +0000 (GMT)
Author: chris
Date: 2006-02-12 16:02:42 +0000 (Sun, 12 Feb 2006)
New Revision: 447
Modified:
box/chris/win32/vc2005-compile-fixes/lib/win32/emu.cpp
box/chris/win32/vc2005-compile-fixes/lib/win32/emu.h
Log:
* emu.cpp, emu.h
- Changed ConvertConsoleToUtf8 (and vice versa) to take a std::string ref
argument, and return a bool
Modified: box/chris/win32/vc2005-compile-fixes/lib/win32/emu.cpp
===================================================================
--- box/chris/win32/vc2005-compile-fixes/lib/win32/emu.cpp 2006-02-12 15:07:25 UTC (rev 446)
+++ box/chris/win32/vc2005-compile-fixes/lib/win32/emu.cpp 2006-02-12 16:02:42 UTC (rev 447)
@@ -362,23 +362,32 @@
// Function
// Name: ConvertUtf8ToConsole
// Purpose: Converts a string from UTF-8 to the console
-// code page. Returns a buffer which MUST be freed
-// by the caller with delete[].
-// In case of fire, logs the error and returns NULL.
+// code page. On success, replaces contents of rDest
+// and returns true. In case of fire, logs the error
+// and returns false.
// Created: 4th February 2006
//
// --------------------------------------------------------------------------
-char* ConvertUtf8ToConsole(const char* pString)
+bool ConvertUtf8ToConsole(const char* pString, std::string& rDest)
{
- WCHAR* pMulti = ConvertToWideString(pString, CP_UTF8);
- if (pMulti == NULL)
+ WCHAR* pWide = ConvertToWideString(pString, CP_UTF8);
+ if (pWide == NULL)
{
- return NULL;
+ return false;
}
- char* pConsole = ConvertFromWideString(pMulti, GetConsoleOutputCP());
- delete [] pMulti;
- return pConsole;
+ char* pConsole = ConvertFromWideString(pWide, GetConsoleOutputCP());
+ delete [] pWide;
+
+ if (!pConsole)
+ {
+ return false;
+ }
+
+ rDest = pConsole;
+ delete [] pConsole;
+
+ return true;
}
// --------------------------------------------------------------------------
@@ -386,23 +395,32 @@
// Function
// Name: ConvertConsoleToUtf8
// Purpose: Converts a string from the console code page
-// to UTF-8. Returns a buffer which MUST be freed
-// by the caller with delete[].
-// In case of fire, logs the error and returns NULL.
+// to UTF-8. On success, replaces contents of rDest
+// and returns true. In case of fire, logs the error
+// and returns false.
// Created: 4th February 2006
//
// --------------------------------------------------------------------------
-char* ConvertConsoleToUtf8(const char* pString)
+bool ConvertConsoleToUtf8(const char* pString, std::string& rDest)
{
- WCHAR* pMulti = ConvertToWideString(pString, GetConsoleCP());
- if (pMulti == NULL)
+ WCHAR* pWide = ConvertToWideString(pString, GetConsoleCP());
+ if (pWide == NULL)
{
- return NULL;
+ return false;
}
- char* pConsole = ConvertFromWideString(pMulti, CP_UTF8);
- delete [] pMulti;
- return pConsole;
+ char* pConsole = ConvertFromWideString(pWide, CP_UTF8);
+ delete [] pWide;
+
+ if (!pConsole)
+ {
+ return false;
+ }
+
+ rDest = pConsole;
+ delete [] pConsole;
+
+ return true;
}
Modified: box/chris/win32/vc2005-compile-fixes/lib/win32/emu.h
===================================================================
--- box/chris/win32/vc2005-compile-fixes/lib/win32/emu.h 2006-02-12 15:07:25 UTC (rev 446)
+++ box/chris/win32/vc2005-compile-fixes/lib/win32/emu.h 2006-02-12 16:02:42 UTC (rev 447)
@@ -194,7 +194,7 @@
extern int optind;
extern char nextchar;
-inline int getopt(int count, char * const * args, char * tolookfor)
+inline int getopt(int count, char * const * args, const char * tolookfor)
{
if (optind >= count) return -1;
@@ -466,10 +466,8 @@
int poll(struct pollfd *ufds, unsigned long nfds, int timeout);
bool EnableBackupRights( void );
-// caller must free the returned buffer with delete[]
-char* ConvertUtf8ToConsole(const char* pString);
-char* ConvertConsoleToUtf8(const char* pString);
-char* ConvertFromWideString(const WCHAR* pString, unsigned int DestCodepage);
+bool ConvertUtf8ToConsole(const char* pString, std::string& rDest);
+bool ConvertConsoleToUtf8(const char* pString, std::string& rDest);
//
// MessageId: MSG_ERR_EXIST