You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/11/09 14:58:59 UTC

svn commit: r834066 - /commons/sandbox/runtime/trunk/src/main/native/shared/string.c

Author: mturk
Date: Mon Nov  9 13:58:55 2009
New Revision: 834066

URL: http://svn.apache.org/viewvc?rev=834066&view=rev
Log:
Add strdup replacements that use x_malloc

Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=834066&r1=834065&r2=834066&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon Nov  9 13:58:55 2009
@@ -741,6 +741,22 @@
     return s ? ++s : pathname;
 }
 
+ACR_DECLARE(char *) ACR_strdup(const char *s)
+{
+    char *d = NULL;
+    if (s) {
+        size_t size = strlen(s);
+        d = x_malloc(size + 1);
+        if (d) {
+            memcpy(d, s, size);
+            d[size]   = '\0';
+        }
+        else
+            ACR_SET_OS_ERROR(ACR_ENOMEM);
+    }
+    return d;
+}
+
 ACR_DECLARE(char *) ACR_StrdupA(JNIEnv *_E, const char *file, int line,
                                 const char *s)
 {
@@ -756,6 +772,22 @@
     return d;
 }
 
+ACR_DECLARE(wchar_t *) ACR_wcsdup(const wchar_t *s)
+{
+    wchar_t *d = NULL;
+    if (s) {
+        size_t size = wcslen(s);
+        d = x_malloc((size + 1) * sizeof(wchar_t));
+        if (d) {
+            memcpy(d, s, size * sizeof(wchar_t));
+            d[size]   = L'\0';
+        }
+        else
+            ACR_SET_OS_ERROR(ACR_ENOMEM);
+    }
+    return d;
+}
+
 ACR_DECLARE(wchar_t *) ACR_StrdupW(JNIEnv *_E, const char *file, int line,
                                    const wchar_t *s)
 {