fpending.m4 4.5 KB

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