update COPYING.DOC to fdl version 1.2.
[gnulib.git] / m4 / getline.m4
1 # getline.m4 serial 7
2 dnl Copyright (C) 1998-2002 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License.  As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 AC_PREREQ(2.52)
10
11 dnl See if there's a working, system-supplied version of the getline function.
12 dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems
13 dnl have a function by that name in -linet that doesn't have anything
14 dnl to do with the function we need.
15 AC_DEFUN([AM_FUNC_GETLINE],
16 [
17   dnl Persuade glibc <stdio.h> to declare getline() and getdelim().
18   AC_REQUIRE([AC_GNU_SOURCE])
19
20   am_getline_needs_run_time_check=no
21   AC_CHECK_FUNC(getline,
22                 dnl Found it in some library.  Verify that it works.
23                 am_getline_needs_run_time_check=yes,
24                 am_cv_func_working_getline=no)
25   if test $am_getline_needs_run_time_check = yes; then
26     AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline,
27     [echo fooN |tr -d '\012'|tr N '\012' > conftest.data
28     AC_TRY_RUN([
29 #    include <stdio.h>
30 #    include <stdlib.h>
31 #    include <string.h>
32     int main ()
33     { /* Based on a test program from Karl Heuer.  */
34       char *line = NULL;
35       size_t siz = 0;
36       int len;
37       FILE *in = fopen ("./conftest.data", "r");
38       if (!in)
39         return 1;
40       len = getline (&line, &siz, in);
41       exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1);
42     }
43     ], am_cv_func_working_getline=yes dnl The library version works.
44     , am_cv_func_working_getline=no dnl The library version does NOT work.
45     , am_cv_func_working_getline=no dnl We're cross compiling.
46     )])
47   fi
48
49   if test $am_cv_func_working_getline = no; then
50     dnl We must choose a different name for our function, since on ELF systems
51     dnl a broken getline() in libc.so would override our getline() in
52     dnl libgettextlib.so.
53     AC_DEFINE([getline], [gnu_getline],
54       [Define to a replacement function name for getline().])
55     AC_LIBOBJ(getline)
56     gl_PREREQ_GETLINE
57   fi
58 ])
59
60 # Prerequisites of lib/getline.c.
61 AC_DEFUN([gl_PREREQ_GETLINE],
62 [
63   AC_CHECK_FUNCS(getdelim)
64 ])