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 --- bin10/lib/mir_core.lib | Bin 31562 -> 32090 bytes bin10/lib/mir_core64.lib | Bin 28820 -> 29332 bytes bin11/lib/mir_core.lib | Bin 31562 -> 32090 bytes bin11/lib/mir_core64.lib | Bin 28820 -> 29332 bytes copylib.cmd | 5 +++++ include/delphi/m_core.inc | 2 ++ include/m_core.h | 2 ++ src/mir_core/memory.cpp | 35 +++++++++++++++++++++++------------ src/mir_core/mir_core.def | 1 + 9 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 copylib.cmd diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib index 2eb78c467b..168b57782f 100644 Binary files a/bin10/lib/mir_core.lib and b/bin10/lib/mir_core.lib differ diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib index e02d6a9c3e..e2ddd40a35 100644 Binary files a/bin10/lib/mir_core64.lib and b/bin10/lib/mir_core64.lib differ diff --git a/bin11/lib/mir_core.lib b/bin11/lib/mir_core.lib index ab60239c88..a47fbce589 100644 Binary files a/bin11/lib/mir_core.lib and b/bin11/lib/mir_core.lib differ diff --git a/bin11/lib/mir_core64.lib b/bin11/lib/mir_core64.lib index d8cf47f751..99eb113b38 100644 Binary files a/bin11/lib/mir_core64.lib and b/bin11/lib/mir_core64.lib differ diff --git a/copylib.cmd b/copylib.cmd new file mode 100644 index 0000000000..6cd462b85c --- /dev/null +++ b/copylib.cmd @@ -0,0 +1,5 @@ +@echo off +copy /Y .\Bin10\Debug\Obj\mir_core\mir_core.lib .\Bin10\lib +copy /Y .\Bin10\Debug64\Obj\mir_core\mir_core64.lib .\Bin10\lib +copy /Y .\Bin11\Debug\Obj\mir_core\mir_core.lib .\Bin11\lib +copy /Y .\Bin11\Debug64\Obj\mir_core\mir_core64.lib .\Bin11\lib \ No newline at end of file diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc index fb7d7034ba..fe6c08de9d 100644 --- a/include/delphi/m_core.inc +++ b/include/delphi/m_core.inc @@ -414,6 +414,8 @@ function mir_wstrdup(const src:PWideChar):PWideChar; stdcall; external CoreDLL name 'mir_wstrdup'; function mir_strndup(const src:PAnsiChar; len:size_t):PAnsiChar; stdcall; external CoreDLL name 'mir_strndup'; +function mir_wstrndup(const src:PWideChar; len:size_t):PWideChar; stdcall; + external CoreDLL name 'mir_wstrndup'; /////////////////////////////////////////////////////////////////////////////// diff --git a/include/m_core.h b/include/m_core.h index 220289995e..6baf15d32e 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -346,7 +346,9 @@ MIR_C_CORE_DLL(void) mir_free(void* ptr); MIR_CORE_DLL(char*) mir_strdup(const char* str); MIR_CORE_DLL(WCHAR*) mir_wstrdup(const WCHAR* str); + MIR_CORE_DLL(char*) mir_strndup(const char* str, size_t len); +MIR_CORE_DLL(WCHAR*) mir_wstrndup(const WCHAR *str, size_t len); /////////////////////////////////////////////////////////////////////////////// // modules 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