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/08/16 08:42:14 UTC
svn commit: r804634 - in /commons/sandbox/runtime/trunk/src/main/native: ./
include/arch/hpux/ include/arch/linux/ include/arch/solaris/
include/arch/windows/ port/
Author: mturk
Date: Sun Aug 16 06:42:14 2009
New Revision: 804634
URL: http://svn.apache.org/viewvc?rev=804634&view=rev
Log:
Add BSD strlcat/strlcpy to the portable layer
Added:
commons/sandbox/runtime/trunk/src/main/native/port/strlcat.c (with props)
commons/sandbox/runtime/trunk/src/main/native/port/strlcpy.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/include/arch/hpux/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.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=804634&r1=804633&r2=804634&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Sun Aug 16 06:42:14 2009
@@ -192,6 +192,8 @@
$(SRCDIR)/os/hpux/os.$(OBJ)
PPORT_OBJS=\
+ $(SRCDIR)/port/strlcat.$(OBJ) \
+ $(SRCDIR)/port/strlcpy.$(OBJ) \
$(SRCDIR)/port/strsignal.$(OBJ)
ZLIB_OBJS=\
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=804634&r1=804633&r2=804634&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sun Aug 16 06:42:14 2009
@@ -114,6 +114,8 @@
$(SRCDIR)/os/win32/wusec.$(OBJ)
PPORT_OBJS=\
+ $(SRCDIR)/port/strlcat.$(OBJ) \
+ $(SRCDIR)/port/strlcpy.$(OBJ) \
$(SRCDIR)/port/strsignal.$(OBJ)
ZLIB_OBJS=\
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h?rev=804634&r1=804633&r2=804634&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h Sun Aug 16 06:42:14 2009
@@ -42,7 +42,11 @@
* Include needed functions from portable layer
*/
#define ACR_WANT_STRSIGNAL 1
-extern char *strsignal(int);
+char *strsignal(int);
+#define ACR_WANT_STRLCAT 1
+size_t strlcat(char *, const char *, size_t);
+#define ACR_WANT_STRLCPY 1
+size_t strlcpy(char *, const char *, size_t);
/**
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h?rev=804634&r1=804633&r2=804634&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h Sun Aug 16 06:42:14 2009
@@ -38,6 +38,14 @@
JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_linux_##CL##_##FN
/**
+ * Include needed functions from portable layer
+ */
+#define ACR_WANT_STRLCAT 1
+size_t strlcat(char *, const char *, size_t);
+#define ACR_WANT_STRLCPY 1
+size_t strlcpy(char *, const char *, size_t);
+
+/**
* Temporary APR flags
*/
#define APR_USE_SHMEM_SHMGET 1
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h?rev=804634&r1=804633&r2=804634&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h Sun Aug 16 06:42:14 2009
@@ -38,6 +38,14 @@
JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_solaris_##CL##_##FN
/**
+ * Include needed functions from portable layer
+ */
+#define ACR_WANT_STRLCAT 1
+size_t strlcat(char *, const char *, size_t);
+#define ACR_WANT_STRLCPY 1
+size_t strlcpy(char *, const char *, size_t);
+
+/**
* Temporary APR flags
*/
#define APR_USE_SHMEM_SHMGET 1
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=804634&r1=804633&r2=804634&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Sun Aug 16 06:42:14 2009
@@ -74,7 +74,11 @@
* Include needed functions from portable layer
*/
#define ACR_WANT_STRSIGNAL 1
-extern char *strsignal(int);
+char *strsignal(int);
+#define ACR_WANT_STRLCAT 1
+size_t strlcat(char *, const char *, size_t);
+#define ACR_WANT_STRLCPY 1
+size_t strlcpy(char *, const char *, size_t);
/**
Added: commons/sandbox/runtime/trunk/src/main/native/port/strlcat.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/port/strlcat.c?rev=804634&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/port/strlcat.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/port/strlcat.c Sun Aug 16 06:42:14 2009
@@ -0,0 +1,79 @@
+/* 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.
+ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <To...@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+
+#if defined(ACR_WANT_STRLCAT)
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+size_t
+strlcat(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return (dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return (dlen + (s - src)); /* count does not include NUL */
+}
+
+#else
+
+UNUSED_SOURCE_FILE(strlcat);
+
+#endif /* ACR_WANT_STRLCAT */
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/port/strlcat.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/port/strlcpy.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/port/strlcpy.c?rev=804634&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/port/strlcpy.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/port/strlcpy.c Sun Aug 16 06:42:14 2009
@@ -0,0 +1,75 @@
+/* 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.
+ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <To...@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+
+#if defined(ACR_WANT_STRLCPY)
+
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+size_t
+strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return (s - src - 1); /* count does not include NUL */
+}
+
+#else
+
+UNUSED_SOURCE_FILE(strlcpy);
+
+#endif /* ACR_WANT_STRLCPY */
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/port/strlcpy.c
------------------------------------------------------------------------------
svn:eol-style = native