1 1.1 christos # getline.m4 serial 13 2 1.1 christos 3 1.1 christos dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005 Free Software 4 1.1 christos dnl Foundation, Inc. 5 1.1 christos dnl 6 1.1 christos dnl This file is free software; the Free Software Foundation 7 1.1 christos dnl gives unlimited permission to copy and/or distribute it, 8 1.1 christos dnl with or without modifications, as long as this notice is preserved. 9 1.1 christos 10 1.1 christos AC_PREREQ(2.52) 11 1.1 christos 12 1.1 christos dnl See if there's a working, system-supplied version of the getline function. 13 1.1 christos dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems 14 1.1 christos dnl have a function by that name in -linet that doesn't have anything 15 1.1 christos dnl to do with the function we need. 16 1.1 christos AC_DEFUN([gl_FUNC_GETLINE], 17 1.1 christos [ 18 1.1 christos AC_LIBSOURCES([getline.c, getline.h]) 19 1.1 christos 20 1.1 christos dnl Persuade glibc <stdio.h> to declare getline(). 21 1.1 christos AC_REQUIRE([AC_GNU_SOURCE]) 22 1.1 christos 23 1.1 christos AC_CHECK_DECLS([getline]) 24 1.1 christos 25 1.1 christos gl_getline_needs_run_time_check=no 26 1.1 christos AC_CHECK_FUNC(getline, 27 1.1 christos dnl Found it in some library. Verify that it works. 28 1.1 christos gl_getline_needs_run_time_check=yes, 29 1.1 christos am_cv_func_working_getline=no) 30 1.1 christos if test $gl_getline_needs_run_time_check = yes; then 31 1.1 christos AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline, 32 1.1 christos [echo fooN |tr -d '\012'|tr N '\012' > conftest.data 33 1.1 christos AC_TRY_RUN([ 34 1.1 christos # include <stdio.h> 35 1.1 christos # include <stdlib.h> 36 1.1 christos # include <string.h> 37 1.1 christos int main () 38 1.1 christos { /* Based on a test program from Karl Heuer. */ 39 1.1 christos char *line = NULL; 40 1.1 christos size_t siz = 0; 41 1.1 christos int len; 42 1.1 christos FILE *in = fopen ("./conftest.data", "r"); 43 1.1 christos if (!in) 44 1.1 christos return 1; 45 1.1 christos len = getline (&line, &siz, in); 46 1.1 christos exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1); 47 1.1 christos } 48 1.1 christos ], am_cv_func_working_getline=yes dnl The library version works. 49 1.1 christos , am_cv_func_working_getline=no dnl The library version does NOT work. 50 1.1 christos , am_cv_func_working_getline=no dnl We're cross compiling. 51 1.1 christos )]) 52 1.1 christos fi 53 1.1 christos 54 1.1 christos if test $am_cv_func_working_getline = no; then 55 1.1 christos dnl We must choose a different name for our function, since on ELF systems 56 1.1 christos dnl a broken getline() in libc.so would override our getline() in 57 1.1 christos dnl libgettextlib.so. 58 1.1 christos AC_DEFINE([getline], [gnu_getline], 59 1.1 christos [Define to a replacement function name for getline().]) 60 1.1 christos AC_LIBOBJ(getline) 61 1.1 christos 62 1.1 christos gl_PREREQ_GETLINE 63 1.1 christos fi 64 1.1 christos ]) 65 1.1 christos 66 1.1 christos # Prerequisites of lib/getline.c. 67 1.1 christos AC_DEFUN([gl_PREREQ_GETLINE], 68 1.1 christos [ 69 1.1 christos gl_FUNC_GETDELIM 70 1.1 christos ]) 71