diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-01-31 14:46:01 +0100 |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-01-31 14:46:01 +0100 |
commit | e8bd88d1fcded01ccd066572eeaae1b507989cb3 (patch) | |
tree | c8e7be6c07c6f635f6e803e6a6ba9e7a95fee7c0 /gl/m4/getline.m4 | |
parent | 2ad962c13473607ca0d974bfaa516a0ed53ec73d (diff) | |
download | monitoring-plugins-e8bd88d1fcded01ccd066572eeaae1b507989cb3.tar.gz |
Sync with the latest Gnulib code 668c0b8ffa
Diffstat (limited to 'gl/m4/getline.m4')
-rw-r--r-- | gl/m4/getline.m4 | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4 new file mode 100644 index 00000000..03569f06 --- /dev/null +++ b/gl/m4/getline.m4 | |||
@@ -0,0 +1,109 @@ | |||
1 | # getline.m4 serial 30 | ||
2 | |||
3 | dnl Copyright (C) 1998-2003, 2005-2007, 2009-2023 Free Software Foundation, | ||
4 | dnl 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 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
20 | |||
21 | dnl Persuade glibc <stdio.h> to declare getline(). | ||
22 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) | ||
23 | |||
24 | AC_CHECK_DECLS_ONCE([getline]) | ||
25 | |||
26 | gl_getline_needs_run_time_check=no | ||
27 | AC_CHECK_FUNC([getline], | ||
28 | [dnl Found it in some library. Verify that it works. | ||
29 | gl_getline_needs_run_time_check=yes], | ||
30 | [am_cv_func_working_getline=no]) | ||
31 | if test $gl_getline_needs_run_time_check = yes; then | ||
32 | AC_CACHE_CHECK([for working getline function], | ||
33 | [am_cv_func_working_getline], | ||
34 | [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data | ||
35 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ | ||
36 | # include <stdio.h> | ||
37 | # include <stdlib.h> | ||
38 | # include <string.h> | ||
39 | int main () | ||
40 | { | ||
41 | FILE *in = fopen ("./conftest.data", "r"); | ||
42 | if (!in) | ||
43 | return 1; | ||
44 | { | ||
45 | /* Test result for a NULL buffer and a zero size. | ||
46 | Based on a test program from Karl Heuer. */ | ||
47 | char *line = NULL; | ||
48 | size_t siz = 0; | ||
49 | int len = getline (&line, &siz, in); | ||
50 | if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) | ||
51 | { free (line); fclose (in); return 2; } | ||
52 | free (line); | ||
53 | } | ||
54 | { | ||
55 | /* Test result for a NULL buffer and a non-zero size. | ||
56 | This crashes on FreeBSD 8.0. */ | ||
57 | char *line = NULL; | ||
58 | size_t siz = (size_t)(~0) / 4; | ||
59 | if (getline (&line, &siz, in) == -1) | ||
60 | { fclose (in); return 3; } | ||
61 | free (line); | ||
62 | } | ||
63 | fclose (in); | ||
64 | return 0; | ||
65 | } | ||
66 | ]])], | ||
67 | [am_cv_func_working_getline=yes], | ||
68 | [am_cv_func_working_getline=no], | ||
69 | [dnl We're cross compiling. | ||
70 | dnl Guess it works on glibc2 systems and musl systems. | ||
71 | AC_EGREP_CPP([Lucky GNU user], | ||
72 | [ | ||
73 | #include <features.h> | ||
74 | #ifdef __GNU_LIBRARY__ | ||
75 | #if (__GLIBC__ >= 2) && !defined __UCLIBC__ | ||
76 | Lucky GNU user | ||
77 | #endif | ||
78 | #endif | ||
79 | ], | ||
80 | [am_cv_func_working_getline="guessing yes"], | ||
81 | [case "$host_os" in | ||
82 | *-musl*) am_cv_func_working_getline="guessing yes" ;; | ||
83 | *) am_cv_func_working_getline="$gl_cross_guess_normal" ;; | ||
84 | esac | ||
85 | ]) | ||
86 | ]) | ||
87 | ]) | ||
88 | fi | ||
89 | |||
90 | if test $ac_cv_have_decl_getline = no; then | ||
91 | HAVE_DECL_GETLINE=0 | ||
92 | fi | ||
93 | |||
94 | case "$am_cv_func_working_getline" in | ||
95 | *yes) ;; | ||
96 | *) | ||
97 | dnl Set REPLACE_GETLINE always: Even if we have not found the broken | ||
98 | dnl getline function among $LIBS, it may exist in libinet and the | ||
99 | dnl executable may be linked with -linet. | ||
100 | REPLACE_GETLINE=1 | ||
101 | ;; | ||
102 | esac | ||
103 | ]) | ||
104 | |||
105 | # Prerequisites of lib/getline.c. | ||
106 | AC_DEFUN([gl_PREREQ_GETLINE], | ||
107 | [ | ||
108 | : | ||
109 | ]) | ||