From: Todd C. Miller Date: Fri, 18 Sep 2009 12:23:01 +0000 (+0000) Subject: Implement getline() in terms of fgetln() if we have it. X-Git-Tag: SUDO_1_7_3~286 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f17c6df8e223f8d6bb4d9ad5a7ba90b10d20a781;p=sudo Implement getline() in terms of fgetln() if we have it. --- diff --git a/config.h.in b/config.h.in index 97e91aec0..6ea8c3867 100644 --- a/config.h.in +++ b/config.h.in @@ -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 diff --git a/configure b/configure index 74ae61b9c..496ce5eaa 100755 --- a/configure +++ b/configure @@ -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 diff --git a/configure.in b/configure.in index f75780d63..1d554d367 100644 --- a/configure.in +++ b/configure.in @@ -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]) diff --git a/getline.c b/getline.c index 5a9821ec8..607a7162b 100644 --- a/getline.c +++ b/getline.c @@ -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