commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r834066 - /commons/sandbox/runtime/trunk/src/main/native/shared/string.c
Date Mon, 09 Nov 2009 13:58:59 GMT
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)
 {



Mime
View raw message