Commit c4e0ed39 authored by David Woodhouse's avatar David Woodhouse

Add strndup() compat function for OSX

The comment in connect_https_socket() suggests that I didn't use strndup()
there because Solaris lacks it. I blithely went ahead and used it in the
NTLM code though, and Solaris 11 *does* seem to have it. (My Solaris 10 VM
no longer boots, and I can't bring myself to care.)

But OSX (10.6.8 Snow Leopard) also seems to lack strndup(). So add a
compat implementation of it rather than just trying to remember not to
use it.
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent a4df343b
......@@ -165,6 +165,23 @@ char *openconnect__strcasestr(const char *haystack, const char *needle)
}
#endif
#ifndef HAVE_STRNDUP
char *openconnect__strndup(const char *s, size_t n)
{
char *r;
if (n > strlen(s))
n = strlen(s);
r = malloc(n + 1);
if (r) {
memcpy(r, s, n);
r[n] = 0;
}
return r;
}
#endif
#ifndef HAVE_SETENV
int openconnect__setenv(const char *name, const char *value, int overwrite)
{
......
......@@ -105,6 +105,7 @@ AC_CHECK_FUNC(fdevname_r, [AC_DEFINE(HAVE_FDEVNAME_R, 1, [Have fdevname_r() func
AC_CHECK_FUNC(getline, [AC_DEFINE(HAVE_GETLINE, 1, [Have getline() function])],
[symver_getline="openconnect__getline;"])
AC_CHECK_FUNC(strcasestr, [AC_DEFINE(HAVE_STRCASESTR, 1, [Have strcasestr() function])], [])
AC_CHECK_FUNC(strndup, [AC_DEFINE(HAVE_STRNDUP, 1, [Have strndup() function])], [])
AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1, [Have asprintf() function])], [])
if test -n "$symver_asprintf"; then
AC_MSG_CHECKING([for va_copy])
......
......@@ -444,6 +444,11 @@ ssize_t openconnect__getline(char **lineptr, size_t *n, FILE *stream);
#define strcasestr openconnect__strcasestr
char *openconnect__strcasestr(const char *haystack, const char *needle);
#endif
#ifndef HAVE_STRNDUP
#undef strndup
#define strndup openconnect__strndup
char *openconnect__strndup(const char *s, size_t n);
#endif
#ifndef HAVE_SETENV
#define setenv openconnect__setenv
int openconnect__setenv(const char *name, const char *value, int overwrite);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment