]> sjero.net Git - wget/blob - m4/getline.m4
Automaetd merge.
[wget] / m4 / getline.m4
1 # getline.m4 serial 18
2
3 dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007 Free
4 dnl Software 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.59])
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([gl_FUNC_GETLINE],
17 [
18   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
19
20   dnl Persuade glibc <stdio.h> to declare getline().
21   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
22
23   AC_CHECK_DECLS_ONCE([getline])
24
25   gl_getline_needs_run_time_check=no
26   AC_CHECK_FUNC(getline,
27                 dnl Found it in some library.  Verify that it works.
28                 gl_getline_needs_run_time_check=yes,
29                 am_cv_func_working_getline=no)
30   if test $gl_getline_needs_run_time_check = yes; then
31     AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline,
32     [echo fooN |tr -d '\012'|tr N '\012' > conftest.data
33     AC_TRY_RUN([
34 #    include <stdio.h>
35 #    include <stdlib.h>
36 #    include <string.h>
37     int main ()
38     { /* Based on a test program from Karl Heuer.  */
39       char *line = NULL;
40       size_t siz = 0;
41       int len;
42       FILE *in = fopen ("./conftest.data", "r");
43       if (!in)
44         return 1;
45       len = getline (&line, &siz, in);
46       exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1);
47     }
48     ], am_cv_func_working_getline=yes dnl The library version works.
49     , am_cv_func_working_getline=no dnl The library version does NOT work.
50     , dnl We're cross compiling. Assume it works on glibc2 systems.
51       [AC_EGREP_CPP([Lucky GNU user],
52          [
53 #include <features.h>
54 #ifdef __GNU_LIBRARY__
55  #if (__GLIBC__ >= 2)
56   Lucky GNU user
57  #endif
58 #endif
59          ],
60          [am_cv_func_working_getline=yes],
61          [am_cv_func_working_getline=no])]
62     )])
63   fi
64
65   if test $ac_cv_have_decl_getline = no; then
66     HAVE_DECL_GETLINE=0
67   fi
68
69   if test $am_cv_func_working_getline = no; then
70     REPLACE_GETLINE=1
71     AC_LIBOBJ([getline])
72
73     gl_PREREQ_GETLINE
74   fi
75 ])
76
77 # Prerequisites of lib/getline.c.
78 AC_DEFUN([gl_PREREQ_GETLINE],
79 [
80   gl_FUNC_GETDELIM
81 ])