tried to clean strdup() mess: we now have wxStrdup[AW] which should be always available
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18172 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
#include "wx/wxchar.h"
|
#include "wx/wxchar.h"
|
||||||
|
|
||||||
#include <string.h> // strdup
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Special classes for (wide) character strings: they use malloc/free instead
|
// Special classes for (wide) character strings: they use malloc/free instead
|
||||||
// of new/delete
|
// of new/delete
|
||||||
@@ -95,32 +93,11 @@ private: \
|
|||||||
chartype *m_str; \
|
chartype *m_str; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef strdup
|
DEFINE_BUFFER(wxCharBuffer, char, wxStrdupA);
|
||||||
inline char *strdup(const char *cs)
|
|
||||||
{
|
|
||||||
size_t len = 0;
|
|
||||||
while (cs[len] != 0)
|
|
||||||
len++;
|
|
||||||
const size_t siz = (len + 1)*sizeof(char);
|
|
||||||
char *csCopy = (char *)malloc(siz);
|
|
||||||
memcpy(csCopy, cs, siz);
|
|
||||||
return csCopy;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DEFINE_BUFFER(wxCharBuffer, char, strdup);
|
|
||||||
|
|
||||||
#if wxUSE_WCHAR_T
|
#if wxUSE_WCHAR_T
|
||||||
|
|
||||||
inline wchar_t *wxWcsdupReplacement(const wchar_t *wcs)
|
DEFINE_BUFFER(wxWCharBuffer, wchar_t, wxStrdupW);
|
||||||
{
|
|
||||||
const size_t siz = (wxWcslen(wcs) + 1)*sizeof(wchar_t);
|
|
||||||
wchar_t *wcsCopy = (wchar_t *)malloc(siz);
|
|
||||||
memcpy(wcsCopy, wcs, siz);
|
|
||||||
return wcsCopy;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFINE_BUFFER(wxWCharBuffer, wchar_t, wxWcsdupReplacement);
|
|
||||||
|
|
||||||
#endif // wxUSE_WCHAR_T
|
#endif // wxUSE_WCHAR_T
|
||||||
|
|
||||||
|
@@ -80,6 +80,13 @@
|
|||||||
// Required for wxPrintf() etc
|
// Required for wxPrintf() etc
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
// Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac
|
||||||
|
// and VC++ for Windows CE don't provide it
|
||||||
|
#if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
|
||||||
|
// use #define, not inline wrapper, as it is tested with #ifndef below
|
||||||
|
#define wxStrdupA strdup
|
||||||
|
#endif
|
||||||
|
|
||||||
// non Unix compilers which do have wchar.h (but not tchar.h which is included
|
// non Unix compilers which do have wchar.h (but not tchar.h which is included
|
||||||
// below and which includes wchar.h anyhow).
|
// below and which includes wchar.h anyhow).
|
||||||
// Actually MinGW has tchar.h, but it does not include wchar.h
|
// Actually MinGW has tchar.h, but it does not include wchar.h
|
||||||
@@ -269,7 +276,7 @@
|
|||||||
#define wxStrcoll _tcscoll
|
#define wxStrcoll _tcscoll
|
||||||
#define wxStrcpy _tcscpy
|
#define wxStrcpy _tcscpy
|
||||||
#define wxStrcspn _tcscspn
|
#define wxStrcspn _tcscspn
|
||||||
#define wxStrdup _tcsdup
|
#define wxStrdupW _wcsdup // notice the 'W'!
|
||||||
#define wxStrftime _tcsftime
|
#define wxStrftime _tcsftime
|
||||||
#define wxStricmp _tcsicmp
|
#define wxStricmp _tcsicmp
|
||||||
#define wxStrnicmp _tcsnicmp
|
#define wxStrnicmp _tcsnicmp
|
||||||
@@ -459,9 +466,7 @@
|
|||||||
#define wxStrcoll strcoll
|
#define wxStrcoll strcoll
|
||||||
#define wxStrcpy strcpy
|
#define wxStrcpy strcpy
|
||||||
#define wxStrcspn strcspn
|
#define wxStrcspn strcspn
|
||||||
#if !defined(__MWERKS__) || !defined(__WXMAC__)
|
|
||||||
#define wxStrdup strdup
|
|
||||||
#endif
|
|
||||||
// wxStricmp and wxStrnicmp are defined below
|
// wxStricmp and wxStrnicmp are defined below
|
||||||
#define wxStrlen_ strlen // used in wxStrlen inline function
|
#define wxStrlen_ strlen // used in wxStrlen inline function
|
||||||
#define wxStrncat strncat
|
#define wxStrncat strncat
|
||||||
@@ -572,6 +577,17 @@ inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
|
|||||||
// safe version of strlen() (returns 0 if passed NULL pointer)
|
// safe version of strlen() (returns 0 if passed NULL pointer)
|
||||||
inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
|
inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
|
||||||
|
|
||||||
|
// each of strdup() and wcsdup() may or may not be available but we need both
|
||||||
|
// of them anyhow for wx/buffer.h so we define the missing one(s) in
|
||||||
|
// wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
|
||||||
|
// defined -- if this is somehow not the case in some situations, please
|
||||||
|
// correct that and not the lines here
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
#define wxStrdup wxStrdupW
|
||||||
|
#else
|
||||||
|
#define wxStrdup wxStrdupA
|
||||||
|
#endif
|
||||||
|
|
||||||
WXDLLEXPORT bool wxOKlibc(); // for internal use
|
WXDLLEXPORT bool wxOKlibc(); // for internal use
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -736,8 +752,12 @@ WXDLLEXPORT bool wxOKlibc(); // for internal use
|
|||||||
WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
|
WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
|
||||||
#endif // wxNEED_WX_STRING_H
|
#endif // wxNEED_WX_STRING_H
|
||||||
|
|
||||||
#ifndef wxStrdup
|
#ifndef wxStrdupA
|
||||||
WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
|
WXDLLEXPORT char *wxStrdupA(const char *psz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef wxStrdupW
|
||||||
|
WXDLLEXPORT wchar_t *wxStrdupW(const wchar_t *pwz);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef wxStricmp
|
#ifndef wxStricmp
|
||||||
|
@@ -964,15 +964,26 @@ WXDLLEXPORT int wxTolower(wxChar ch) { return (wxChar)CharLower((LPTSTR)(ch)); }
|
|||||||
WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)CharUpper((LPTSTR)(ch)); }
|
WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)CharUpper((LPTSTR)(ch)); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef wxStrdup
|
#ifndef wxStrdupA
|
||||||
WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz)
|
|
||||||
|
WXDLLEXPORT char *wxStrdupA(const char *s)
|
||||||
{
|
{
|
||||||
size_t size = (wxStrlen(psz) + 1) * sizeof(wxChar);
|
return strcpy((char *)malloc(strlen(s) + 1), s);
|
||||||
wxChar *ret = (wxChar *) malloc(size);
|
}
|
||||||
memcpy(ret, psz, size);
|
|
||||||
|
#endif // wxStrdupA
|
||||||
|
|
||||||
|
#ifndef wxStrdupW
|
||||||
|
|
||||||
|
WXDLLEXPORT wchar_t * wxStrdupW(const wchar_t *pwz)
|
||||||
|
{
|
||||||
|
size_t size = (wxWcslen(pwz) + 1) * sizeof(wchar_t);
|
||||||
|
wchar_t *ret = (wchar_t *) malloc(size);
|
||||||
|
memcpy(ret, pwz, size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // wxStrdupW
|
||||||
|
|
||||||
#ifndef wxStricmp
|
#ifndef wxStricmp
|
||||||
int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
|
int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
|
||||||
|
Reference in New Issue
Block a user