140ec4fddelphij/* Prefer faster, non-thread-safe stdio functions if available.
240ec4fddelphij
340ec4fddelphij   Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
440ec4fddelphij
540ec4fddelphij   This program is free software; you can redistribute it and/or modify
640ec4fddelphij   it under the terms of the GNU General Public License as published by
740ec4fddelphij   the Free Software Foundation; either version 2, or (at your option)
840ec4fddelphij   any later version.
940ec4fddelphij
1040ec4fddelphij   This program is distributed in the hope that it will be useful,
1140ec4fddelphij   but WITHOUT ANY WARRANTY; without even the implied warranty of
1240ec4fddelphij   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1340ec4fddelphij   GNU General Public License for more details.
1440ec4fddelphij
1540ec4fddelphij   You should have received a copy of the GNU General Public License along
1640ec4fddelphij   with this program; if not, write to the Free Software Foundation,
1740ec4fddelphij   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
1840ec4fddelphij
1940ec4fddelphij/* Written by Jim Meyering.  */
2040ec4fddelphij
2140ec4fddelphij#ifndef UNLOCKED_IO_H
2240ec4fddelphij# define UNLOCKED_IO_H 1
2340ec4fddelphij
2440ec4fddelphij# ifndef USE_UNLOCKED_IO
2540ec4fddelphij#  define USE_UNLOCKED_IO 1
2640ec4fddelphij# endif
2740ec4fddelphij
2840ec4fddelphij# if USE_UNLOCKED_IO
2940ec4fddelphij
3040ec4fddelphij/* These are wrappers for functions/macros from the GNU C library, and
3140ec4fddelphij   from other C libraries supporting POSIX's optional thread-safe functions.
3240ec4fddelphij
3340ec4fddelphij   The standard I/O functions are thread-safe.  These *_unlocked ones are
3440ec4fddelphij   more efficient but not thread-safe.  That they're not thread-safe is
3540ec4fddelphij   fine since all of the applications in this package are single threaded.
3640ec4fddelphij
3740ec4fddelphij   Also, some code that is shared with the GNU C library may invoke
3840ec4fddelphij   the *_unlocked functions directly.  On hosts that lack those
3940ec4fddelphij   functions, invoke the non-thread-safe versions instead.  */
4040ec4fddelphij
4140ec4fddelphij#  include <stdio.h>
4240ec4fddelphij
4340ec4fddelphij#  if HAVE_DECL_CLEARERR_UNLOCKED
4440ec4fddelphij#   undef clearerr
4540ec4fddelphij#   define clearerr(x) clearerr_unlocked (x)
4640ec4fddelphij#  else
4740ec4fddelphij#   define clearerr_unlocked(x) clearerr (x)
4840ec4fddelphij#  endif
4940ec4fddelphij#  if HAVE_DECL_FEOF_UNLOCKED
5040ec4fddelphij#   undef feof
5140ec4fddelphij#   define feof(x) feof_unlocked (x)
5240ec4fddelphij#  else
5340ec4fddelphij#   define feof_unlocked(x) feof (x)
5440ec4fddelphij#  endif
5540ec4fddelphij#  if HAVE_DECL_FERROR_UNLOCKED
5640ec4fddelphij#   undef ferror
5740ec4fddelphij#   define ferror(x) ferror_unlocked (x)
5840ec4fddelphij#  else
5940ec4fddelphij#   define ferror_unlocked(x) ferror (x)
6040ec4fddelphij#  endif
6140ec4fddelphij#  if HAVE_DECL_FFLUSH_UNLOCKED
6240ec4fddelphij#   undef fflush
6340ec4fddelphij#   define fflush(x) fflush_unlocked (x)
6440ec4fddelphij#  else
6540ec4fddelphij#   define fflush_unlocked(x) fflush (x)
6640ec4fddelphij#  endif
6740ec4fddelphij#  if HAVE_DECL_FGETS_UNLOCKED
6840ec4fddelphij#   undef fgets
6940ec4fddelphij#   define fgets(x,y,z) fgets_unlocked (x,y,z)
7040ec4fddelphij#  else
7140ec4fddelphij#   define fgets_unlocked(x,y,z) fgets (x,y,z)
7240ec4fddelphij#  endif
7340ec4fddelphij#  if HAVE_DECL_FPUTC_UNLOCKED
7440ec4fddelphij#   undef fputc
7540ec4fddelphij#   define fputc(x,y) fputc_unlocked (x,y)
7640ec4fddelphij#  else
7740ec4fddelphij#   define fputc_unlocked(x,y) fputc (x,y)
7840ec4fddelphij#  endif
7940ec4fddelphij#  if HAVE_DECL_FPUTS_UNLOCKED
8040ec4fddelphij#   undef fputs
8140ec4fddelphij#   define fputs(x,y) fputs_unlocked (x,y)
8240ec4fddelphij#  else
8340ec4fddelphij#   define fputs_unlocked(x,y) fputs (x,y)
8440ec4fddelphij#  endif
8540ec4fddelphij#  if HAVE_DECL_FREAD_UNLOCKED
8640ec4fddelphij#   undef fread
8740ec4fddelphij#   define fread(w,x,y,z) fread_unlocked (w,x,y,z)
8840ec4fddelphij#  else
8940ec4fddelphij#   define fread_unlocked(w,x,y,z) fread (w,x,y,z)
9040ec4fddelphij#  endif
9140ec4fddelphij#  if HAVE_DECL_FWRITE_UNLOCKED
9240ec4fddelphij#   undef fwrite
9340ec4fddelphij#   define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
9440ec4fddelphij#  else
9540ec4fddelphij#   define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
9640ec4fddelphij#  endif
9740ec4fddelphij#  if HAVE_DECL_GETC_UNLOCKED
9840ec4fddelphij#   undef getc
9940ec4fddelphij#   define getc(x) getc_unlocked (x)
10040ec4fddelphij#  else
10140ec4fddelphij#   define getc_unlocked(x) getc (x)
10240ec4fddelphij#  endif
10340ec4fddelphij#  if HAVE_DECL_GETCHAR_UNLOCKED
10440ec4fddelphij#   undef getchar
10540ec4fddelphij#   define getchar() getchar_unlocked ()
10640ec4fddelphij#  else
10740ec4fddelphij#   define getchar_unlocked() getchar ()
10840ec4fddelphij#  endif
10940ec4fddelphij#  if HAVE_DECL_PUTC_UNLOCKED
11040ec4fddelphij#   undef putc
11140ec4fddelphij#   define putc(x,y) putc_unlocked (x,y)
11240ec4fddelphij#  else
11340ec4fddelphij#   define putc_unlocked(x,y) putc (x,y)
11440ec4fddelphij#  endif
11540ec4fddelphij#  if HAVE_DECL_PUTCHAR_UNLOCKED
11640ec4fddelphij#   undef putchar
11740ec4fddelphij#   define putchar(x) putchar_unlocked (x)
11840ec4fddelphij#  else
11940ec4fddelphij#   define putchar_unlocked(x) putchar (x)
12040ec4fddelphij#  endif
12140ec4fddelphij
12240ec4fddelphij#  undef flockfile
12340ec4fddelphij#  define flockfile(x) ((void) 0)
12440ec4fddelphij
12540ec4fddelphij#  undef ftrylockfile
12640ec4fddelphij#  define ftrylockfile(x) 0
12740ec4fddelphij
12840ec4fddelphij#  undef funlockfile
12940ec4fddelphij#  define funlockfile(x) ((void) 0)
13040ec4fddelphij
13140ec4fddelphij# endif /* USE_UNLOCKED_IO */
13240ec4fddelphij#endif /* UNLOCKED_IO_H */
133