02b7b1fdd0b6f67e46c96fb8825e5dd0bb501293
[gnulib.git] / lib / gen-uio
1 #!/bin/sh
2
3 tmp=gen-uio.$$
4 trap 'status=$?; rm -f $tmp && exit $status' 0
5 trap '{ (exit 1); exit 1; }' 1 2 13 15
6
7 cat <<\EOF || exit 1
8 #ifndef UNLOCKED_IO_H
9 # define UNLOCKED_IO_H 1
10
11 # if USE_UNLOCKED_IO
12
13 /* These are wrappers for functions/macros from GNU libc.
14    The standard I/O functions are thread-safe.  These *_unlocked ones are
15    more efficient but not thread-safe.  That they're not thread-safe is
16    fine since all of the applications in this package are single threaded.  */
17
18 EOF
19
20 for f in $@; do
21   u=`echo $f|tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
22   cat <<EOF || exit 1
23 #  if HAVE_${u}_UNLOCKED
24 #   undef $f
25 EOF
26   case $f in
27     getchar)
28       params=;;
29     putchar | clearerr | feof | ferror | fflush | getc )
30       params=x;;
31     putc | fputc | fputs )
32       params=x,y;;
33     fgets )
34       params=x,y,z;;
35     fread | fwrite )
36       params=w,x,y,z;;
37     *)
38       echo $0: missing case for $f 2>&1; exit 1;;
39   esac
40   cat <<EOF || exit 1
41 #   define $f($params) ${f}_unlocked ($params)
42 #  endif
43 EOF
44 done
45
46 cat <<\EOF || exit 1
47
48 # endif /* USE_UNLOCKED_IO */
49 #endif /* UNLOCKED_IO_H */
50 EOF
51
52 (exit 0); exit