From f2d8ababda905068528b340345c74e7f56f6e364 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 17 Mar 2013 09:53:39 +0000 Subject: mir_wstrndup added, the Unicode version of mir_strndup git-svn-id: http://svn.miranda-ng.org/main/trunk@4066 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/memory.cpp | 35 +++++++++++++++++++++++------------ src/mir_core/mir_core.def | 1 + 2 files changed, 24 insertions(+), 12 deletions(-) (limited to 'src/mir_core') diff --git a/src/mir_core/memory.cpp b/src/mir_core/memory.cpp index 0ed432a610..b8bf481aad 100644 --- a/src/mir_core/memory.cpp +++ b/src/mir_core/memory.cpp @@ -142,10 +142,10 @@ MIR_C_CORE_DLL(void) mir_free(void* ptr) /******************************************************************************/ -MIR_CORE_DLL(char*) mir_strdup(const char* str) +MIR_CORE_DLL(char*) mir_strdup(const char *str) { if (str != NULL) { - char* p = (char*)mir_alloc(strlen(str)+1); + char *p = (char*)mir_alloc(strlen(str)+1); if (p) strcpy(p, str); return p; @@ -153,13 +153,24 @@ MIR_CORE_DLL(char*) mir_strdup(const char* str) return NULL; } +MIR_CORE_DLL(WCHAR*) mir_wstrdup(const WCHAR *str) +{ + if (str != NULL) { + WCHAR *p = (WCHAR*)mir_alloc(sizeof(WCHAR)*(wcslen(str)+1)); + if (p) + wcscpy(p, str); + return p; + } + return NULL; +} + /******************************************************************************/ -MIR_CORE_DLL(char*) mir_strndup(const char* str, size_t len) +MIR_CORE_DLL(char*) mir_strndup(const char *str, size_t len) { if (str != NULL && len != 0) { - char* p = (char*)mir_alloc(len + 1); - if ( !p) { + char *p = (char*)mir_alloc(len+1); + if (p) { memcpy(p, str, len); p[ len ] = 0; } @@ -168,14 +179,14 @@ MIR_CORE_DLL(char*) mir_strndup(const char* str, size_t len) return NULL; } -/******************************************************************************/ - -MIR_CORE_DLL(WCHAR*) mir_wstrdup(const WCHAR* str) +MIR_CORE_DLL(WCHAR*) mir_wstrndup(const WCHAR *str, size_t len) { - if (str != NULL) { - WCHAR* p = (WCHAR*)mir_alloc(sizeof(WCHAR)*(wcslen(str)+1)); - if (p) - wcscpy(p, str); + if (str != NULL && len != 0) { + WCHAR *p = (WCHAR*)mir_alloc(sizeof(WCHAR)*(len+1)); + if (p) { + memcpy(p, str, sizeof(WCHAR)*len); + p[ len ] = 0; + } return p; } return NULL; diff --git a/src/mir_core/mir_core.def b/src/mir_core/mir_core.def index a5978b9ddb..c124c559e5 100644 --- a/src/mir_core/mir_core.def +++ b/src/mir_core/mir_core.def @@ -139,3 +139,4 @@ Icon_RegisterT @136 mir_subclassWindow @137 mir_callNextSubclass @138 KillModuleSubclassing @139 +mir_wstrndup @140 -- cgit v1.2.3