unlocked-io.h 3.5 KB

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