From: Ove Kaaven Date: Sat, 10 Apr 1999 14:15:15 +0000 (+0000) Subject: Added wxStrdup(). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/639a9fb5d7875cf34ddda6169e2401b396403ace?hp=f362b96d6701d2da187c13a1b34a2e71c1cbb90c Added wxStrdup(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2084 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/wxchar.h b/include/wx/wxchar.h index 7f1c3e5cc4..fda15454f2 100644 --- a/include/wx/wxchar.h +++ b/include/wx/wxchar.h @@ -277,7 +277,7 @@ typedef unsigned char wxUChar; inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; } /// safe version of strlen() (returns 0 if passed NULL pointer) -inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz) +inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz) #if defined(__VISUALC__) { return psz ? _tcslen(psz) : 0; } #elif wxUSE_UNICODE @@ -323,5 +323,18 @@ inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2) #error "Please define string case-insensitive compare for your OS/compiler" #endif // OS/compiler +/// portable strdup +inline wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz) +#if !wxUSE_UNICODE + { return strdup(psz); } +#else + { + size_t size = (wxStrlen(psz) + 1) * sizeof(wxChar); + wxChar *ret = (wxChar *) malloc(size); + memcpy(ret, psz, size); + return ret; + } +#endif + #endif //_WX_WXCHAR_H_