From: Tobias Oetiker Date: Fri, 9 Jan 2015 13:25:38 +0000 (+0100) Subject: check if the system has strndup, if not, compensate X-Git-Tag: v1.5.0-rc2~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e216fa9b1610f8ab406a421fc1cdbbbf97d57094;p=thirdparty%2Frrdtool-1.x.git check if the system has strndup, if not, compensate --- diff --git a/configure b/configure index 1e06e8f8..45a9a9d6 100755 --- 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" diff --git a/configure.ac b/configure.ac index a44e77a8..17771889 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/rrd_client.c b/src/rrd_client.c index c20489b5..4f102394 100644 --- a/src/rrd_client.c +++ b/src/rrd_client.c @@ -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); diff --git a/src/rrd_create.c b/src/rrd_create.c index 1c52229d..50ff122a 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -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 . + +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);