]> arthur.barton.de Git - netatalk.git/commitdiff
check for BSD strlcpy/strlcat functions, with an implementation from samba
authordidg <didg>
Sat, 14 Feb 2004 00:23:20 +0000 (00:23 +0000)
committerdidg <didg>
Sat, 14 Feb 2004 00:23:20 +0000 (00:23 +0000)
configure.in
libatalk/util/Makefile.am
libatalk/util/strlcpy.c [new file with mode: 0644]

index 4167bbe5cfb2e758f0fd491c93759f2d0df240f7..cbc1845d93fdeeb37f263ecd09c5e929ed17ef18 100644 (file)
@@ -1,4 +1,4 @@
-dnl $Id: configure.in,v 1.179.2.3.2.17 2004-02-07 19:46:07 didg Exp $
+dnl $Id: configure.in,v 1.179.2.3.2.18 2004-02-14 00:23:20 didg Exp $
 dnl configure.in for netatalk
 
 AC_INIT(etc/afpd/main.c)
@@ -118,6 +118,7 @@ AC_FUNC_SETPGRP
 AC_CHECK_FUNCS(backtrace_symbols)
 AC_CHECK_FUNCS(setlocale nl_langinfo)
 AC_CHECK_FUNCS(dlopen dlclose dlsym dlerror waitpid getcwd strdup strndup strnlen strtoul strerror chown fchown chmod fchmod chroot link mknod mknod64)
+AC_CHECK_FUNCS(strlcpy strlcat)
 AC_CACHE_SAVE
 
 
index 0b241b9b69c821380f2159acd5290843affe6c7c..c8991b7f42ffb560f00c8b445417462129a1f45e 100644 (file)
@@ -15,6 +15,7 @@ libutil_la_SOURCES = \
        server_lock.c   \
        strcasestr.c    \
        strdicasecmp.c  \
+       strlcpy.c       \
        fault.c
 
 #      util_unicode.c
diff --git a/libatalk/util/strlcpy.c b/libatalk/util/strlcpy.c
new file mode 100644 (file)
index 0000000..a0a5976
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+   Copy from samba lib/replace.c
+
+   Unix SMB/CIFS implementation.
+   replacement routines for broken systems
+   Copyright (C) Andrew Tridgell 1992-1998
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+   strlcpy strlcat functions.
+*/
+                          
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <atalk/util.h>
+#include <string.h>
+
+#ifndef HAVE_STRLCPY
+/* like strncpy but does not 0 fill the buffer and always null
+   terminates. bufsize is the size of the destination buffer */
+ size_t strlcpy(char *d, const char *s, size_t bufsize)
+{
+        size_t len = strlen(s);
+        size_t ret = len;
+
+        if (bufsize <= 0) 
+               return 0;
+
+        if (len >= bufsize) 
+               len = bufsize-1;
+
+        memcpy(d, s, len);
+        d[len] = 0;
+        return ret;
+}
+#endif
+#ifndef HAVE_STRLCAT
+/* like strncat but does not 0 fill the buffer and always null
+   terminates. bufsize is the length of the buffer, which should
+   be one more than the maximum resulting string length */
+ size_t strlcat(char *d, const char *s, size_t bufsize)
+{
+        size_t len1 = strlen(d);
+        size_t len2 = strlen(s);
+        size_t ret = len1 + len2;
+        if (len1+len2 >= bufsize) {
+                len2 = bufsize - (len1+1);
+        }
+        if (len2 > 0) {
+                memcpy(d+len1, s, len2);
+                d[len1+len2] = 0;
+        }
+        return ret;
+}
+#endif