* m4/Makefile.am: add fnmatchcase.m4 and mbstate_t.m4
[findutils.git] / m4 / getline.m4
blob613152c5a4ec227b2ef08d85788cad61f76847c2
1 #serial 3
3 dnl See if there's a working, system-supplied version of the getline function.
4 dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems
5 dnl have a function by that name in -linet that doesn't have anything
6 dnl to do with the function we need.
7 AC_DEFUN(AM_FUNC_GETLINE,
8 [dnl
9   am_getline_needs_run_time_check=no
10   AC_CHECK_FUNC(getline,
11                 dnl Found it in some library.  Verify that it works.
12                 am_getline_needs_run_time_check=yes,
13                 am_cv_func_working_getline=no)
14   if test $am_getline_needs_run_time_check = yes; then
15     AC_CHECK_HEADERS(string.h)
16     AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline,
17     [echo fooN |tr -d '\012'|tr N '\012' > conftest.data
18     AC_TRY_RUN([
19 #    include <stdio.h>
20 #    include <sys/types.h>
21 #    if HAVE_STRING_H
22 #     include <string.h>
23 #    endif
24     int main ()
25     { /* Based on a test program from Karl Heuer.  */
26       char *line = NULL;
27       size_t siz = 0;
28       int len;
29       FILE *in = fopen ("./conftest.data", "r");
30       if (!in)
31         return 1;
32       len = getline (&line, &siz, in);
33       exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1);
34     }
35     ], am_cv_func_working_getline=yes dnl The library version works.
36     , am_cv_func_working_getline=no dnl The library version does NOT work.
37     , am_cv_func_working_getline=no dnl We're cross compiling.
38     )])
39   fi
41   if test $am_cv_func_working_getline = yes; then
42     AC_DEFINE(HAVE_GETLINE, 1,
43       [Define if you have the GETLINE function.])dnl
44   fi