|
Packit Service |
a2ae7a |
# getdelim.m4 serial 13
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
dnl Copyright (C) 2005-2007, 2009-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
dnl
|
|
Packit Service |
a2ae7a |
dnl This file is free software; the Free Software Foundation
|
|
Packit Service |
a2ae7a |
dnl gives unlimited permission to copy and/or distribute it,
|
|
Packit Service |
a2ae7a |
dnl with or without modifications, as long as this notice is preserved.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
AC_PREREQ([2.59])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
AC_DEFUN([gl_FUNC_GETDELIM],
|
|
Packit Service |
a2ae7a |
[
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
dnl Persuade glibc <stdio.h> to declare getdelim().
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
AC_CHECK_DECLS_ONCE([getdelim])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
AC_CHECK_FUNCS_ONCE([getdelim])
|
|
Packit Service |
a2ae7a |
if test $ac_cv_func_getdelim = yes; then
|
|
Packit Service |
a2ae7a |
HAVE_GETDELIM=1
|
|
Packit Service |
a2ae7a |
dnl Found it in some library. Verify that it works.
|
|
Packit Service |
a2ae7a |
AC_CACHE_CHECK([for working getdelim function],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_working_getdelim],
|
|
Packit Service |
a2ae7a |
[echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
|
|
Packit Service |
a2ae7a |
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
|
Packit Service |
a2ae7a |
# include <stdio.h>
|
|
Packit Service |
a2ae7a |
# include <stdlib.h>
|
|
Packit Service |
a2ae7a |
# include <string.h>
|
|
Packit Service |
a2ae7a |
int main ()
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
FILE *in = fopen ("./conftest.data", "r");
|
|
Packit Service |
a2ae7a |
if (!in)
|
|
Packit Service |
a2ae7a |
return 1;
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
/* Test result for a NULL buffer and a zero size.
|
|
Packit Service |
a2ae7a |
Based on a test program from Karl Heuer. */
|
|
Packit Service |
a2ae7a |
char *line = NULL;
|
|
Packit Service |
a2ae7a |
size_t siz = 0;
|
|
Packit Service |
a2ae7a |
int len = getdelim (&line, &siz, '\n', in);
|
|
Packit Service |
a2ae7a |
if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
|
|
Packit Service |
a2ae7a |
{ free (line); fclose (in); return 2; }
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
/* Test result for a NULL buffer and a non-zero size.
|
|
Packit Service |
a2ae7a |
This crashes on FreeBSD 8.0. */
|
|
Packit Service |
a2ae7a |
char *line = NULL;
|
|
Packit Service |
a2ae7a |
size_t siz = (size_t)(~0) / 4;
|
|
Packit Service |
a2ae7a |
if (getdelim (&line, &siz, '\n', in) == -1)
|
|
Packit Service |
a2ae7a |
{ fclose (in); return 3; }
|
|
Packit Service |
a2ae7a |
free (line);
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
fclose (in);
|
|
Packit Service |
a2ae7a |
return 0;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
]])],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_working_getdelim=yes],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_working_getdelim=no],
|
|
Packit Service |
a2ae7a |
[dnl We're cross compiling.
|
|
Packit Service |
a2ae7a |
dnl Guess it works on glibc2 systems and musl systems.
|
|
Packit Service |
a2ae7a |
AC_EGREP_CPP([Lucky GNU user],
|
|
Packit Service |
a2ae7a |
[
|
|
Packit Service |
a2ae7a |
#include <features.h>
|
|
Packit Service |
a2ae7a |
#ifdef __GNU_LIBRARY__
|
|
Packit Service |
a2ae7a |
#if (__GLIBC__ >= 2) && !defined __UCLIBC__
|
|
Packit Service |
a2ae7a |
Lucky GNU user
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_working_getdelim="guessing yes"],
|
|
Packit Service |
a2ae7a |
[case "$host_os" in
|
|
Packit Service |
a2ae7a |
*-musl*) gl_cv_func_working_getdelim="guessing yes" ;;
|
|
Packit Service |
a2ae7a |
*) gl_cv_func_working_getdelim="guessing no" ;;
|
|
Packit Service |
a2ae7a |
esac
|
|
Packit Service |
a2ae7a |
])
|
|
Packit Service |
a2ae7a |
])
|
|
Packit Service |
a2ae7a |
])
|
|
Packit Service |
a2ae7a |
case "$gl_cv_func_working_getdelim" in
|
|
Packit Service |
a2ae7a |
*yes) ;;
|
|
Packit Service |
a2ae7a |
*) REPLACE_GETDELIM=1 ;;
|
|
Packit Service |
a2ae7a |
esac
|
|
Packit Service |
a2ae7a |
else
|
|
Packit Service |
a2ae7a |
HAVE_GETDELIM=0
|
|
Packit Service |
a2ae7a |
fi
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
if test $ac_cv_have_decl_getdelim = no; then
|
|
Packit Service |
a2ae7a |
HAVE_DECL_GETDELIM=0
|
|
Packit Service |
a2ae7a |
fi
|
|
Packit Service |
a2ae7a |
])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
# Prerequisites of lib/getdelim.c.
|
|
Packit Service |
a2ae7a |
AC_DEFUN([gl_PREREQ_GETDELIM],
|
|
Packit Service |
a2ae7a |
[
|
|
Packit Service |
a2ae7a |
AC_CHECK_FUNCS([flockfile funlockfile])
|
|
Packit Service |
a2ae7a |
AC_CHECK_DECLS([getc_unlocked])
|
|
Packit Service |
a2ae7a |
])
|