Implement getline() in terms of fgetln() if we have it.

This commit is contained in:
Todd C. Miller
2009-09-18 12:23:01 +00:00
parent 89fa08f7e6
commit f17c6df8e2
4 changed files with 33 additions and 1 deletions

View File

@@ -110,6 +110,9 @@
/* Define to 1 if your system has the F_CLOSEM fcntl. */
#undef HAVE_FCNTL_CLOSEM
/* Define to 1 if you have the `fgetln' function. */
#undef HAVE_FGETLN
/* Define to 1 if you have the `flock' function. */
#undef HAVE_FLOCK

2
configure vendored
View File

@@ -15828,11 +15828,13 @@ LIBS=$ac_save_LIBS
for ac_func in dup2 strchr strrchr memchr memcpy memset sysconf tzset getline \
strftime setrlimit initgroups getgroups fstat gettimeofday \
regcomp setlocale getaddrinfo setsid setenv vhangup nanosleep
fgetln
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5

View File

@@ -1836,7 +1836,8 @@ dnl
AC_FUNC_GETGROUPS
AC_CHECK_FUNCS(dup2 strchr strrchr memchr memcpy memset sysconf tzset getline \
strftime setrlimit initgroups getgroups fstat gettimeofday \
regcomp setlocale getaddrinfo setsid setenv vhangup nanosleep)
regcomp setlocale getaddrinfo setsid setenv vhangup nanosleep
fgetln)
AC_CHECK_FUNCS(openpty, [AC_CHECK_HEADERS(util.h pty.h, [break])], [
AC_CHECK_LIB(util, openpty, [
AC_CHECK_HEADERS(util.h pty.h, [break])

View File

@@ -42,6 +42,31 @@
extern void *erealloc __P((void *, size_t));
#ifdef HAVE_FGETLN
ssize_t
getline(bufp, bufsizep, fp)
char **bufp;
size_t *bufsizep;
FILE *fp;
{
char *buf;
size_t bufsize;
size_t len;
buf = fgetln(fp, &len);
if (buf) {
bufsize = *bufp ? *bufsizep : 0;
if (bufsize < len + 1) {
bufsize = len + 1;
*bufp = erealloc(*bufp, bufsize);
*bufsizep = bufsize;
}
memcpy(*bufp, buf, len);
(*bufp)[len] = '\0';
}
return(buf ? len : -1);
}
#else
ssize_t
getline(bufp, bufsizep, fp)
char **bufp;
@@ -74,3 +99,4 @@ getline(bufp, bufsizep, fp)
*bufsizep = bufsize;
return(len);
}
#endif