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