unlocked-io.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Prefer faster, non-thread-safe stdio functions if available.
  2. Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. /* Written by Jim Meyering. */
  15. #ifndef UNLOCKED_IO_H
  16. # define UNLOCKED_IO_H 1
  17. # ifndef USE_UNLOCKED_IO
  18. # define USE_UNLOCKED_IO 1
  19. # endif
  20. # if USE_UNLOCKED_IO
  21. /* These are wrappers for functions/macros from the GNU C library, and
  22. from other C libraries supporting POSIX's optional thread-safe functions.
  23. The standard I/O functions are thread-safe. These *_unlocked ones are
  24. more efficient but not thread-safe. That they're not thread-safe is
  25. fine since all of the applications in this package are single threaded.
  26. Also, some code that is shared with the GNU C library may invoke
  27. the *_unlocked functions directly. On hosts that lack those
  28. functions, invoke the non-thread-safe versions instead. */
  29. # include <stdio.h>
  30. # if HAVE_DECL_CLEARERR_UNLOCKED
  31. # undef clearerr
  32. # define clearerr(x) clearerr_unlocked (x)
  33. # else
  34. # define clearerr_unlocked(x) clearerr (x)
  35. # endif
  36. # if HAVE_DECL_FEOF_UNLOCKED
  37. # undef feof
  38. # define feof(x) feof_unlocked (x)
  39. # else
  40. # define feof_unlocked(x) feof (x)
  41. # endif
  42. # if HAVE_DECL_FERROR_UNLOCKED
  43. # undef ferror
  44. # define ferror(x) ferror_unlocked (x)
  45. # else
  46. # define ferror_unlocked(x) ferror (x)
  47. # endif
  48. # if HAVE_DECL_FFLUSH_UNLOCKED
  49. # undef fflush
  50. # define fflush(x) fflush_unlocked (x)
  51. # else
  52. # define fflush_unlocked(x) fflush (x)
  53. # endif
  54. # if HAVE_DECL_FGETS_UNLOCKED
  55. # undef fgets
  56. # define fgets(x,y,z) fgets_unlocked (x,y,z)
  57. # else
  58. # define fgets_unlocked(x,y,z) fgets (x,y,z)
  59. # endif
  60. # if HAVE_DECL_FPUTC_UNLOCKED
  61. # undef fputc
  62. # define fputc(x,y) fputc_unlocked (x,y)
  63. # else
  64. # define fputc_unlocked(x,y) fputc (x,y)
  65. # endif
  66. # if HAVE_DECL_FPUTS_UNLOCKED
  67. # undef fputs
  68. # define fputs(x,y) fputs_unlocked (x,y)
  69. # else
  70. # define fputs_unlocked(x,y) fputs (x,y)
  71. # endif
  72. # if HAVE_DECL_FREAD_UNLOCKED
  73. # undef fread
  74. # define fread(w,x,y,z) fread_unlocked (w,x,y,z)
  75. # else
  76. # define fread_unlocked(w,x,y,z) fread (w,x,y,z)
  77. # endif
  78. # if HAVE_DECL_FWRITE_UNLOCKED
  79. # undef fwrite
  80. # define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
  81. # else
  82. # define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
  83. # endif
  84. # if HAVE_DECL_GETC_UNLOCKED
  85. # undef getc
  86. # define getc(x) getc_unlocked (x)
  87. # else
  88. # define getc_unlocked(x) getc (x)
  89. # endif
  90. # if HAVE_DECL_GETCHAR_UNLOCKED
  91. # undef getchar
  92. # define getchar() getchar_unlocked ()
  93. # else
  94. # define getchar_unlocked() getchar ()
  95. # endif
  96. # if HAVE_DECL_PUTC_UNLOCKED
  97. # undef putc
  98. # define putc(x,y) putc_unlocked (x,y)
  99. # else
  100. # define putc_unlocked(x,y) putc (x,y)
  101. # endif
  102. # if HAVE_DECL_PUTCHAR_UNLOCKED
  103. # undef putchar
  104. # define putchar(x) putchar_unlocked (x)
  105. # else
  106. # define putchar_unlocked(x) putchar (x)
  107. # endif
  108. # undef flockfile
  109. # define flockfile(x) ((void) 0)
  110. # undef ftrylockfile
  111. # define ftrylockfile(x) 0
  112. # undef funlockfile
  113. # define funlockfile(x) ((void) 0)
  114. # endif /* USE_UNLOCKED_IO */
  115. #endif /* UNLOCKED_IO_H */