[pacman-dev] [PATCH 2/5] common: Avoid errors on systems that define strnlen but not strndup
Will Miles
wmiles at sgl.com
Thu Feb 26 22:04:10 UTC 2015
Add a configure test for a system library supplied strnlen, and disable
the embedded version in common if one is found.
Signed-off-by: Will Miles <wmiles at sgl.com>
---
configure.ac | 4 ++--
src/common/util-common.c | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 735fdc3..359d61b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -304,8 +304,8 @@ AC_FUNC_MKTIME
AC_FUNC_STRCOLL
AC_CHECK_FUNCS([dup2 getcwd getmntinfo gettimeofday memmove memset \
mkdir realpath regcomp rmdir setenv setlocale strcasecmp \
- strchr strcspn strdup strerror strndup strrchr strsep strstr \
- strtol swprintf tcflush wcwidth uname])
+ strchr strcspn strdup strerror strndup strnlen strrchr \
+ strsep strstr strtol swprintf tcflush wcwidth uname])
AC_CHECK_MEMBERS([struct stat.st_blksize],,,[[#include <sys/stat.h>]])
# For the diskspace code
diff --git a/src/common/util-common.c b/src/common/util-common.c
index f5b00f1..e834168 100644
--- a/src/common/util-common.c
+++ b/src/common/util-common.c
@@ -127,7 +127,7 @@ char *safe_fgets(char *s, int size, FILE *stream)
return ret;
}
-#ifndef HAVE_STRNDUP
+#ifndef HAVE_STRNLEN
/* A quick and dirty implementation derived from glibc */
/** Determines the length of a fixed-size string.
* @param s string to be measured
@@ -140,7 +140,9 @@ static size_t strnlen(const char *s, size_t max)
for(p = s; *p && max--; ++p);
return (p - s);
}
+#endif
+#ifndef HAVE_STRNDUP
/** Copies a string.
* Returned string needs to be freed
* @param s string to be copied
--
2.3.0
More information about the pacman-dev
mailing list