Use an all-permissive copyright notice, recommended by RMS.
[gnulib.git] / m4 / getline.m4
1 # getline.m4 serial 11
2
3 dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
4 dnl Foundation, Inc.
5 dnl
6 dnl This file is free software; the Free Software Foundation
7 dnl gives unlimited permission to copy and/or distribute it,
8 dnl with or without modifications, as long as this notice is preserved.
9
10 AC_PREREQ(2.52)
11
12 dnl See if there's a working, system-supplied version of the getline function.
13 dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems
14 dnl have a function by that name in -linet that doesn't have anything
15 dnl to do with the function we need.
16 AC_DEFUN([AM_FUNC_GETLINE],
17 [
18   dnl Persuade glibc <stdio.h> to declare getline() and getdelim().
19   AC_REQUIRE([AC_GNU_SOURCE])
20
21   am_getline_needs_run_time_check=no
22   AC_CHECK_FUNC(getline,
23                 dnl Found it in some library.  Verify that it works.
24                 am_getline_needs_run_time_check=yes,
25                 am_cv_func_working_getline=no)
26   if test $am_getline_needs_run_time_check = yes; then
27     AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline,
28     [echo fooN |tr -d '\012'|tr N '\012' > conftest.data
29     AC_TRY_RUN([
30 #    include <stdio.h>
31 #    include <stdlib.h>
32 #    include <string.h>
33     int main ()
34     { /* Based on a test program from Karl Heuer.  */
35       char *line = NULL;
36       size_t siz = 0;
37       int len;
38       FILE *in = fopen ("./conftest.data", "r");
39       if (!in)
40         return 1;
41       len = getline (&line, &siz, in);
42       exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1);
43     }
44     ], am_cv_func_working_getline=yes dnl The library version works.
45     , am_cv_func_working_getline=no dnl The library version does NOT work.
46     , am_cv_func_working_getline=no dnl We're cross compiling.
47     )])
48   fi
49
50   if test $am_cv_func_working_getline = no; then
51     dnl We must choose a different name for our function, since on ELF systems
52     dnl a broken getline() in libc.so would override our getline() in
53     dnl libgettextlib.so.
54     AC_DEFINE([getline], [gnu_getline],
55       [Define to a replacement function name for getline().])
56     AC_LIBOBJ(getline)
57
58     # Avoid multiple inclusions of getndelim2.o into LIBOBJS.
59     # This hack won't be needed after gnulib requires Autoconf 2.58 or later.
60     case " $LIB@&t@OBJS " in
61     *" getndelim2.$ac_objext "* ) ;;
62     *) AC_LIBOBJ(getndelim2);;
63     esac
64
65     gl_PREREQ_GETLINE
66     gl_PREREQ_GETNDELIM2
67   fi
68 ])
69
70 # Prerequisites of lib/getline.c.
71 AC_DEFUN([gl_PREREQ_GETLINE],
72 [
73   AC_CHECK_FUNCS(getdelim)
74 ])