diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2009-07-11 22:50:18 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2009-07-11 22:50:18 +0000 |
commit | 14e7017ab6366f088aa3b2dba794847bb22a16d4 (patch) | |
tree | 3be29c508762394ff9a52d6077c5edc3c72f16d0 /misc.h | |
parent | 4b53fa6f2956ccf4b0cdb98adeceeaf66b67612b (diff) | |
download | cryptopp-14e7017ab6366f088aa3b2dba794847bb22a16d4.tar.gz |
improve Unicode filename handling
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@473 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'misc.h')
-rw-r--r-- | misc.h | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; |