aboutsummaryrefslogtreecommitdiff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile9
-rw-r--r--libio/clearerr.c4
-rw-r--r--libio/clearerr_u.c2
-rw-r--r--libio/feof_u.c2
-rw-r--r--libio/ferror_u.c2
-rw-r--r--libio/fgetc.c5
-rw-r--r--libio/fileno.c4
-rw-r--r--libio/fputc.c5
-rw-r--r--libio/fputc_u.c2
-rw-r--r--libio/freopen.c5
-rw-r--r--libio/fseek.c9
-rw-r--r--libio/genops.c4
-rw-r--r--libio/getc.c5
-rw-r--r--libio/getc_u.c2
-rw-r--r--libio/getchar.c5
-rw-r--r--libio/getchar_u.c2
-rw-r--r--libio/iofclose.c3
-rw-r--r--libio/iofdopen.c33
-rw-r--r--libio/iofflush.c7
-rw-r--r--libio/iofgetpos.c5
-rw-r--r--libio/iofgets.c3
-rw-r--r--libio/ioflockfile.c43
-rw-r--r--libio/iofopen.c27
-rw-r--r--libio/iofopncook.c28
-rw-r--r--libio/iofputs.c3
-rw-r--r--libio/iofread.c3
-rw-r--r--libio/iofsetpos.c3
-rw-r--r--libio/ioftell.c5
-rw-r--r--libio/iofwrite.c5
-rw-r--r--libio/iogetdelim.c5
-rw-r--r--libio/iogets.c5
-rw-r--r--libio/iopopen.c16
-rw-r--r--libio/ioputs.c5
-rw-r--r--libio/iosetbuffer.c3
-rw-r--r--libio/iosetvbuf.c5
-rw-r--r--libio/ioungetc.c3
-rw-r--r--libio/iovsprintf.c3
-rw-r--r--libio/iovsscanf.c2
-rw-r--r--libio/libio.h5
-rw-r--r--libio/libioP.h1
-rw-r--r--libio/memstream.c32
-rw-r--r--libio/putc.c5
-rw-r--r--libio/putchar.c5
-rw-r--r--libio/putchar_u.c4
-rw-r--r--libio/rewind.c5
-rw-r--r--libio/stdio.h36
-rw-r--r--libio/vasprintf.c2
-rw-r--r--libio/vdprintf.c2
-rw-r--r--libio/vsnprintf.c2
49 files changed, 257 insertions, 124 deletions
diff --git a/libio/Makefile b/libio/Makefile
index e4df6b545e..355a79a0e5 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -36,6 +36,15 @@ routines := \
\
libc_fatal
+include ../Makeconfig
+
+ifneq (,$(filter %REENTRANT, $(defines)))
+routines += clearerr_u feof_u ferror_u fputc_u getc_u getchar_u \
+ iofflush_u putc_u putchar_u ioflockfile
+
+CPPFLAGS += -D_IO_MTSAFE_IO
+endif
+
aux := \
cleanup fileops genops stdfiles stdio strops
diff --git a/libio/clearerr.c b/libio/clearerr.c
index 669a9b0d74..9dfdb11530 100644
--- a/libio/clearerr.c
+++ b/libio/clearerr.c
@@ -24,9 +24,9 @@ clearerr (fp)
FILE *fp;
{
CHECK_FILE (fp, /*nothing*/);
- flockfile (fp);
+ _IO_flockfile (fp);
_IO_clearerr (fp);
- funlockfile (fp);
+ _IO_funlockfile (fp);
}
#ifdef _IO_MTSAFE_IO
diff --git a/libio/clearerr_u.c b/libio/clearerr_u.c
index 83ed65d8b1..4c8b6c29bd 100644
--- a/libio/clearerr_u.c
+++ b/libio/clearerr_u.c
@@ -27,4 +27,4 @@ __clearerr_unlocked (fp)
_IO_clearerr (fp);
}
-weak_alias (clearerr_unlocked, __clearerr_unlocked)
+weak_alias (__clearerr_unlocked, clearerr_unlocked)
diff --git a/libio/feof_u.c b/libio/feof_u.c
index 5ce5583613..6ed8b7d4fe 100644
--- a/libio/feof_u.c
+++ b/libio/feof_u.c
@@ -24,6 +24,8 @@ the executable file might be covered by the GNU General Public License. */
#include "libioP.h"
#include "stdio.h"
+#undef feof_unlocked
+
int
feof_unlocked (fp)
_IO_FILE* fp;
diff --git a/libio/ferror_u.c b/libio/ferror_u.c
index bee668d6d9..df550d9d4d 100644
--- a/libio/ferror_u.c
+++ b/libio/ferror_u.c
@@ -24,6 +24,8 @@ the executable file might be covered by the GNU General Public License. */
#include "libioP.h"
#include "stdio.h"
+#undef ferror_unlocked
+
int
ferror_unlocked (fp)
_IO_FILE* fp;
diff --git a/libio/fgetc.c b/libio/fgetc.c
index 2aaea05cfe..07fd89a516 100644
--- a/libio/fgetc.c
+++ b/libio/fgetc.c
@@ -31,8 +31,9 @@ fgetc (fp)
{
int result;
CHECK_FILE (fp, EOF);
- flockfile (fp);
+ __libc_cleanup_region_start (_IO_funlockfile, fp);
+ _IO_flockfile (fp);
result = _IO_getc_unlocked (fp);
- funlockfile (fp);
+ __libc_cleanup_region_end (1);
return result;
}
diff --git a/libio/fileno.c b/libio/fileno.c
index 2dc67149c8..08e657b970 100644
--- a/libio/fileno.c
+++ b/libio/fileno.c
@@ -42,6 +42,6 @@ fileno (fp)
it only accesses once a single variable and this is already atomic
(at least at thread level). */
-weak_alias (fileno_unlocked, fileno)
-weak_alias (fileno_locked, fileno)
+weak_alias (fileno, fileno_unlocked)
+weak_alias (fileno, fileno_locked)
#endif
diff --git a/libio/fputc.c b/libio/fputc.c
index 339861119f..bd871ab047 100644
--- a/libio/fputc.c
+++ b/libio/fputc.c
@@ -32,8 +32,11 @@ fputc (c, fp)
{
int result;
CHECK_FILE (fp, EOF);
+ __libc_cleanup_region_start (&_IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_putc_unlocked (c, fp);
- _IO_funlockfile (fp);
+ __libc_cleanup_region_end (1);
return result;
}
+
+weak_alias (fputc, fputc_locked)
diff --git a/libio/fputc_u.c b/libio/fputc_u.c
index 211e206605..97e4d94eb3 100644
--- a/libio/fputc_u.c
+++ b/libio/fputc_u.c
@@ -36,4 +36,4 @@ __fputc_unlocked (c, fp)
return _IO_putc_unlocked (c, fp);
}
-weak_alias (fputc_unlocked, __fputc_unlocked)
+weak_alias (__fputc_unlocked, fputc_unlocked)
diff --git a/libio/freopen.c b/libio/freopen.c
index 829af31dc1..5821e84c6f 100644
--- a/libio/freopen.c
+++ b/libio/freopen.c
@@ -35,8 +35,9 @@ freopen (filename, mode, fp)
CHECK_FILE (fp, NULL);
if (!(fp->_flags & _IO_IS_FILEBUF))
return NULL;
- flockfile (fp);
+ __libc_cleanup_region_start (&_IO_funlockfile, fp);
+ _IO_flockfile (fp);
result = _IO_freopen (filename, mode, fp);
- funlockfile (fp);
+ __libc_cleanup_region_end (1);
return result;
}
diff --git a/libio/fseek.c b/libio/fseek.c
index 5255e9defe..c33927a95f 100644
--- a/libio/fseek.c
+++ b/libio/fseek.c
@@ -1,5 +1,5 @@
/*
-Copyright (C) 1993, 1995 Free Software Foundation
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
@@ -22,8 +22,8 @@ the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
-#include "stdio.h"
#include "libioP.h"
+#include "stdio.h"
int
fseek (fp, offset, whence)
@@ -33,8 +33,9 @@ fseek (fp, offset, whence)
{
int result;
CHECK_FILE (fp, -1);
- flockfile (fp);
+ __libc_cleanup_region_start (&_IO_funlockfile, fp);
+ _IO_flockfile (fp);
result = _IO_fseek (fp, offset, whence);
- funlockfile (fp);
+ __libc_cleanup_region_end (1);
return result;
}
diff --git a/libio/genops.c b/libio/genops.c
index 98eef94b58..818e740851 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -466,7 +466,7 @@ DEFUN(_IO_init, (fp, flags),
fp->_markers = NULL;
fp->_cur_column = 0;
#ifdef _IO_MTSAFE_IO
- _IO_mutex_init (fp->_lock);
+ __libc_lock_init (fp->_lock);
#endif
}
@@ -501,7 +501,7 @@ DEFUN(_IO_default_finish, (fp),
}
#ifdef _IO_MTSAFE_IO
- _IO_mutex_destroy (fp->_lock);
+ __libc_lock_fini (fp->_lock);
#endif
_IO_un_link(fp);
diff --git a/libio/getc.c b/libio/getc.c
index 89abc0dac0..82e5756ad3 100644
--- a/libio/getc.c
+++ b/libio/getc.c
@@ -33,14 +33,15 @@ getc (fp)
{
int result;
CHECK_FILE (fp, EOF);
+ __libc_cleanup_region_start (&_IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_getc_unlocked (fp);
- _IO_funlockfile (fp);
+ __libc_cleanup_region_end (1);
return result;
}
#ifdef _IO_MTSAFE_IO
# undef getc_locked
-weak_alias (getc_locked, getc)
+weak_alias (getc, getc_locked)
#endif
diff --git a/libio/getc_u.c b/libio/getc_u.c
index e6491bb944..4aa5cd5ccd 100644
--- a/libio/getc_u.c
+++ b/libio/getc_u.c
@@ -35,4 +35,4 @@ __getc_unlocked (fp)
return _IO_getc_unlocked (fp);
}
-weak_alias (getc_unlocked, __getc_unlocked)
+weak_alias (__getc_unlocked, getc_unlocked)
diff --git a/libio/getchar.c b/libio/getchar.c
index fa5c11f731..e7a236cf2e 100644
--- a/libio/getchar.c
+++ b/libio/getchar.c
@@ -31,14 +31,15 @@ int
getchar ()
{
int result;
+ __libc_cleanup_region_start (&_IO_funlockfile, stdin);
_IO_flockfile (stdin);
result = _IO_getc_unlocked (stdin);
- _IO_funlockfile (stdin);
+ __libc_cleanup_region_end (1);
return result;
}
#ifdef _IO_MTSAFE_IO
# undef getchar_locked
-weak_alias (getchar_locked, getchar)
+weak_alias (getchar, getchar_locked)
#endif
diff --git a/libio/getchar_u.c b/libio/getchar_u.c
index 40cfbf6625..0430f8119c 100644
--- a/libio/getchar_u.c
+++ b/libio/getchar_u.c
@@ -33,4 +33,4 @@ __getchar_unlocked ()
return _IO_getc_unlocked (stdin);
}
-weak_alias (getchar_unlocked, __getchar_unlocked)
+weak_alias (__getchar_unlocked, getchar_unlocked)
diff --git a/libio/iofclose.c b/libio/iofclose.c
index e5cae966fd..9d537377a4 100644
--- a/libio/iofclose.c
+++ b/libio/iofclose.c
@@ -35,6 +35,7 @@ _IO_fclose (fp)
CHECK_FILE(fp, EOF);
+ __libc_cleanup_region_start (&_IO_funlockfile, fp);
_IO_flockfile (fp);
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
status = _IO_file_close_it (fp);
@@ -46,7 +47,7 @@ _IO_fclose (fp)
fp->_IO_file_flags = 0;
free(fp);
}
- _IO_funlockfile (fp);
+ __libc_cleanup_region_end (1);
return status;
}
diff --git a/libio/iofdopen.c b/libio/iofdopen.c
index 6bb19fa214..c49387b1a0 100644
--- a/libio/iofdopen.c
+++ b/libio/iofdopen.c
@@ -39,7 +39,11 @@ _IO_fdopen (fd, mode)
{
int read_write;
int posix_mode = 0;
- struct _IO_FILE_plus *fp;
+ struct locked_FILE
+ {
+ struct _IO_FILE_plus fp;
+ _IO_lock_t lock;
+ } *new_f;
int fd_flags;
switch (*mode++)
@@ -97,28 +101,29 @@ _IO_fdopen (fd, mode)
}
#endif
- fp = (struct _IO_FILE_plus *) malloc (sizeof (struct _IO_FILE_plus));
- if (fp == NULL)
+ new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
+ if (new_f == NULL)
return NULL;
- _IO_init (&fp->file, 0);
- _IO_JUMPS (&fp->file) = &_IO_file_jumps;
- _IO_file_init (&fp->file);
+ new_f->fp.file._lock = &new_f->lock;
+ _IO_init (&new_f->fp.file, 0);
+ _IO_JUMPS (&new_f->fp.file) = &_IO_file_jumps;
+ _IO_file_init (&new_f->fp.file);
#if !_IO_UNIFIED_JUMPTABLES
- fp->vtable = NULL;
+ new_f->fp.vtable = NULL;
#endif
- if (_IO_file_attach (&fp->file, fd) == NULL)
+ if (_IO_file_attach (&new_f->fp.file, fd) == NULL)
{
- _IO_un_link (&fp->file);
- free (fp);
+ _IO_un_link (&new_f->fp.file);
+ free (new_f);
return NULL;
}
- fp->file._flags &= ~_IO_DELETE_DONT_CLOSE;
+ new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
- fp->file._IO_file_flags =
- _IO_mask_flags (&fp->file, read_write,
+ new_f->fp.file._IO_file_flags =
+ _IO_mask_flags (&new_f->fp.file, read_write,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
- return (_IO_FILE *) fp;
+ return (_IO_FILE *) &new_f->fp;
}
weak_alias (_IO_fdopen, fdopen)
diff --git a/libio/iofflush.c b/libio/iofflush.c
index 6fe2d5262d..cbc5b1f6d7 100644
--- a/libio/iofflush.c
+++ b/libio/iofflush.c
@@ -1,5 +1,5 @@
/*
-Copyright (C) 1993, 1995 Free Software Foundation
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
@@ -33,10 +33,11 @@ _IO_fflush (fp)
else
{
int result;
- _IO_flockfile (fp);
CHECK_FILE (fp, EOF);
+ __libc_cleanup_region_start (&_IO_funlockfile, fp);
+ _IO_flockfile (fp);
result = _IO_SYNC (fp) ? EOF : 0;
- _IO_funlockfile (fp);
+ __libc_cleanup_region_end (1);
return result;
}
}
diff --git a/libio/iofgetpos.c b/libio/iofgetpos.c
index 50014765f9..c45cfacb06 100644
--- a/libio/iofgetpos.c
+++ b/libio/iofgetpos.c
@@ -1,5 +1,5 @@
/*
-Copyright (C) 1993, 1995 Free Software Foundation
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
@@ -33,9 +33,10 @@ _IO_fgetpos (fp, posp)
{
_IO_fpos_t pos;
CHECK_FILE (fp, EOF);
+ __libc_cleanup_region_start (&_IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0);
- _IO_funlockfile (fp);
+ __libc_cleanup_region_end (1);
if (pos == _IO_pos_BAD)
{
#ifdef EIO<