1 /* Prefer faster, non-thread-safe stdio functions if available.
3 Copyright (C) 2001-2004, 2009-2024 Free Software Foundation, Inc.
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 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by Jim Meyering. */
21 # define UNLOCKED_IO_H 1
23 /* These are wrappers for functions/macros from the GNU C library, and
24 from other C libraries supporting POSIX's optional thread-safe functions.
26 The standard I/O functions are thread-safe. These *_unlocked ones are
27 more efficient but not thread-safe. That they're not thread-safe is
28 fine since all of the applications in this package are single threaded.
30 Also, some code that is shared with the GNU C library may invoke
31 the *_unlocked functions directly. On hosts that lack those
32 functions, invoke the non-thread-safe versions instead. */
34 /* This file uses HAVE_DECL_*_UNLOCKED. */
35 # if !_GL_CONFIG_H_INCLUDED
36 # error "Please include config.h first."
41 # if HAVE_DECL_CLEARERR_UNLOCKED || defined clearerr_unlocked
43 # define clearerr(x) clearerr_unlocked (x)
45 # define clearerr_unlocked(x) clearerr (x)
48 # if HAVE_DECL_FEOF_UNLOCKED || defined feof_unlocked
50 # define feof(x) feof_unlocked (x)
52 # define feof_unlocked(x) feof (x)
55 # if HAVE_DECL_FERROR_UNLOCKED || defined ferror_unlocked
57 # define ferror(x) ferror_unlocked (x)
59 # define ferror_unlocked(x) ferror (x)
62 # if HAVE_DECL_FFLUSH_UNLOCKED || defined fflush_unlocked
64 # define fflush(x) fflush_unlocked (x)
66 # define fflush_unlocked(x) fflush (x)
69 # if HAVE_DECL_FGETS_UNLOCKED || defined fgets_unlocked
71 # define fgets(x,y,z) fgets_unlocked (x,y,z)
73 # define fgets_unlocked(x,y,z) fgets (x,y,z)
76 # if HAVE_DECL_FPUTC_UNLOCKED || defined fputc_unlocked
78 # define fputc(x,y) fputc_unlocked (x,y)
80 # define fputc_unlocked(x,y) fputc (x,y)
83 # if HAVE_DECL_FPUTS_UNLOCKED || defined fputs_unlocked
85 # define fputs(x,y) fputs_unlocked (x,y)
87 # define fputs_unlocked(x,y) fputs (x,y)
90 # if HAVE_DECL_FREAD_UNLOCKED || defined fread_unlocked
92 # define fread(w,x,y,z) fread_unlocked (w,x,y,z)
94 # define fread_unlocked(w,x,y,z) fread (w,x,y,z)
97 # if HAVE_DECL_FWRITE_UNLOCKED || defined fwrite_unlocked
99 # define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
101 # define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
104 # if HAVE_DECL_GETC_UNLOCKED || defined getc_unlocked
106 # define getc(x) getc_unlocked (x)
108 # define getc_unlocked(x) getc (x)
111 # if HAVE_DECL_GETCHAR_UNLOCKED || defined getchar_unlocked
113 # define getchar() getchar_unlocked ()
115 # define getchar_unlocked() getchar ()
118 # if HAVE_DECL_PUTC_UNLOCKED || defined putc_unlocked
120 # define putc(x,y) putc_unlocked (x,y)
122 # define putc_unlocked(x,y) putc (x,y)
125 # if HAVE_DECL_PUTCHAR_UNLOCKED || defined putchar_unlocked
127 # define putchar(x) putchar_unlocked (x)
129 # define putchar_unlocked(x) putchar (x)
133 # define flockfile(x) ((void) 0)
136 # define ftrylockfile(x) 0
139 # define funlockfile(x) ((void) 0)
141 #endif /* UNLOCKED_IO_H */