[Box Backup-dev] COMMIT r438 - box/chris/win32/vc2005-compile-fixes/lib/win32
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Sun Feb 12 13:13:15 GMT 2006
Author: chris
Date: 2006-02-12 13:13:12 +0000 (Sun, 12 Feb 2006)
New Revision: 438
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
- Added a new function, console_read, to replace _cgetws without requiring
a newer version of the M$ runtime library
Modified: box/chris/win32/vc2005-compile-fixes/lib/win32/emu.cpp
===================================================================
--- box/chris/win32/vc2005-compile-fixes/lib/win32/emu.cpp 2006-02-12 13:12:28 UTC (rev 437)
+++ box/chris/win32/vc2005-compile-fixes/lib/win32/emu.cpp 2006-02-12 13:13:12 UTC (rev 438)
@@ -1162,4 +1162,48 @@
return 0;
}
+int console_read(char* pBuffer, size_t BufferSize)
+{
+ HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
+
+ if (hConsole == INVALID_HANDLE_VALUE)
+ {
+ ::fprintf(stderr, "Failed to get a handle on standard input: "
+ "error %d\n", GetLastError());
+ return -1;
+ }
+
+ int WideSize = BufferSize / 5;
+ WCHAR* pWideBuffer = new WCHAR [WideSize];
+
+ if (!pWideBuffer)
+ {
+ ::perror("Failed to allocate wide character buffer");
+ return -1;
+ }
+
+ DWORD numCharsRead = 0;
+
+ if (!ReadConsoleW(
+ hConsole,
+ pWideBuffer,
+ WideSize - 1,
+ &numCharsRead,
+ NULL // reserved
+ ))
+ {
+ ::fprintf(stderr, "Failed to read from console: error %d\n",
+ GetLastError());
+ return -1;
+ }
+
+ pWideBuffer[numCharsRead] = 0;
+
+ char* pUtf8 = ConvertFromWideString(pWideBuffer, GetConsoleCP());
+ strncpy(pBuffer, pUtf8, BufferSize);
+ delete [] pUtf8;
+
+ return strlen(pBuffer);
+}
+
#endif // WIN32
Modified: box/chris/win32/vc2005-compile-fixes/lib/win32/emu.h
===================================================================
--- box/chris/win32/vc2005-compile-fixes/lib/win32/emu.h 2006-02-12 13:12:28 UTC (rev 437)
+++ box/chris/win32/vc2005-compile-fixes/lib/win32/emu.h 2006-02-12 13:13:12 UTC (rev 438)
@@ -478,8 +478,7 @@
//
#define MSG_ERR_EXIST ((DWORD)0xC0000004L)
-#ifdef __MINGW32__
- extern "C" { _CRTIMP wchar_t* __cdecl _cgetws (wchar_t *); }
-#endif
+// replacement for _cgetws which requires a relatively recent C runtime lib
+int console_read(char* pBuffer, size_t BufferSize);
#endif // !EMU_INCLUDE && WIN32
More information about the Boxbackup-dev
mailing list