diff --git a/configure.ac.in b/configure.ac.in index 8b0ea411..f4f2f4f7 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -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!])])], []) diff --git a/src/common.c b/src/common.c index 921998aa..240de431 100644 --- a/src/common.c +++ b/src/common.c @@ -34,6 +34,20 @@ #include #include +#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); diff --git a/src/conky.h b/src/conky.h index 305f411b..47d229f3 100644 --- a/src/conky.h +++ b/src/conky.h @@ -64,6 +64,11 @@ #include #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