From c62338082e8115b4abf47af3bd44615884cec023 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 3 May 2012 15:41:49 +0100 Subject: [PATCH] Add local getline() for Solaris 10 build Signed-off-by: David Woodhouse --- compat.c | 29 +++++++++++++++++++++++++++++ configure.ac | 1 + openconnect-internal.h | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/compat.c b/compat.c index f10a292f..537f68db 100644 --- a/compat.c +++ b/compat.c @@ -111,3 +111,32 @@ int openconnect__asprintf(char **strp, const char *fmt, ...) return ret; } #endif + +#ifndef HAVE_GETLINE +ssize_t openconnect__getline(char **lineptr, size_t *n, FILE *stream) +{ + int len = 0; + + if (!*lineptr) { + *n = 2; + *lineptr = malloc(*n); + if (!*lineptr) + return -1; + } + + while (fgets((*lineptr) + len, (*n) - len, stream)) { + + len += strlen((*lineptr) + len); + if ((*lineptr)[len-1] == '\n') + break; + + *n *= 2; + *lineptr = realloc(*lineptr, *n); + if (!*lineptr) + return -1; + } + if (len) + return len; + return -1; +} +#endif diff --git a/configure.ac b/configure.ac index 2bcde700..5860fb09 100644 --- a/configure.ac +++ b/configure.ac @@ -67,6 +67,7 @@ case $host_os in ;; esac +AC_CHECK_FUNC(getline, [AC_DEFINE(HAVE_GETLINE, 1)], []) AC_CHECK_FUNC(strcasestr, [AC_DEFINE(HAVE_STRCASESTR, 1)], []) need_vacopy=no AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1)], [need_vacopy=yes]) diff --git a/openconnect-internal.h b/openconnect-internal.h index e9d2ce7c..eda3e9c1 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -248,6 +248,10 @@ time_t openconnect__time(time_t *t); #define asprintf openconnect__asprintf int openconnect__asprintf(char **strp, const char *fmt, ...); #endif +#ifndef HAVE_GETLINE +#define getline openconnect__getline +ssize_t openconnect__getline(char **lineptr, size_t *n, FILE *stream); +#endif /****************************************************************************/