1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

common: Avoid errors on systems that define strnlen but not strndup

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@sgl.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Will Miles 2015-02-27 14:43:24 -05:00 committed by Allan McRae
parent bb94729c09
commit 965539adbf
2 changed files with 5 additions and 3 deletions

View File

@ -304,8 +304,8 @@ AC_FUNC_MKTIME
AC_FUNC_STRCOLL AC_FUNC_STRCOLL
AC_CHECK_FUNCS([dup2 getcwd getmntinfo gettimeofday memmove memset \ AC_CHECK_FUNCS([dup2 getcwd getmntinfo gettimeofday memmove memset \
mkdir realpath regcomp rmdir setenv setlocale strcasecmp \ mkdir realpath regcomp rmdir setenv setlocale strcasecmp \
strchr strcspn strdup strerror strndup strrchr strsep strstr \ strchr strcspn strdup strerror strndup strnlen strrchr \
strtol swprintf tcflush wcwidth uname]) strsep strstr strtol swprintf tcflush wcwidth uname])
AC_CHECK_MEMBERS([struct stat.st_blksize],,,[[#include <sys/stat.h>]]) AC_CHECK_MEMBERS([struct stat.st_blksize],,,[[#include <sys/stat.h>]])
# For the diskspace code # For the diskspace code

View File

@ -127,7 +127,7 @@ char *safe_fgets(char *s, int size, FILE *stream)
return ret; return ret;
} }
#ifndef HAVE_STRNDUP #ifndef HAVE_STRNLEN
/* A quick and dirty implementation derived from glibc */ /* A quick and dirty implementation derived from glibc */
/** Determines the length of a fixed-size string. /** Determines the length of a fixed-size string.
* @param s string to be measured * @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); for(p = s; *p && max--; ++p);
return (p - s); return (p - s);
} }
#endif
#ifndef HAVE_STRNDUP
/** Copies a string. /** Copies a string.
* Returned string needs to be freed * Returned string needs to be freed
* @param s string to be copied * @param s string to be copied