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