aboutsummaryrefslogtreecommitdiff
path: root/libio/stdio
diff options
context:
space:
mode:
authorBrendan Kehoe <brendan@gcc.gnu.org>1997-09-06 03:44:38 -0400
committerBrendan Kehoe <brendan@gcc.gnu.org>1997-09-06 03:44:38 -0400
commitdbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56 (patch)
tree82e1a9aef1a37d3e21b8f1d0fe3a9435ad5a2f53 /libio/stdio
parent1496c1bb0be5c2981f056fa169cf1c199f50a38a (diff)
downloadgcc-dbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56.zip
gcc-dbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56.tar.gz
gcc-dbfcb4beace35e1426c1ce1e9bf2f20c7d5a0f56.tar.bz2
Insert libio rewrite and its various changes from devo.
From-SVN: r15129
Diffstat (limited to 'libio/stdio')
-rw-r--r--libio/stdio/ChangeLog41
-rw-r--r--libio/stdio/Makefile.in18
-rw-r--r--libio/stdio/clearerr.c28
-rw-r--r--libio/stdio/clearerr_u.c28
-rw-r--r--libio/stdio/feof_u.c37
-rw-r--r--libio/stdio/ferror_u.c37
-rw-r--r--libio/stdio/fgetc.c36
-rw-r--r--libio/stdio/fileno.c43
-rw-r--r--libio/stdio/fputc.c38
-rw-r--r--libio/stdio/fputc_u.c38
-rw-r--r--libio/stdio/freopen.c36
-rw-r--r--libio/stdio/fseek.c38
-rw-r--r--libio/stdio/getc_u.c37
-rw-r--r--libio/stdio/getchar.c32
-rw-r--r--libio/stdio/getchar_u.c35
-rw-r--r--libio/stdio/putc_u.c31
-rw-r--r--libio/stdio/putchar.c29
-rw-r--r--libio/stdio/putchar_u.c30
-rw-r--r--libio/stdio/rewind.c38
-rw-r--r--libio/stdio/setbuf.c30
-rw-r--r--libio/stdio/setlinebuf.c29
-rw-r--r--libio/stdio/vscanf.c57
-rw-r--r--libio/stdio/vsnprintf.c153
23 files changed, 828 insertions, 91 deletions
diff --git a/libio/stdio/ChangeLog b/libio/stdio/ChangeLog
index 76ce5b7..788c055 100644
--- a/libio/stdio/ChangeLog
+++ b/libio/stdio/ChangeLog
@@ -1,3 +1,44 @@
+1997-09-04 16:11 Ulrich Drepper <drepper@cygnus.com>
+
+ * Makefile.in (STDIO_OBJECTS): Lose feof.o and ferror.o. Add getc.o
+ and putc.o.
+ (stmp-libio, stmp-libiostream, stmp-io, stmp-streamlib): New rules.
+
+ (iostream.list): Depend upon stmp-stdio. Add the entries
+ from stdio.list to iostream.list.
+ (stmp-stdio): New name for what was the stdio/stdio.list rule.
+ All it now does is cd down into stdio and build stdio.list.
+
+ * clearerr.c: Add copyright and lock stream before use.
+ * feof.c: Likewise.
+ * ferror.c: Likewise.
+ * fgetc.c: Likewise.
+ * fputc.c: Likewise.
+ * freopen.c: Likewise.
+ * fseek.c: Likewise.
+ * getc.c: Likewise.
+ * getchar.c: Likewise.
+ * putc.c: Likewise.
+ * putchar.c: Likewise.
+ * rewind.c: Likewise.
+
+ * setbuf.c: Update copyright.
+ * setlinebuf.c: Likewise.
+ * vscanf.c: Likewise.
+
+ * fileno.c: Define alias fileno_unlocked. Update copyright.
+
+ * clearerr_u.c: New file. Implement clearerr_unlocked function.
+ * feof_u.c: New file. Implement feof_unlocked function.
+ * ferror_u.c: New file. Implement ferror_unlocked function.
+ * fputc_u.c: New file. Implement fputc_unlocked function.
+ * getc_u.c: New file. Implement getc_unclocked function.
+ * getchar_u.c: New file. Implement getchar_unclocked function.
+ * putc_u.c: New file. Implement putc_unclocked function.
+ * putchar_u.c: New file. Implement putchar_unclocked function.
+
+ * vsnprintf.c: Rewrite according to ISO C 9X draft.
+
Thu May 1 11:03:45 1997 Brendan Kehoe <brendan@lisa.cygnus.com>
* stdio.h (TMP_MAX): Wrap it with #ifndef for now, since it can
diff --git a/libio/stdio/Makefile.in b/libio/stdio/Makefile.in
index 8df66a7..680c8a4 100644
--- a/libio/stdio/Makefile.in
+++ b/libio/stdio/Makefile.in
@@ -7,9 +7,9 @@ srcdir = .
STDIO_RENAMED_OBJECTS = ... filled in by configure ...
# These are the files that a libc would want.
STDIO_OBJECTS = $(STDIO_RENAMED_OBJECTS) \
- clearerr.o fdopen.o feof.o ferror.o fgetc.o fileno.o \
- fputc.o freopen.o fseek.o getc.o getchar.o getline.o getw.o \
- popen.o putc.o putchar.o putw.o rewind.o \
+ clearerr.o fdopen.o fgetc.o fileno.o \
+ fputc.o freopen.o fseek.o getchar.o getline.o getw.o \
+ popen.o putchar.o putw.o rewind.o \
setbuf.o setfileno.o setlinebuf.o snprintf.o \
vfprintf.o vfscanf.o vprintf.o vscanf.o vsnprintf.o
@@ -18,6 +18,18 @@ CINCLUDES = -I. -I$(srcdir) -I.. -I$(srcdir)/.. -D__USE_GNU
nothing:
+stmp-libio: stdio.list stamp-io
+
+stamp-io:
+ $(AR) $(AR_FLAGS) ../libio.a $(STDIO_OBJECTS)
+ touch stmp-io
+
+stmp-libiostream: stdio.list stamp-streamlib
+
+stamp-streamlib:
+ $(AR) $(AR_FLAGS) ../libiostream.a $(STDIO_OBJECTS)
+ touch stmp-streamlib
+
stdio.list: stamp-picdir $(STDIO_OBJECTS)
@echo "$(STDIO_OBJECTS)" >stdio.list
diff --git a/libio/stdio/clearerr.c b/libio/stdio/clearerr.c
index ee9780b..4776250 100644
--- a/libio/stdio/clearerr.c
+++ b/libio/stdio/clearerr.c
@@ -1,10 +1,30 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
#include "libioP.h"
#include "stdio.h"
void
-clearerr(fp)
- FILE* fp;
+clearerr (fp)
+ FILE *fp;
{
- CHECK_FILE(fp, /*nothing*/);
- _IO_clearerr(fp);
+ CHECK_FILE (fp, /*nothing*/);
+ _IO_flockfile (fp);
+ _IO_clearerr (fp);
+ _IO_funlockfile (fp);
}
diff --git a/libio/stdio/clearerr_u.c b/libio/stdio/clearerr_u.c
new file mode 100644
index 0000000..2a1ba70
--- /dev/null
+++ b/libio/stdio/clearerr_u.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "libioP.h"
+#include "stdio.h"
+
+void
+clearerr_unlocked (fp)
+ FILE *fp;
+{
+ CHECK_FILE (fp, /*nothing*/);
+ _IO_clearerr (fp);
+}
diff --git a/libio/stdio/feof_u.c b/libio/stdio/feof_u.c
new file mode 100644
index 0000000..4773599
--- /dev/null
+++ b/libio/stdio/feof_u.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1993, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
+#include "stdio.h"
+
+#undef feof_unlocked
+
+int
+feof_unlocked (fp)
+ _IO_FILE* fp;
+{
+ CHECK_FILE (fp, EOF);
+ return _IO_feof_unlocked (fp);
+}
diff --git a/libio/stdio/ferror_u.c b/libio/stdio/ferror_u.c
new file mode 100644
index 0000000..6e13e53
--- /dev/null
+++ b/libio/stdio/ferror_u.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1993, 1995, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
+#include "stdio.h"
+
+#undef ferror_unlocked
+
+int
+ferror_unlocked (fp)
+ _IO_FILE* fp;
+{
+ CHECK_FILE (fp, EOF);
+ return _IO_ferror_unlocked (fp);
+}
diff --git a/libio/stdio/fgetc.c b/libio/stdio/fgetc.c
index cf6410a..174e60f 100644
--- a/libio/stdio/fgetc.c
+++ b/libio/stdio/fgetc.c
@@ -1,10 +1,40 @@
+/* Copyright (C) 1993, 1995, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
int
-fgetc(fp)
+fgetc (fp)
FILE *fp;
{
- CHECK_FILE(fp, EOF);
- return _IO_getc(fp);
+ int result;
+ CHECK_FILE (fp, EOF);
+ _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+ _IO_flockfile (fp);
+ result = _IO_getc_unlocked (fp);
+ _IO_cleanup_region_end (1);
+ return result;
}
diff --git a/libio/stdio/fileno.c b/libio/stdio/fileno.c
index c0bc55c..7ff93e6 100644
--- a/libio/stdio/fileno.c
+++ b/libio/stdio/fileno.c
@@ -1,12 +1,49 @@
+/* Copyright (C) 1993, 1995, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
int
-fileno(fp)
+fileno (fp)
_IO_FILE* fp;
{
- CHECK_FILE(fp, EOF);
+ CHECK_FILE (fp, EOF);
+
if (!(fp->_flags & _IO_IS_FILEBUF))
return EOF;
- return _IO_fileno(fp);
+
+ return _IO_fileno (fp);
}
+
+#ifdef _IO_MTSAFE_IO
+#ifdef weak_alias
+/* The fileno implementation for libio does not require locking because
+ it only accesses once a single variable and this is already atomic
+ (at least at thread level). */
+
+weak_alias (fileno, fileno_unlocked)
+#endif
+#endif
diff --git a/libio/stdio/fputc.c b/libio/stdio/fputc.c
index e87b042..22cdfab 100644
--- a/libio/stdio/fputc.c
+++ b/libio/stdio/fputc.c
@@ -1,11 +1,41 @@
+/* Copyright (C) 1993, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
int
-fputc(c, fp)
+fputc (c, fp)
int c;
- FILE *fp;
+ _IO_FILE *fp;
{
- CHECK_FILE(fp, EOF);
- return _IO_putc(c, fp);
+ int result;
+ CHECK_FILE (fp, EOF);
+ _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+ _IO_flockfile (fp);
+ result = _IO_putc_unlocked (c, fp);
+ _IO_cleanup_region_end (1);
+ return result;
}
diff --git a/libio/stdio/fputc_u.c b/libio/stdio/fputc_u.c
new file mode 100644
index 0000000..48701e1
--- /dev/null
+++ b/libio/stdio/fputc_u.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1993, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
+#include "stdio.h"
+
+#undef fputc_unlocked
+
+int
+fputc_unlocked (c, fp)
+ int c;
+ _IO_FILE *fp;
+{
+ CHECK_FILE (fp, EOF);
+ return _IO_putc_unlocked (c, fp);
+}
diff --git a/libio/stdio/freopen.c b/libio/stdio/freopen.c
index da3dc1d..ff57d60 100644
--- a/libio/stdio/freopen.c
+++ b/libio/stdio/freopen.c
@@ -1,14 +1,44 @@
+/* Copyright (C) 1993, 1995, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
FILE*
-freopen(filename, mode, fp)
+freopen (filename, mode, fp)
const char* filename;
const char* mode;
FILE* fp;
{
- CHECK_FILE(fp, NULL);
+ FILE *result;
+ CHECK_FILE (fp, NULL);
if (!(fp->_flags & _IO_IS_FILEBUF))
return NULL;
- return _IO_freopen(filename, mode, fp);
+ _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+ _IO_flockfile (fp);
+ result = _IO_freopen (filename, mode, fp);
+ _IO_cleanup_region_end (1);
+ return result;
}
diff --git a/libio/stdio/fseek.c b/libio/stdio/fseek.c
index b80067d..f2563d3 100644
--- a/libio/stdio/fseek.c
+++ b/libio/stdio/fseek.c
@@ -1,12 +1,42 @@
-#include "stdio.h"
+/* Copyright (C) 1993, 1995, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
+#include "stdio.h"
int
-fseek(fp, offset, whence)
+fseek (fp, offset, whence)
_IO_FILE* fp;
long int offset;
int whence;
{
- CHECK_FILE(fp, -1);
- return _IO_fseek(fp, offset, whence);
+ int result;
+ CHECK_FILE (fp, -1);
+ _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+ _IO_flockfile (fp);
+ result = _IO_fseek (fp, offset, whence);
+ _IO_cleanup_region_end (1);
+ return result;
}
diff --git a/libio/stdio/getc_u.c b/libio/stdio/getc_u.c
new file mode 100644
index 0000000..f074427
--- /dev/null
+++ b/libio/stdio/getc_u.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1993, 1995, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
+#include "stdio.h"
+
+#undef getc_unlocked
+
+int
+getc_unlocked (fp)
+ FILE *fp;
+{
+ CHECK_FILE (fp, EOF);
+ return _IO_getc_unlocked (fp);
+}
diff --git a/libio/stdio/getchar.c b/libio/stdio/getchar.c
index 88610dc..93194b3 100644
--- a/libio/stdio/getchar.c
+++ b/libio/stdio/getchar.c
@@ -1,3 +1,28 @@
+/* Copyright (C) 1993, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
@@ -6,5 +31,10 @@
int
getchar ()
{
- return _IO_getc (stdin);
+ int result;
+ _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, stdin);
+ _IO_flockfile (stdin);
+ result = _IO_getc_unlocked (stdin);
+ _IO_cleanup_region_end (1);
+ return result;
}
diff --git a/libio/stdio/getchar_u.c b/libio/stdio/getchar_u.c
new file mode 100644
index 0000000..bfbe56b
--- /dev/null
+++ b/libio/stdio/getchar_u.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1993, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
+#include "stdio.h"
+
+#undef getchar_unlocked
+
+int
+getchar_unlocked ()
+{
+ return _IO_getc_unlocked (stdin);
+}
diff --git a/libio/stdio/putc_u.c b/libio/stdio/putc_u.c
new file mode 100644
index 0000000..b4d94e8
--- /dev/null
+++ b/libio/stdio/putc_u.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "libioP.h"
+#include "stdio.h"
+
+#undef putc_unlocked
+
+int
+putc_unlocked (c, fp)
+ int c;
+ _IO_FILE *fp;
+{
+ CHECK_FILE (fp, EOF);
+ return _IO_putc_unlocked (c, fp);
+}
diff --git a/libio/stdio/putchar.c b/libio/stdio/putchar.c
index a0a972f..f97af04 100644
--- a/libio/stdio/putchar.c
+++ b/libio/stdio/putchar.c
@@ -1,10 +1,35 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
#include "libioP.h"
#include "stdio.h"
+
#undef putchar
int
-putchar(c)
+putchar (c)
int c;
{
- return _IO_putc(c, stdout);
+ int result;
+ _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+ _IO_stdout);
+ _IO_flockfile (_IO_stdout);
+ result = _IO_putc_unlocked (c, _IO_stdout);
+ _IO_cleanup_region_end (1);
+ return result;
}
diff --git a/libio/stdio/putchar_u.c b/libio/stdio/putchar_u.c
new file mode 100644
index 0000000..f8f387a
--- /dev/null
+++ b/libio/stdio/putchar_u.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "libioP.h"
+#include "stdio.h"
+
+#undef putchar_unlocked
+
+int
+putchar_unlocked (c)
+ int c;
+{
+ CHECK_FILE (stdout, EOF);
+ return _IO_putc_unlocked (c, stdout);
+}
diff --git a/libio/stdio/rewind.c b/libio/stdio/rewind.c
index 01fe20a..bce2757 100644
--- a/libio/stdio/rewind.c
+++ b/libio/stdio/rewind.c
@@ -1,10 +1,38 @@
-#include "stdio.h"
+/* Copyright (C) 1993, 1996, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
+#include "stdio.h"
void
-rewind(fp)
- _IO_FILE* fp;
+rewind (fp)
+ _IO_FILE *fp;
{
- CHECK_FILE(fp, );
- _IO_rewind(fp);
+ CHECK_FILE (fp, );
+ _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+ _IO_flockfile (fp);
+ _IO_rewind (fp);
+ _IO_cleanup_region_end (1);
}
diff --git a/libio/stdio/setbuf.c b/libio/stdio/setbuf.c
index 5002e3d..ac323a3 100644
--- a/libio/stdio/setbuf.c
+++ b/libio/stdio/setbuf.c
@@ -1,9 +1,35 @@
+/* Copyright (C) 1993, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
void
setbuf (fp, buf)
- FILE *fp; char *buf;
+ _IO_FILE *fp;
+ char *buf;
{
- _IO_setbuffer(fp, buf, _IO_BUFSIZ);
+ _IO_setbuffer (fp, buf, _IO_BUFSIZ);
}
diff --git a/libio/stdio/setlinebuf.c b/libio/stdio/setlinebuf.c
index c447f95..e4e029f 100644
--- a/libio/stdio/setlinebuf.c
+++ b/libio/stdio/setlinebuf.c
@@ -1,3 +1,28 @@
+/* Copyright (C) 1993, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
@@ -5,7 +30,7 @@
void
setlinebuf (stream)
- FILE *stream;
+ _IO_FILE *stream;
{
- _IO_setvbuf(stream, NULL, 1, 0);
+ _IO_setvbuf (stream, NULL, 1, 0);
}
diff --git a/libio/stdio/vscanf.c b/libio/stdio/vscanf.c
index 4ef4b52..8b92ae2 100644
--- a/libio/stdio/vscanf.c
+++ b/libio/stdio/vscanf.c
@@ -1,34 +1,41 @@
-/*
-Copyright (C) 1993 Free Software Foundation
-
-This file is part of the GNU IO Library. This library is free
-software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-As a special exception, if you link this library with files
-compiled with a GNU compiler to produce an executable, this does not cause
-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. */
+/* Copyright (C) 1993, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "stdio.h"
+#undef vscanf
+
int
-vscanf(format, args)
+_IO_vscanf (format, args)
const char *format;
_IO_va_list args;
{
- return _IO_vfscanf(_IO_stdin, format, args, NULL);
+ return _IO_vfscanf (_IO_stdin, format, args, NULL);
}
+
+#ifdef weak_alias
+weak_alias (_IO_vscanf, vscanf)
+#endif
diff --git a/libio/stdio/vsnprintf.c b/libio/stdio/vsnprintf.c
index 8db41b7..3f35af2 100644
--- a/libio/stdio/vsnprintf.c
+++ b/libio/stdio/vsnprintf.c
@@ -1,43 +1,136 @@
-/*
-Copyright (C) 1994 Free Software Foundation
-
-This file is part of the GNU IO Library. This library is free
-software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-As a special exception, if you link this library with files
-compiled with a GNU compiler to produce an executable, this does not cause
-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. */
+/* Copyright (C) 1994, 1997 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 terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA.
+
+ As a special exception, if you link this library with files
+ compiled with a GNU compiler to produce an executable, this does
+ not cause 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 "libioP.h"
#include "strfile.h"
+
+typedef struct
+{
+ _IO_strfile f;
+ /* This is used for the characters which do not fit in the buffer
+ provided by the user. */
+ char overflow_buf[64];
+} _IO_strnfile;
+
+
+static int _IO_strn_overflow __P ((_IO_FILE *fp, int c));
+
+static int
+_IO_strn_overflow (fp, c)
+ _IO_FILE *fp;
+ int c;
+{
+ /* When we come to here this means the user supplied buffer is
+ filled. But since we must return the number of characters which
+ would have been written in total we must provide a buffer for
+ further use. We can do this by writing on and on in the overflow
+ buffer in the _IO_strnfile structure. */
+ _IO_strnfile *snf = (_IO_strnfile *) fp;
+
+ if (fp->_IO_buf_base != snf->overflow_buf)
+ {
+ /* Terminate the string. We know that there is room for at
+ least one more character since we initialized the stream with
+ a size to make this possible. */
+ *fp->_IO_write_ptr = '\0';
+
+ _IO_setb (fp, snf->overflow_buf,
+ snf->overflow_buf + sizeof (snf->overflow_buf), 0);
+
+ fp->_IO_write_base = snf->overflow_buf;
+ fp->_IO_read_base = snf->overflow_buf;
+ fp->_IO_read_ptr = snf->overflow_buf;
+ fp->_IO_read_end = snf->overflow_buf + sizeof (snf->overflow_buf);
+ }
+
+ fp->_IO_write_ptr = snf->overflow_buf;
+ fp->_IO_write_end = snf->overflow_buf;
+
+ /* Since we are not really interested in storing the characters
+ which do not fit in the buffer we simply ignore it. */
+ return c;
+}
+
+
+static struct _IO_jump_t _IO_strn_jumps =
+{
+ JUMP_INIT_DUMMY,
+ JUMP_INIT(finish, _IO_str_finish),
+ JUMP_INIT(overflow, _IO_strn_overflow),
+ JUMP_INIT(underflow, _IO_str_underflow),
+ JUMP_INIT(uflow, _IO_default_uflow),
+ JUMP_INIT(pbackfail, _IO_str_pbackfail),
+ JUMP_INIT(xsputn, _IO_default_xsputn),
+ JUMP_INIT(xsgetn, _IO_default_xsgetn),
+ JUMP_INIT(seekoff, _IO_str_seekoff),
+ JUMP_INIT(seekpos, _IO_default_seekpos),
+ JUMP_INIT(setbuf, _IO_default_setbuf),
+ JUMP_INIT(sync, _IO_default_sync),
+ JUMP_INIT(doallocate, _IO_default_doallocate),
+ JUMP_INIT(read, _IO_default_read),
+ JUMP_INIT(write, _IO_default_write),
+ JUMP_INIT(seek, _IO_default_seek),
+ JUMP_INIT(close, _IO_default_close),
+ JUMP_INIT(stat, _IO_default_stat)
+};
+
+
int
-vsnprintf (string, maxlen, format, args)
+_IO_vsnprintf (string, maxlen, format, args)
char *string;
_IO_size_t maxlen;
const char *format;
_IO_va_list args;
{
- _IO_strfile sf;
+ _IO_strnfile sf;
int ret;
- _IO_init((_IO_FILE*)&sf, 0);
- _IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps;
- _IO_str_init_static ((_IO_FILE*)&sf, string, maxlen - 1, string);
- ret = _IO_vfprintf((_IO_FILE*)&sf, format, args);
- *((_IO_FILE*)&sf)->_IO_write_ptr = '\0';
+#ifdef _IO_MTSAFE_IO
+ _IO_lock_t lock;
+ sf.f._sbf._f._lock = &lock;
+#endif
+
+ /* We need to handle the special case where MAXLEN is 0. Use the
+ overflow buffer right from the start. */
+ if (maxlen == 0)
+ {
+ string = sf.overflow_buf;
+ maxlen = sizeof (sf.overflow_buf);
+ }
+
+ _IO_init ((_IO_FILE *) &sf, 0);
+ _IO_JUMPS ((_IO_FILE *) &sf) = &_IO_strn_jumps;
+ _IO_str_init_static ((_IO_FILE *) &sf, string, maxlen - 1, string);
+ ret = _IO_vfprintf ((_IO_FILE *) &sf, format, args);
+
+ if (sf.f._sbf._f._IO_buf_base != sf.overflow_buf)
+ *sf.f._sbf._f._IO_write_ptr = '\0';
return ret;
}
+
+#ifdef weak_alias
+weak_alias (_IO_vsnprintf, __vsnprintf)
+weak_alias (_IO_vsnprintf, vsnprintf)
+#endif