*** empty log message ***
[gnulib.git] / m4 / fpending.m4
1 #serial 1
2
3 dnl From Jim Meyering
4 dnl Using code from emacs, based on suggestions from Paul Eggert
5 dnl and Ulrich Drepper.
6
7 dnl Find out how to determine the number of pending output bytes on a stream.
8 dnl Solaris provides __fpending.  On other systems, we have to grub around
9 dnl in the FILE struct.
10
11 AC_DEFUN(jm_FUNC_FPENDING,
12 [
13   AC_CHECK_HEADERS(stdio_ext.h)
14   AC_REPLACE_FUNCS([__fpending])
15   if test $ac_cv_func___fpending = no; then
16     AC_CACHE_CHECK(
17               [how to determine the number of pending output bytes on a stream],
18                    ac_cv_sys_pending_output_n_bytes,
19       [
20         fp_save_DEFS=$DEFS
21         for ac_expr in                                          \
22                                                                 \
23             '# glibc2'                                          \
24             'fp->_IO_write_ptr - fp->_IO_write_base'            \
25                                                                 \
26             '# traditional Unix'                                \
27             'fp->_ptr - fp->_base'                              \
28                                                                 \
29             '# BSD'                                             \
30             'fp->_p - fp->_bf._base'                            \
31                                                                 \
32             '# SCO, Unixware'                                   \
33             'fp->__ptr - fp->__base'                            \
34                                                                 \
35             '# old glibc?'                                      \
36             'fp->__bufp - fp->__buffer'                         \
37                                                                 \
38             '# old glibc iostream?'                             \
39             'fp->_pptr - fp->_pbase'                            \
40                                                                 \
41             '# VMS'                                             \
42             '(*fp)->_ptr - (*fp)->_base'                        \
43                                                                 \
44             '# e.g., DGUX R4.11; the info is not available'     \
45             1                                                   \
46             ; do
47
48           # Skip each embedded comment.
49           case "$ac_expr" in '#'*) continue;; esac
50
51           DEFS="$DEFS -DPENDING_OUTPUT_N_BYTES=$ac_expr"
52           AC_TRY_COMPILE(
53             [#include <stdio.h>
54             ],
55             [FILE *fp = stdin; (void) ($ac_expr);],
56             fp_done=yes
57           )
58           DEFS=$fp_save_DEFS
59           test "$fp_done" = yes && break
60         done
61
62         ac_cv_sys_pending_output_n_bytes=$ac_expr
63       ]
64     )
65     AC_DEFINE_UNQUOTED(PENDING_OUTPUT_N_BYTES,
66       $ac_cv_sys_pending_output_n_bytes,
67       [the number of pending output bytes on stream `fp'])
68   fi
69 ])