From 14e7017ab6366f088aa3b2dba794847bb22a16d4 Mon Sep 17 00:00:00 2001 From: weidai Date: Sat, 11 Jul 2009 22:50:18 +0000 Subject: improve Unicode filename handling git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@473 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- misc.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'misc.h') diff --git a/misc.h b/misc.h index e8b8013..ac1cbda 100644 --- a/misc.h +++ b/misc.h @@ -548,13 +548,20 @@ inline void SecureWipeArray(T *buf, size_t n) } // this function uses wcstombs(), which assumes that setlocale() has been called -static std::string StringNarrow(const wchar_t *str) +static std::string StringNarrow(const wchar_t *str, bool throwOnError = true) { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4996) // 'wcstombs': This function or variable may be unsafe. #endif size_t size = wcstombs(NULL, str, 0); + if (size == -1) + { + if (throwOnError) + throw InvalidArgument("StringNarrow: wcstombs() call failed"); + else + return std::string(); + } std::string result(size, 0); wcstombs(&result[0], str, size); return result; -- cgit v1.2.1