diff options
author | George Hazan <george.hazan@gmail.com> | 2013-03-17 09:53:39 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-03-17 09:53:39 +0000 |
commit | f2d8ababda905068528b340345c74e7f56f6e364 (patch) | |
tree | 62c40545a74832622ee1f7edef7faaa4ff118a3d /src/mir_core | |
parent | bb18d3cc1394e374f3a064ef7eadf9fed5af35de (diff) |
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
Diffstat (limited to 'src/mir_core')
-rw-r--r-- | src/mir_core/memory.cpp | 35 | ||||
-rw-r--r-- | src/mir_core/mir_core.def | 1 |
2 files changed, 24 insertions, 12 deletions
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
|