unlocked-io.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Prefer faster, non-thread-safe stdio functions if available.
  2. Copyright (C) 2001-2004, 2009-2013 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 3 of the License, or
  6. (at your option) 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
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /* Written by Jim Meyering. */
  14. #ifndef UNLOCKED_IO_H
  15. # define UNLOCKED_IO_H 1
  16. /* These are wrappers for functions/macros from the GNU C library, and
  17. from other C libraries supporting POSIX's optional thread-safe functions.
  18. The standard I/O functions are thread-safe. These *_unlocked ones are
  19. more efficient but not thread-safe. That they're not thread-safe is
  20. fine since all of the applications in this package are single threaded.
  21. Also, some code that is shared with the GNU C library may invoke
  22. the *_unlocked functions directly. On hosts that lack those
  23. functions, invoke the non-thread-safe versions instead. */
  24. # include <stdio.h>
  25. # if HAVE_DECL_CLEARERR_UNLOCKED
  26. # undef clearerr
  27. # define clearerr(x) clearerr_unlocked (x)
  28. # else
  29. # define clearerr_unlocked(x) clearerr (x)
  30. # endif
  31. # if HAVE_DECL_FEOF_UNLOCKED
  32. # undef feof
  33. # define feof(x) feof_unlocked (x)
  34. # else
  35. # define feof_unlocked(x) feof (x)
  36. # endif
  37. # if HAVE_DECL_FERROR_UNLOCKED
  38. # undef ferror
  39. # define ferror(x) ferror_unlocked (x)
  40. # else
  41. # define ferror_unlocked(x) ferror (x)
  42. # endif
  43. # if HAVE_DECL_FFLUSH_UNLOCKED
  44. # undef fflush
  45. # define fflush(x) fflush_unlocked (x)
  46. # else
  47. # define fflush_unlocked(x) fflush (x)
  48. # endif
  49. # if HAVE_DECL_FGETS_UNLOCKED
  50. # undef fgets
  51. # define fgets(x,y,z) fgets_unlocked (x,y,z)
  52. # else
  53. # define fgets_unlocked(x,y,z) fgets (x,y,z)
  54. # endif
  55. # if HAVE_DECL_FPUTC_UNLOCKED
  56. # undef fputc
  57. # define fputc(x,y) fputc_unlocked (x,y)
  58. # else
  59. # define fputc_unlocked(x,y) fputc (x,y)
  60. # endif
  61. # if HAVE_DECL_FPUTS_UNLOCKED
  62. # undef fputs
  63. # define fputs(x,y) fputs_unlocked (x,y)
  64. # else
  65. # define fputs_unlocked(x,y) fputs (x,y)
  66. # endif
  67. # if HAVE_DECL_FREAD_UNLOCKED
  68. # undef fread
  69. # define fread(w,x,y,z) fread_unlocked (w,x,y,z)
  70. # else
  71. # define fread_unlocked(w,x,y,z) fread (w,x,y,z)
  72. # endif
  73. # if HAVE_DECL_FWRITE_UNLOCKED
  74. # undef fwrite
  75. # define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
  76. # else
  77. # define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
  78. # endif
  79. # if HAVE_DECL_GETC_UNLOCKED
  80. # undef getc
  81. # define getc(x) getc_unlocked (x)
  82. # else
  83. # define getc_unlocked(x) getc (x)
  84. # endif
  85. # if HAVE_DECL_GETCHAR_UNLOCKED
  86. # undef getchar
  87. # define getchar() getchar_unlocked ()
  88. # else
  89. # define getchar_unlocked() getchar ()
  90. # endif
  91. # if HAVE_DECL_PUTC_UNLOCKED
  92. # undef putc
  93. # define putc(x,y) putc_unlocked (x,y)
  94. # else
  95. # define putc_unlocked(x,y) putc (x,y)
  96. # endif
  97. # if HAVE_DECL_PUTCHAR_UNLOCKED
  98. # undef putchar
  99. # define putchar(x) putchar_unlocked (x)
  100. # else
  101. # define putchar_unlocked(x) putchar (x)
  102. # endif
  103. # undef flockfile
  104. # define flockfile(x) ((void) 0)
  105. # undef ftrylockfile
  106. # define ftrylockfile(x) 0
  107. # undef funlockfile
  108. # define funlockfile(x) ((void) 0)
  109. #endif /* UNLOCKED_IO_H */