Author: mturk
Date: Thu Apr  9 18:52:46 2009
New Revision: 763767

URL: http://svn.apache.org/viewvc?rev=763767&view=rev
Log:
Add shared string utils

Added:
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/acr.h

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=763767&r1=763766&r2=763767&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Thu Apr  9 
18:52:46 2009
@@ -65,7 +65,8 @@
        
 COMMON_OBJS=\
        $(SRCDIR)/shared/dbb.$(OBJ) \
-       $(SRCDIR)/shared/error.$(OBJ)
+       $(SRCDIR)/shared/error.$(OBJ) \
+       $(SRCDIR)/shared/string.$(OBJ)
 
 LINUX_OBJS= \
        $(SRCDIR)/os/unix/main.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=763767&r1=763766&r2=763767&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Apr  9 
18:52:46 2009
@@ -59,7 +59,8 @@
 
 COMMON_OBJS=\
        $(SRCDIR)/shared/dbb.$(OBJ) \
-       $(SRCDIR)/shared/error.$(OBJ)
+       $(SRCDIR)/shared/error.$(OBJ) \
+       $(SRCDIR)/shared/string.$(OBJ)
 
 WINDOWS_OBJS= \
        $(SRCDIR)/os/win32/main.res \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=763767&r1=763766&r2=763767&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Thu Apr  9 18:52:46 
2009
@@ -296,7 +296,7 @@
         varadds cxxopts "/TP"
         varadds ldflags "kernel32.lib advapi32.lib ws2_32.lib mswsock.lib"
         varadds ldflags "ole32.lib shell32.lib rpcrt4.lib user32.lib gdi32.lib"
-        varadds ldflags "psapi.lib shlwapi.lib wldap32.lib netapi32.lib 
iphlpapi.lib
+        varadds ldflags "psapi.lib shlwapi.lib wldap32.lib netapi32.lib 
iphlpapi.lib"
         varadds shflags "/NOLOGO /OPT:REF"
         so=".dll"
         exe=".exe"
@@ -445,8 +445,8 @@
 
 #define CC_SIZEOF_INT         `test_csizeof int`
 #define CC_SIZEOF_LONG        `test_csizeof long`
-#define CC_SIZEOF_LONG_LONG   `test_csizeof 'long long'`
-#define CC_SIZEOF_VOIDP       `test_csizeof 'void *'`
+#define CC_SIZEOF_LONG_LONG   `test_csizeof "long long"`
+#define CC_SIZEOF_VOIDP       `test_csizeof "void *"`
 #define CC_SIZEOF_SIZE_T      `test_csizeof size_t`
 #define CC_SIZEOF_OFF64_T     `test_csizeof off64_t`
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=763767&r1=763766&r2=763767&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Thu Apr  9 
18:52:46 2009
@@ -80,17 +80,17 @@
 
 #endif /* HAVE_WINDOWS_H */
 
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stddef.h>
-
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 #if HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
 #endif
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stddef.h>
+
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif

Added: 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=763767&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Thu Apr  9 
18:52:46 2009
@@ -0,0 +1,137 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+
+/*
+ * Apache's "replacement" for the strncpy() function. We roll our
+ * own to implement these specific changes:
+ *   (1) strncpy() doesn't always null terminate and we want it to.
+ *   (2) strncpy() null fills, which is bogus, esp. when copy 8byte
+ *       strings into 8k blocks.
+ *   (3) Instead of returning the pointer to the beginning of
+ *       the destination string, we return a pointer to the
+ *       terminating '\0' to allow us to "check" for truncation
+ *
+ * ACR_CopyStrn() follows the same call structure as strncpy().
+ */
+
+ACR_DECLARE(char *) ACR_CopyStrn(char *dst, const char *src, acr_size_t dsize)
+{
+
+    char *d, *end;
+
+    if (dsize == 0) {
+        return dst;
+    }
+
+    d = dst;
+    end = dst + dsize - 1;
+
+    for (; d < end; ++d, ++src) {
+        if (!(*d = *src)) {
+            return d;
+        }
+    }
+
+    *d = '\0';    /* always null terminate */
+    return d;
+}
+
+/* Filepath_name_get returns the final element of the pathname.
+ * Using the current platform's filename syntax.
+ *   "/foo/bar/gum" -> "gum"
+ *   "/foo/bar/gum/" -> ""
+ *   "gum" -> "gum"
+ *   "wi\\n32\\stuff" -> "stuff
+ *
+ * Corrected Win32 to accept "a/b\\stuff", "a:stuff"
+ */
+ACR_DECLARE(const char *) ACR_FilepathNameGet(const char *pathname)
+{
+    const char path_separator = '/';
+    const char *s = strrchr(pathname, path_separator);
+
+#ifdef WIN32
+    const char path_separator_win = '\\';
+    const char drive_separator_win = ':';
+    const char *s2 = strrchr(pathname, path_separator_win);
+
+    if (s2 > s)
+        s = s2;
+    if (!s)
+        s = strrchr(pathname, drive_separator_win);
+#endif
+
+    return s ? ++s : pathname;
+}
+
+ACR_DECLARE(char *) ACR_Itoa(jint n)
+{
+    const int BUFFER_SIZE = sizeof(jint) * 3 + 2;
+    char *start;
+    int negative;
+    char *buf = malloc(BUFFER_SIZE);
+
+    if (!buf)
+        return NULL;
+    start = buf + BUFFER_SIZE - 1;
+    if (n < 0) {
+        negative = 1;
+        n = -n;
+    }
+    else {
+        negative = 0;
+    }
+    *start = 0;
+    do {
+        *--start = (char)('0' + (n % 10));
+        n /= 10;
+    } while (n);
+    if (negative) {
+        *--start = '-';
+    }
+    return start;
+}
+
+ACR_DECLARE(char *) ACR_Ltoa(jlong n)
+{
+    const int BUFFER_SIZE = sizeof(jlong) * 3 + 2;
+    char *start;
+    int negative;
+    char *buf = malloc(BUFFER_SIZE);
+
+    if (!buf)
+        return NULL;
+    start = buf + BUFFER_SIZE - 1;
+    if (n < 0) {
+        negative = 1;
+        n = -n;
+    }
+    else {
+        negative = 0;
+    }
+    *start = 0;
+    do {
+        *--start = (char)('0' + (n % 10));
+        n /= 10;
+    } while (n);
+    if (negative) {
+        *--start = '-';
+    }
+    return start;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to