]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
check if the system has strndup, if not, compensate
authorTobias Oetiker <tobi@oetiker.ch>
Fri, 9 Jan 2015 13:25:38 +0000 (14:25 +0100)
committerTobias Oetiker <tobi@oetiker.ch>
Fri, 9 Jan 2015 13:25:38 +0000 (14:25 +0100)
configure
configure.ac
src/rrd_client.c
src/rrd_create.c

index 1e06e8f805b483c28972ab9953bc30fe1fa8e6a7..45a9a9d64e98bafe610bb243fa6ae3d0b1b98b13 100755 (executable)
--- a/configure
+++ b/configure
@@ -14725,7 +14725,7 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
 
 
 
-for ac_func in nl_langinfo tzset fsync mbstowcs opendir readdir chdir chroot getgid getuid setgid setuid strerror snprintf vsnprintf vasprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday getpwnam getgrnam
+for ac_func in nl_langinfo tzset fsync mbstowcs opendir readdir chdir chroot getgid getuid setgid setuid strndup strerror snprintf vsnprintf vasprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday getpwnam getgrnam
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
index a44e77a8c87eed72208d6e480eabd459af6d9dd6..17771889a17726adc7b21a52c8f0dba352ccf37e 100644 (file)
@@ -250,7 +250,7 @@ AC_C_BIGENDIAN
 dnl for each function found we get a definition in config.h 
 dnl of the form HAVE_FUNCTION
 
-AC_CHECK_FUNCS(nl_langinfo tzset fsync mbstowcs opendir readdir chdir chroot getgid getuid setgid setuid strerror snprintf vsnprintf vasprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday getpwnam getgrnam)
+AC_CHECK_FUNCS(nl_langinfo tzset fsync mbstowcs opendir readdir chdir chroot getgid getuid setgid setuid strndup strerror snprintf vsnprintf vasprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday getpwnam getgrnam)
 
 AC_FUNC_STRERROR_R
 
index c20489b5945b1d543e20fccef03b2adb02ad740a..4f102394a44970bcb19a85895d8d79cec040b894 100644 (file)
@@ -111,8 +111,11 @@ static const char *get_path (const char *path, char *resolved_path) /* {{{ */
         char *lastslash = strrchr(path, '/');
         
         char *dir = (lastslash == NULL || lastslash == path) ? strdup(".") 
+#ifdef HAVE_STRNDUP
                 : strndup(path, lastslash - path);
-        
+#else
+                : strdup(path);
+#endif
         if (dir != NULL) {
             ret = realpath(dir, buffer);
             free(dir);
index 1c52229d49babe46d1f11986a56d798395b009be..50ff122a41e6aa919c27cc719985c08da3683c88 100644 (file)
@@ -250,6 +250,44 @@ done:
     return rc;
 }
 
+#ifndef HAVE_STRNDUP
+/* Implement the strndup function.
+   Copyright (C) 2005 Free Software Foundation, Inc.
+   Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>. 
+
+This function is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+static char* strndup (const char *s, size_t n) {
+  char *result;
+  size_t len = strlen (s);
+
+  if (n < len)
+    len = n;
+
+  result = (char *) malloc (len + 1);
+  if (!result)
+    return 0;
+
+  result[len] = '\0';
+  return (char *) memcpy (result, s, len);
+}
+
+#endif
+
 //                           1                  2                    3               4                5
 static const char *DS_RE = "^(" DS_NAM_RE ")(?:=(" DS_NAM_RE ")(?:\\[([0-9]+)\\])?)?:(" DST_FMT_RE "):(.+)$";
 /*
@@ -336,6 +374,7 @@ int parseDS(const char *def,
     s2=ovector[DST_ARGS_SUBGROUP*2];
     e2=ovector[DST_ARGS_SUBGROUP*2+1];
 #endif        
+
     dst_tmp  = strndup(def + s, e - s);
     dst_args = strndup(def + s2, e2 - s2);