1 # getdelim.m4 serial 15
3 dnl Copyright (C) 2005-2007, 2009-2020 Free Software Foundation, Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
11 AC_DEFUN([gl_FUNC_GETDELIM],
13 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
14 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
16 dnl Persuade glibc <stdio.h> to declare getdelim().
17 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
19 AC_CHECK_DECLS_ONCE([getdelim])
21 AC_CHECK_FUNCS_ONCE([getdelim])
22 if test $ac_cv_func_getdelim = yes; then
24 dnl Found it in some library. Verify that it works.
25 AC_CACHE_CHECK([for working getdelim function],
26 [gl_cv_func_working_getdelim],
27 [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
28 AC_RUN_IFELSE([AC_LANG_SOURCE([[
34 FILE *in = fopen ("./conftest.data", "r");
38 /* Test result for a NULL buffer and a zero size.
39 Based on a test program from Karl Heuer. */
42 int len = getdelim (&line, &siz, '\n', in);
43 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
44 { free (line); fclose (in); return 2; }
48 /* Test result for a NULL buffer and a non-zero size.
49 This crashes on FreeBSD 8.0. */
51 size_t siz = (size_t)(~0) / 4;
52 if (getdelim (&line, &siz, '\n', in) == -1)
53 { fclose (in); return 3; }
60 [gl_cv_func_working_getdelim=yes],
61 [gl_cv_func_working_getdelim=no],
62 [dnl We're cross compiling.
63 dnl Guess it works on glibc2 systems and musl systems.
64 AC_EGREP_CPP([Lucky GNU user],
67 #ifdef __GNU_LIBRARY__
68 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
73 [gl_cv_func_working_getdelim="guessing yes"],
75 *-musl*) gl_cv_func_working_getdelim="guessing yes" ;;
76 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
81 case "$gl_cv_func_working_getdelim" in
83 *) REPLACE_GETDELIM=1 ;;
89 if test $ac_cv_have_decl_getdelim = no; then
94 # Prerequisites of lib/getdelim.c.
95 AC_DEFUN([gl_PREREQ_GETDELIM],
97 AC_CHECK_FUNCS([flockfile funlockfile])
98 AC_CHECK_DECLS([getc_unlocked])