define our own strndup() when its not available (thanks to Pippijn for the idea)
authorBrenden Matthews <brenden1@rty.ca>
Wed, 2 Apr 2008 19:46:09 +0000 (19:46 +0000)
committerBrenden Matthews <brenden1@rty.ca>
Wed, 2 Apr 2008 19:46:09 +0000 (19:46 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1101 7f574dfc-610e-0410-a909-a81674777703

configure.ac.in
src/common.c
src/conky.h

index 8b0ea41..f4f2f4f 100644 (file)
@@ -470,7 +470,7 @@ dnl
 dnl Some functions
 dnl
 
-AC_CHECK_FUNCS([calloc malloc free popen sysinfo getloadavg memrchr])
+AC_CHECK_FUNCS([calloc malloc free popen sysinfo getloadavg memrchr strndup])
 AC_SEARCH_LIBS(clock_gettime, [rt],
                [AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if you have clock_gettime()])],
                [AC_CHECK_FUNCS([gettimeofday], [], [AC_MSG_ERROR([gettimeofday() not available!])])], [])
index 921998a..240de43 100644 (file)
 #include <sys/time.h>
 #include <pthread.h>
 
+#ifndef HAVE_STRNDUP
+// use our own strndup() if it's not available
+char *strndup(const char *s, size_t n)
+{
+       if (strlen(s) + 1 > n) {
+               char *ret = malloc(n);
+               strncpy(ret, s, n);
+               return ret;
+       } else {
+               return strdup(s);
+       }
+}
+#endif /* HAVE_STRNDUP */
+
 void update_uname(void)
 {
        uname(&info.uname_s);
index 305f411..47d229f 100644 (file)
 #include <machine/apmvar.h>
 #endif /* __OpenBSD__ */
 
+#ifndef HAVE_STRNDUP
+// use our own strndup() if it's not available
+char *strndup(const char *s, size_t n);
+#endif /* HAVE_STRNDUP */
+
 #ifdef AUDACIOUS
 #include "audacious.h"
 #endif