Skip to content

Commit

Permalink
Add local getline() for Solaris 10 build
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed May 3, 2012
1 parent 7761041 commit c623380
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions compat.c
Expand Up @@ -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
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -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])
Expand Down
4 changes: 4 additions & 0 deletions openconnect-internal.h
Expand Up @@ -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

/****************************************************************************/

Expand Down

0 comments on commit c623380

Please sign in to comment.