]> git.draconx.ca Git - dxcommon.git/blob - m4/getline.m4
dx_getline: Fix EOF handling in standard C fallback.
[dxcommon.git] / m4 / getline.m4
1 # Copyright © 2024 Nick Bowler
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16 # DX_CHECK_GETLINE
17 #
18 # Check whether or not the getline function is available.  If it is, the macro
19 # HAVE_GETLINE is defined to 1 and the cache variable dx_cv_have_getline is set
20 # to "yes".  Otherwise, dx_cv_have_getline is set to "no".
21 AC_DEFUN([DX_CHECK_GETLINE],
22 [AC_CACHE_CHECK([for getline], [dx_cv_have_getline],
23   [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
24 ], [ssize_t (*x)() = getline;
25 char *p = 0;
26 size_t n = 0;
27 return getline(&p, &n, stdin);
28 ])], [dx_cv_have_getline=yes], [dx_cv_have_getline=no])])
29 AS_CASE([$dx_cv_have_getline], [yes],
30   [AC_DEFINE([HAVE_GETLINE], [1],
31     [Define to 1 if the getline function is available.])])])