1# serial 19
2
3# Copyright (C) 2000-2001, 2004-2012 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved.
7
8dnl From Jim Meyering
9dnl Using code from emacs, based on suggestions from Paul Eggert
10dnl and Ulrich Drepper.
11
12dnl Find out how to determine the number of pending output bytes on a stream.
13dnl glibc (2.1.93 and newer) and Solaris provide __fpending.  On other systems,
14dnl we have to grub around in the FILE struct.
15
16AC_DEFUN([gl_FUNC_FPENDING],
17[
18  AC_CHECK_HEADERS_ONCE([stdio_ext.h])
19  AC_CHECK_FUNCS_ONCE([__fpending])
20  fp_headers='
21#     include <stdio.h>
22#     if HAVE_STDIO_EXT_H
23#      include <stdio_ext.h>
24#     endif
25'
26  AC_CHECK_DECLS([__fpending], , , $fp_headers)
27])
28
29AC_DEFUN([gl_PREREQ_FPENDING],
30[
31  AC_CACHE_CHECK(
32              [how to determine the number of pending output bytes on a stream],
33                 ac_cv_sys_pending_output_n_bytes,
34    [
35      for ac_expr in                                                    \
36                                                                        \
37          '# glibc2'                                                    \
38          'fp->_IO_write_ptr - fp->_IO_write_base'                      \
39                                                                        \
40          '# traditional Unix'                                          \
41          'fp->_ptr - fp->_base'                                        \
42                                                                        \
43          '# BSD'                                                       \
44          'fp->_p - fp->_bf._base'                                      \
45                                                                        \
46          '# SCO, Unixware'                                             \
47          '(fp->__ptr ? fp->__ptr - fp->__base : 0)'                    \
48                                                                        \
49          '# QNX'                                                       \
50          '(fp->_Mode & 0x2000 /*_MWRITE*/ ? fp->_Next - fp->_Buf : 0)' \
51                                                                        \
52          '# old glibc?'                                                \
53          'fp->__bufp - fp->__buffer'                                   \
54                                                                        \
55          '# old glibc iostream?'                                       \
56          'fp->_pptr - fp->_pbase'                                      \
57                                                                        \
58          '# emx+gcc'                                                   \
59          'fp->_ptr - fp->_buffer'                                      \
60                                                                        \
61          '# Minix'                                                     \
62          'fp->_ptr - fp->_buf'                                         \
63                                                                        \
64          '# Plan9'                                                     \
65          'fp->wp - fp->buf'                                            \
66                                                                        \
67          '# VMS'                                                       \
68          '(*fp)->_ptr - (*fp)->_base'                                  \
69                                                                        \
70          '# e.g., DGUX R4.11; the info is not available'               \
71          1                                                             \
72          ; do
73
74        # Skip each embedded comment.
75        case "$ac_expr" in '#'*) continue;; esac
76
77        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
78          [[FILE *fp = stdin; (void) ($ac_expr);]])],
79          [fp_done=yes]
80        )
81        test "$fp_done" = yes && break
82      done
83
84      ac_cv_sys_pending_output_n_bytes=$ac_expr
85    ]
86  )
87  AC_DEFINE_UNQUOTED([PENDING_OUTPUT_N_BYTES],
88    $ac_cv_sys_pending_output_n_bytes,
89    [the number of pending output bytes on stream 'fp'])
90])
91