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