2N/A# getline.m4 serial 21
2N/A
2N/Adnl Copyright (C) 1998-2003, 2005-2007, 2009-2010 Free Software Foundation,
2N/Adnl Inc.
2N/Adnl
2N/Adnl This file is free software; the Free Software Foundation
2N/Adnl gives unlimited permission to copy and/or distribute it,
2N/Adnl with or without modifications, as long as this notice is preserved.
2N/A
2N/AAC_PREREQ([2.59])
2N/A
2N/Adnl See if there's a working, system-supplied version of the getline function.
2N/Adnl We can't just do AC_REPLACE_FUNCS([getline]) because some systems
2N/Adnl have a function by that name in -linet that doesn't have anything
2N/Adnl to do with the function we need.
2N/AAC_DEFUN([gl_FUNC_GETLINE],
2N/A[
2N/A AC_REQUIRE([gl_STDIO_H_DEFAULTS])
2N/A
2N/A dnl Persuade glibc <stdio.h> to declare getline().
2N/A AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
2N/A
2N/A AC_CHECK_DECLS_ONCE([getline])
2N/A
2N/A gl_getline_needs_run_time_check=no
2N/A AC_CHECK_FUNC([getline],
2N/A [dnl Found it in some library. Verify that it works.
2N/A gl_getline_needs_run_time_check=yes],
2N/A [am_cv_func_working_getline=no])
2N/A if test $gl_getline_needs_run_time_check = yes; then
2N/A AC_CACHE_CHECK([for working getline function], [am_cv_func_working_getline],
2N/A [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
2N/A AC_RUN_IFELSE([AC_LANG_SOURCE([[
2N/A# include <stdio.h>
2N/A# include <stdlib.h>
2N/A# include <string.h>
2N/A int main ()
2N/A {
2N/A FILE *in = fopen ("./conftest.data", "r");
2N/A if (!in)
2N/A return 1;
2N/A {
2N/A /* Test result for a NULL buffer and a zero size.
2N/A Based on a test program from Karl Heuer. */
2N/A char *line = NULL;
2N/A size_t siz = 0;
2N/A int len = getline (&line, &siz, in);
2N/A if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
2N/A return 1;
2N/A }
2N/A {
2N/A /* Test result for a NULL buffer and a non-zero size.
2N/A This crashes on FreeBSD 8.0. */
2N/A char *line = NULL;
2N/A size_t siz = (size_t)(~0) / 4;
2N/A if (getline (&line, &siz, in) == -1)
2N/A return 1;
2N/A }
2N/A return 0;
2N/A }
2N/A ]])], [am_cv_func_working_getline=yes] dnl The library version works.
2N/A , [am_cv_func_working_getline=no] dnl The library version does NOT work.
2N/A , dnl We're cross compiling. Assume it works on glibc2 systems.
2N/A [AC_EGREP_CPP([Lucky GNU user],
2N/A [
2N/A#include <features.h>
2N/A#ifdef __GNU_LIBRARY__
2N/A #if (__GLIBC__ >= 2)
2N/A Lucky GNU user
2N/A #endif
2N/A#endif
2N/A ],
2N/A [am_cv_func_working_getline=yes],
2N/A [am_cv_func_working_getline=no])]
2N/A )])
2N/A fi
2N/A
2N/A if test $ac_cv_have_decl_getline = no; then
2N/A HAVE_DECL_GETLINE=0
2N/A fi
2N/A
2N/A if test $am_cv_func_working_getline = no; then
2N/A dnl Set REPLACE_GETLINE always: Even if we have not found the broken
2N/A dnl getline function among $LIBS, it may exist in libinet and the
2N/A dnl executable may be linked with -linet.
2N/A REPLACE_GETLINE=1
2N/A AC_LIBOBJ([getline])
2N/A
2N/A gl_PREREQ_GETLINE
2N/A fi
2N/A])
2N/A
2N/A# Prerequisites of lib/getline.c.
2N/AAC_DEFUN([gl_PREREQ_GETLINE],
2N/A[
2N/A gl_FUNC_GETDELIM
2N/A])