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