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