annotate m4/getline.m4 @ 40158:383f7a766b7c

test-framework-sh: Improve maintainability. * tests/init.sh: Clarify what belongs together. Reorder definitions.
author Bruno Haible <bruno@clisp.org>
date Sun, 27 Jan 2019 16:55:27 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18935
ec3c62e83a8b Avoid wrong configure results with gcc -fsanitize=address.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
1 # getline.m4 serial 28
4166
053cd474cdc5 (gl_PREREQ_GETLINE): Require AC_HEADER_STDC.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4108
diff changeset
2
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
3 dnl Copyright (C) 1998-2003, 2005-2007, 2009-2019 Free Software Foundation,
12559
c2cbabec01dd update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents: 12421
diff changeset
4 dnl Inc.
5611
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4809
diff changeset
5 dnl
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4809
diff changeset
6 dnl This file is free software; the Free Software Foundation
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4809
diff changeset
7 dnl gives unlimited permission to copy and/or distribute it,
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4809
diff changeset
8 dnl with or without modifications, as long as this notice is preserved.
4108
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
9
9511
740cd2f7aaa1 Let these macros work also with autoconf-2.59.
Jim Meyering <meyering@redhat.com>
parents: 9209
diff changeset
10 AC_PREREQ([2.59])
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
12 dnl See if there's a working, system-supplied version of the getline function.
11007
f6cba5a556ce many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents: 9511
diff changeset
13 dnl We can't just do AC_REPLACE_FUNCS([getline]) because some systems
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
14 dnl have a function by that name in -linet that doesn't have anything
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
15 dnl to do with the function we need.
6011
cf3d0bf4fc6f 2005-08-02 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents: 5721
diff changeset
16 AC_DEFUN([gl_FUNC_GETLINE],
4108
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
17 [
9161
c5cedfcd0db0 Move getline and getdelim into stdio.h, per POSIX 200x.
Eric Blake <ebb9@byu.net>
parents: 7180
diff changeset
18 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
c5cedfcd0db0 Move getline and getdelim into stdio.h, per POSIX 200x.
Eric Blake <ebb9@byu.net>
parents: 7180
diff changeset
19
6011
cf3d0bf4fc6f 2005-08-02 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents: 5721
diff changeset
20 dnl Persuade glibc <stdio.h> to declare getline().
9209
5a0294ce5372 Track CVS Autoconf on AC_USE_SYSTEM_EXTENSIONS.
Eric Blake <ebb9@byu.net>
parents: 9164
diff changeset
21 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
4108
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
22
9164
e945561759a5 Getline touchups.
Eric Blake <ebb9@byu.net>
parents: 9161
diff changeset
23 AC_CHECK_DECLS_ONCE([getline])
6011
cf3d0bf4fc6f 2005-08-02 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents: 5721
diff changeset
24
cf3d0bf4fc6f 2005-08-02 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents: 5721
diff changeset
25 gl_getline_needs_run_time_check=no
11007
f6cba5a556ce many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents: 9511
diff changeset
26 AC_CHECK_FUNC([getline],
12837
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
27 [dnl Found it in some library. Verify that it works.
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
28 gl_getline_needs_run_time_check=yes],
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
29 [am_cv_func_working_getline=no])
6011
cf3d0bf4fc6f 2005-08-02 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents: 5721
diff changeset
30 if test $gl_getline_needs_run_time_check = yes; then
11007
f6cba5a556ce many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents: 9511
diff changeset
31 AC_CACHE_CHECK([for working getline function], [am_cv_func_working_getline],
12837
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
32 [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
11987
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 11007
diff changeset
33 AC_RUN_IFELSE([AC_LANG_SOURCE([[
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
34 # include <stdio.h>
4108
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
35 # include <stdlib.h>
3314
0cbeff087afe (AM_FUNC_GETLINE): Quote first arg of AC_DEFUN.
Jim Meyering <jim@meyering.net>
parents: 2685
diff changeset
36 # include <string.h>
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
37 int main ()
12837
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
38 {
1912
14abc42d2378 Rename test file from conftestdata to conftest.data
Jim Meyering <jim@meyering.net>
parents: 1702
diff changeset
39 FILE *in = fopen ("./conftest.data", "r");
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
40 if (!in)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
41 return 1;
12837
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
42 {
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
43 /* Test result for a NULL buffer and a zero size.
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
44 Based on a test program from Karl Heuer. */
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
45 char *line = NULL;
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
46 size_t siz = 0;
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
47 int len = getline (&line, &siz, in);
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
48 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
18935
ec3c62e83a8b Avoid wrong configure results with gcc -fsanitize=address.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
49 { free (line); fclose (in); return 2; }
18240
8f47f3e77c8e misc: port better to gcc -fsanitize=address
Paul Eggert <eggert@cs.ucla.edu>
parents: 18189
diff changeset
50 free (line);
12837
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
51 }
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
52 {
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
53 /* Test result for a NULL buffer and a non-zero size.
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
54 This crashes on FreeBSD 8.0. */
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
55 char *line = NULL;
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
56 size_t siz = (size_t)(~0) / 4;
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
57 if (getline (&line, &siz, in) == -1)
18935
ec3c62e83a8b Avoid wrong configure results with gcc -fsanitize=address.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
58 { fclose (in); return 3; }
18240
8f47f3e77c8e misc: port better to gcc -fsanitize=address
Paul Eggert <eggert@cs.ucla.edu>
parents: 18189
diff changeset
59 free (line);
12837
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
60 }
18240
8f47f3e77c8e misc: port better to gcc -fsanitize=address
Paul Eggert <eggert@cs.ucla.edu>
parents: 18189
diff changeset
61 fclose (in);
12837
fff2b96bad5e Work around getline() bug on FreeBSD 8.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
62 return 0;
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
63 }
11987
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 11007
diff changeset
64 ]])], [am_cv_func_working_getline=yes] dnl The library version works.
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 11007
diff changeset
65 , [am_cv_func_working_getline=no] dnl The library version does NOT work.
7016
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
66 , dnl We're cross compiling. Assume it works on glibc2 systems.
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
67 [AC_EGREP_CPP([Lucky GNU user],
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
68 [
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
69 #include <features.h>
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
70 #ifdef __GNU_LIBRARY__
13885
87a95303747f Port to uClibc.
Bruno Haible <bruno@clisp.org>
parents: 12840
diff changeset
71 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
7016
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
72 Lucky GNU user
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
73 #endif
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
74 #endif
518e17651b9d Avoid causing trouble in relocatable.c.
Bruno Haible <bruno@clisp.org>
parents: 6011
diff changeset
75 ],
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
76 [am_cv_func_working_getline="guessing yes"],
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
77 [am_cv_func_working_getline="guessing no"])]
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
78 )])
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
79 fi
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
80
9164
e945561759a5 Getline touchups.
Eric Blake <ebb9@byu.net>
parents: 9161
diff changeset
81 if test $ac_cv_have_decl_getline = no; then
9161
c5cedfcd0db0 Move getline and getdelim into stdio.h, per POSIX 200x.
Eric Blake <ebb9@byu.net>
parents: 7180
diff changeset
82 HAVE_DECL_GETLINE=0
c5cedfcd0db0 Move getline and getdelim into stdio.h, per POSIX 200x.
Eric Blake <ebb9@byu.net>
parents: 7180
diff changeset
83 fi
c5cedfcd0db0 Move getline and getdelim into stdio.h, per POSIX 200x.
Eric Blake <ebb9@byu.net>
parents: 7180
diff changeset
84
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
85 case "$am_cv_func_working_getline" in
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
86 *no)
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
87 dnl Set REPLACE_GETLINE always: Even if we have not found the broken
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
88 dnl getline function among $LIBS, it may exist in libinet and the
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
89 dnl executable may be linked with -linet.
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
90 REPLACE_GETLINE=1
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
91 ;;
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
92 esac
820
7d99d39333e1 broken out of ../acinclude.m4
Jim Meyering <jim@meyering.net>
parents:
diff changeset
93 ])
4108
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
94
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
95 # Prerequisites of lib/getline.c.
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
96 AC_DEFUN([gl_PREREQ_GETLINE],
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
97 [
14958
0f9adf6a2b9e getline: Simplify.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
98 :
4108
c1d472db5c30 An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents: 3314
diff changeset
99 ])