summaryrefslogtreecommitdiff
path: root/lib/gen-uio
blob: 02b7b1fdd0b6f67e46c96fb8825e5dd0bb501293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh

tmp=gen-uio.$$
trap 'status=$?; rm -f $tmp && exit $status' 0
trap '{ (exit 1); exit 1; }' 1 2 13 15

cat <<\EOF || exit 1
#ifndef UNLOCKED_IO_H
# define UNLOCKED_IO_H 1

# if USE_UNLOCKED_IO

/* These are wrappers for functions/macros from GNU libc.
   The standard I/O functions are thread-safe.  These *_unlocked ones are
   more efficient but not thread-safe.  That they're not thread-safe is
   fine since all of the applications in this package are single threaded.  */

EOF

for f in $@; do
  u=`echo $f|tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
  cat <<EOF || exit 1
#  if HAVE_${u}_UNLOCKED
#   undef $f
EOF
  case $f in
    getchar)
      params=;;
    putchar | clearerr | feof | ferror | fflush | getc )
      params=x;;
    putc | fputc | fputs )
      params=x,y;;
    fgets )
      params=x,y,z;;
    fread | fwrite )
      params=w,x,y,z;;
    *)
      echo $0: missing case for $f 2>&1; exit 1;;
  esac
  cat <<EOF || exit 1
#   define $f($params) ${f}_unlocked ($params)
#  endif
EOF
done

cat <<\EOF || exit 1

# endif /* USE_UNLOCKED_IO */
#endif /* UNLOCKED_IO_H */
EOF

(exit 0); exit