Add local getline() for Solaris 10 build
authorDavid Woodhouse <David.Woodhouse@intel.com>
Thu, 3 May 2012 14:41:49 +0000 (15:41 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Thu, 3 May 2012 14:43:54 +0000 (15:43 +0100)
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
compat.c
configure.ac
openconnect-internal.h

index f10a292..537f68d 100644 (file)
--- 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
index 2bcde70..5860fb0 100644 (file)
@@ -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])
index e9d2ce7..eda3e9c 100644 (file)
@@ -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
 
 /****************************************************************************/