1 # getdelim.m4 serial 14
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; }
47 /* Test result for a NULL buffer and a non-zero size.
48 This crashes on FreeBSD 8.0. */
50 size_t siz = (size_t)(~0) / 4;
51 if (getdelim (&line, &siz, '\n', in) == -1)
52 { fclose (in); return 3; }
59 [gl_cv_func_working_getdelim=yes],
60 [gl_cv_func_working_getdelim=no],
61 [dnl We're cross compiling.
62 dnl Guess it works on glibc2 systems and musl systems.
63 AC_EGREP_CPP([Lucky GNU user],
66 #ifdef __GNU_LIBRARY__
67 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
72 [gl_cv_func_working_getdelim="guessing yes"],
74 *-musl*) gl_cv_func_working_getdelim="guessing yes" ;;
75 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
80 case "$gl_cv_func_working_getdelim" in
82 *) REPLACE_GETDELIM=1 ;;
88 if test $ac_cv_have_decl_getdelim = no; then
93 # Prerequisites of lib/getdelim.c.
94 AC_DEFUN([gl_PREREQ_GETDELIM],
96 AC_CHECK_FUNCS([flockfile funlockfile])
97 AC_CHECK_DECLS([getc_unlocked])