private strndup() implementation in case libc does not provide it
This commit is contained in:
parent
086cf3a272
commit
6ac5a82eec
|
@ -188,7 +188,7 @@ AC_CHECK_FUNCS([ \
|
||||||
# Optional functions
|
# Optional functions
|
||||||
AC_CHECK_FUNCS_ONCE([ \
|
AC_CHECK_FUNCS_ONCE([ \
|
||||||
gai_strerror getaddrinfo getnameinfo inet_aton sigaction sigprocmask \
|
gai_strerror getaddrinfo getnameinfo inet_aton sigaction sigprocmask \
|
||||||
snprintf vsnprintf strdup strlcpy strlcat strtok_r waitpid])
|
snprintf vsnprintf strdup strndup strlcpy strlcat strtok_r waitpid])
|
||||||
|
|
||||||
# -- Configuration options --
|
# -- Configuration options --
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ EXTRA_DIST = Makefile.ng
|
||||||
|
|
||||||
noinst_LIBRARIES = libngportab.a
|
noinst_LIBRARIES = libngportab.a
|
||||||
|
|
||||||
libngportab_a_SOURCES = strdup.c strlcpy.c strtok_r.c vsnprintf.c waitpid.c
|
libngportab_a_SOURCES = strdup.c strndup.c strlcpy.c strtok_r.c vsnprintf.c waitpid.c
|
||||||
|
|
||||||
check_PROGRAMS = portabtest
|
check_PROGRAMS = portabtest
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,10 @@ extern size_t strlcpy PARAMS(( char *dst, const char *src, size_t size ));
|
||||||
extern char * strdup PARAMS(( const char *s ));
|
extern char * strdup PARAMS(( const char *s ));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRNDUP
|
||||||
|
extern char * strndup PARAMS((const char *s, size_t maxlen));
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_STRTOK_R
|
#ifndef HAVE_STRTOK_R
|
||||||
extern char * strtok_r PARAMS((char *str, const char *delim, char **saveptr));
|
extern char * strtok_r PARAMS((char *str, const char *delim, char **saveptr));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* ngIRCd -- The Next Generation IRC Daemon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "portab.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* strndup() implementation. Public domain.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HAVE_STRNDUP
|
||||||
|
|
||||||
|
#include "imp.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "exp.h"
|
||||||
|
|
||||||
|
GLOBAL char *
|
||||||
|
strndup(const char *s, size_t maxlen)
|
||||||
|
{
|
||||||
|
char *dup;
|
||||||
|
size_t len = strlen(s);
|
||||||
|
|
||||||
|
if (len > maxlen)
|
||||||
|
len = maxlen;
|
||||||
|
len++;
|
||||||
|
dup = malloc(len);
|
||||||
|
if (dup)
|
||||||
|
strlcpy(dup, s, len);
|
||||||
|
return dup;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue