Insert libio rewrite and its various changes from devo.
authorBrendan Kehoe <brendan@gcc.gnu.org>
Sat, 6 Sep 1997 07:44:38 +0000 (03:44 -0400)
committerBrendan Kehoe <brendan@gcc.gnu.org>
Sat, 6 Sep 1997 07:44:38 +0000 (03:44 -0400)
From-SVN: r15129

72 files changed:
libio/ChangeLog
libio/Makefile.in
libio/configure.in
libio/filedoalloc.c
libio/fileops.c
libio/genops.c
libio/include/empty.h [new file with mode: 0644]
libio/iofclose.c
libio/iofdopen.c
libio/iofeof.c [new file with mode: 0644]
libio/ioferror.c [new file with mode: 0644]
libio/iofflush.c
libio/iofflush_u.c [new file with mode: 0644]
libio/iofgetpos.c
libio/iofgets.c
libio/iofopen.c
libio/iofprintf.c
libio/iofputs.c
libio/iofread.c
libio/iofsetpos.c
libio/ioftell.c
libio/iofwrite.c
libio/iogetc.c [new file with mode: 0644]
libio/iogetdelim.c
libio/iogetline.c
libio/iogets.c
libio/iopadn.c
libio/iopopen.c
libio/ioputc.c [new file with mode: 0644]
libio/ioputs.c
libio/ioseekoff.c
libio/ioseekpos.c
libio/iosetbuffer.c
libio/iosetvbuf.c
libio/iosprintf.c
libio/iostream.h
libio/ioungetc.c
libio/iovsprintf.c
libio/iovsscanf.c
libio/libio.h
libio/libioP.h
libio/parsestream.cc
libio/peekc.c [new file with mode: 0644]
libio/stdfiles.c
libio/stdio-lock.h [new file with mode: 0644]
libio/stdio/ChangeLog
libio/stdio/Makefile.in
libio/stdio/clearerr.c
libio/stdio/clearerr_u.c [new file with mode: 0644]
libio/stdio/feof_u.c [new file with mode: 0644]
libio/stdio/ferror_u.c [new file with mode: 0644]
libio/stdio/fgetc.c
libio/stdio/fileno.c
libio/stdio/fputc.c
libio/stdio/fputc_u.c [new file with mode: 0644]
libio/stdio/freopen.c
libio/stdio/fseek.c
libio/stdio/getc_u.c [new file with mode: 0644]
libio/stdio/getchar.c
libio/stdio/getchar_u.c [new file with mode: 0644]
libio/stdio/putc_u.c [new file with mode: 0644]
libio/stdio/putchar.c
libio/stdio/putchar_u.c [new file with mode: 0644]
libio/stdio/rewind.c
libio/stdio/setbuf.c
libio/stdio/setlinebuf.c
libio/stdio/vscanf.c
libio/stdio/vsnprintf.c
libio/streambuf.cc
libio/streambuf.h
libio/strfile.h
libio/strops.c

index 5926479c8a26f5ebcc7d672084b77de5134cd9ef..bc9267442d21964e4a75bcb32aab74be3bdf5a27 100644 (file)
@@ -1,7 +1,180 @@
+Fri Sep  5 09:58:43 1997  Brendan Kehoe  <brendan@lisa.cygnus.com>
+
+       * Makefile.in (iostream.list): Instead of adding stdio.list, add
+       STDIO_WRAP_OBJECTS.
+       (iostream.list): Lose dependency on stmp-stdio, not necessary for
+       our stuff.  The stdio stuff is present here just for uniformity
+       with glibc.
+
+Thu Sep  4 17:26:22 1997  Brendan Kehoe  <brendan@lisa.cygnus.com>
+
+       * parsestream.cc (general_parsebuf): Cast return of malloc to char*.
+
+1997-09-04 16:11  Ulrich Drepper  <drepper@cygnus.com>
+
+       Change compared to version initially intended to in:
+       * strops.c (_IO_str_count): Still use _IO_write_ptr, not
+       _IO_write_end, for now.
+
+       * iofeof.c, ioferror.c, iofflush_u.c, iogetc.c, ioputc.c, peekc.c,
+       stdio-lock.h: New files.
+
+       * include: New dir.
+       * include/empty.h: New header.
+
+       * filedoalloc.c: Update and reformat copyright.
+       Don't use DEFUN.
+       Use __set_errno throughout the code to support multi-threaded
+       programs.
+       Correct layout to follow the Coding Standard.
+       Add casts to prevent warnings.
+       * fileops.c: Likewise.
+       * genops.c: Likewise.
+       * iofclose.c: Likewise.
+       * iofdopen.c: Likewise.
+       * iofflush.c: Likewise.
+       * iofgetpos.c: Likewise.
+       * iofgets.c: Likewise.
+       * iofopen.c: Likewise.
+       * iofprintf.c: Likewise.
+       * iofputs.c: Likewise.
+       * iofread.c: Likewise.
+       * iofsetpos.c: Likewise.
+       * ioftell.c: Likewise.
+       * iofwrite.c: Likewise.
+       * iogetdelim.c: Likewise.
+       * iogetline.c: Likewise.
+       * iogets.c: Likewise.
+       * iopadn.c: Likewise.
+       * iopopen.c: Likewise.
+       * ioputs.c: Likewise.
+       * ioseekoff.c: Likewise.
+       * iosetbuffer.c: Likewise.
+       * iosetvbuf.c: Likewise.
+       * iosprintf.c: Likewise.
+       * ioungetc.c: Likewise.
+       * iovsprintf.c: Likewise.
+       * iovsscanf.c: Likewise.
+       * libio.h: Likewise.
+       * libioP.h: Likewise.
+       * stdfiles.c: Likewise.
+       * strfile.h: Likewise.
+       * strops.c: Likewise.
+
+       * Makefile.in (IO_OBJECTS): Add peekc.o, iogetc.o, ioputc.o,
+       iofeof.o, and ioferror.o.
+       (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.
+
+       * configure.in (ALL): Add libiostream.a.
+
+       * libio.h [_IO_MTSFE_IO]: Include header declaring locking code.
+       Otherwise define opaque _IO_lock_t.
+       Define _IO_cookie_file.
+       Rename _IO_getc to _IO_getc_unlocked, _IO_peekc to _IO_peekc_unlocked,
+       _IO_putc to _IO_putc_unlocked, _IO_feof to _IO_feof_unclocked, and
+       _IO_ferror to _IO_ferror_unlocked.
+       Add prototypes for _IO_getc, _IO_putc, _IO_feof, _IO_ferror,
+       and _IO_peekc_locked.
+       Add declarations for _IO_flockfile, _IO_funlockfile, and
+       _IO_ftrylockfile.  If !_IO_MTSAFE_IO define _IO_flockfile,
+       _IO_funlockfile, _IO_ftrylockfile, _IO_cleanup_region_start, and
+       _IO_cleanup_region_end as empty macros.
+
+       * libioP.h: Change type of finish function to take an additional int
+       argument and change declaration of finish functions.
+       Add prototypes for _IO_seekoff and _IO_seekpos.
+       If _G_HAVE_MMAP is defined use stream buffers allocated with mmap.
+       Redefine FREE_BUF and ALLOC_BUF macros to help in both situations.
+       (FILEBUF_LITERAL): If we compile for a thread-safe library also
+       initialize lock member.
+
+       * filedoalloc.c: Take care for systems already defining _POSIX_SOURCE.
+       Keep name space clean on systems which require this.
+       (_IO_file_doallocate): Adopt ALLOC_BUF call for changed semantic.
+
+       * fileops.c: Keep name space clean on systems which require this.
+       (_IO_file_attach): Don't fail if seek failed because it's used on a
+       pipe.
+       (_IO_file_underflow): Update buffer pointers before calling `read'
+       since the `read' might not return anymore.
+       (_IO_file_overflow): If stream allows no writes set error flag.
+       (_IO_seekoff): Make sure that after flushing the file pointer in
+       the underlying file is exact.
+       (_IO_file_read): Don't restart `read' syscall if it return EINTR.
+       This violates POSIX.
+       (_IO_file_write): Likewise for `write'.
+       (_IO_cleanup): Install as exit handler in glibc.
+
+       * genops.c (_IO_setb): Correctly use FREE_BUF.
+       (_IO_default_doallocate): Correctly use ALLOC_BUF.
+       (_IO_init): Initialize lock in stream structure.
+       (_IO_default_finish): Destroy lock.
+       (_IO_get_column): Don't compile since it's not needed.
+       (_IO_nobackup_default): Likewise.
+
+       * iopopen.c: Take care for systems already defining _POSIX_SOURCE.
+       Correct _IO_fork and _IO_dup2 prototypes.
+
+       * iofclose.c: Acquire lock before starting the work.
+       * iofflush.c: Likewise.
+       * iofgetpos.c: Likewise.
+       * iofgets.c: Likewise.
+       * iofputs.c: Likewise.
+       * iofread.c: Likewise.
+       * iofsetpos.c: Likewise.
+       * ioftell.c: Likewise.
+       * iofwrite.c: Likewise.
+       * iogetdelim.c: Likewise.
+       * iogets.c: Likewise.
+       * ioputs.c: Likewise.
+       * iosetbuffer.c: Likewise.
+       * iosetvbuf.c: Likewise.
+       * ioungetc.c: Likewise.
+
+       * iofdopen.c: Create and initialize lock for new stream.
+       * iofopen.c: Likewise.
+       * iopopen.c (_IO_popen): Likewise.
+       * iovsprintf.c: Likewise.
+       * iovsscanf.c: Likewise.
+
+       * genops.c: Make weak aliases for various functions.
+       * iofclose.c: Likewise.
+       * iofdopen.c: Likewise.
+       * iofflush.c: Likewise.
+       * iofgetpos.c: Likewise.
+       * iofgets.c: Likewise.
+       * iofopen.c: Likewise.
+       * iofputs.c: Likewise.
+       * iofread.c: Likewise.
+       * iofsetpos.c: Likewise.
+       * ioftell.c: Likewise.
+       * iofwrite.c: Likewise.
+       * iogetdelim.c: Likewise.
+       * iogets.c: Likewise.
+       * ioputs.c: Likewise.
+       * iosetbuffer.c: Likewise.
+       * iosetvbuf.c: Likewise.
+       * ioungetc.c: Likewise.
+       * iovsprintf.c: Likewise.
+       * iovsscanf.c: Likewise.
+
+       * iofflush_u.c: New file.  fflush_unlocked implementation.
+
+       * iostream.h [_G_HAVE_LONG_DOUBLE_IO]: Declare real long double
+       output operator.
+
+       * peekc.c: New file.  Implement _IO_peekc_locked function.
+
+       * stdfiles.c: If we compile for a thread-safe library also define
+       lock variable.
+
 Tue Aug 26 12:24:01 1997  H.J. Lu  (hjl@gnu.ai.mit.edu)
 
-        * testsuite/Makefile.in (check): Don't depend on site.exp.
-        (just-check): Depend on site.exp.
+       * testsuite/Makefile.in (check): Don't depend on site.exp.
+       (just-check): Depend on site.exp.
 
 Wed Aug 20 02:01:34 1997  Jason Merrill  <jason@yorick.cygnus.com>
 
index ccf8f3ecc528f9b645b4f03c821d6a7325669bc3..aab8ac601282d889c0b9bf2b93202291c8b86b36 100644 (file)
@@ -29,7 +29,8 @@ IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \
   iofgetpos.o iofread.o iofscanf.o \
   iofsetpos.o iogetdelim.o iogetline.o \
   ioprintf.o ioseekoff.o ioseekpos.o \
-  outfloat.o strops.o iofclose.o iopopen.o ioungetc.o
+  outfloat.o strops.o iofclose.o iopopen.o ioungetc.o peekc.o iogetc.o \
+  ioputc.o iofeof.o ioferror.o
 
 # These emulate stdio functionality, but with a different name (_IO_ungetc
 # instead of ungetc), and using _IO_FILE instead of FILE.
@@ -40,7 +41,7 @@ IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \
 # iofclose.o is not here, because it is needed for stdio (by pclose).
 STDIO_WRAP_OBJECTS =  iofdopen.o iofflush.o iofgets.o iofopen.o iofprintf.o iofputs.o iofwrite.o \
   iogets.o ioperror.o ioputs.o ioscanf.o iosetbuffer.o iosetvbuf.o \
-  iosprintf.o iosscanf.o ioftell.o iovsprintf.o iovsscanf.o
+  iosprintf.o iosscanf.o ioftell.o iovsscanf.o iovsprintf.o
 
 IOSTREAM_OBJECTS = builtinbuf.o filebuf.o fstream.o \
   indstream.o ioassign.o ioextend.o iomanip.o iostream.o \
@@ -82,16 +83,12 @@ tpipe: tpipe.o libio.a
 
 iostream.list: stamp-picdir $(_G_CONFIG_H) $(LIBIOSTREAM_DEP)
        @echo "$(LIBIOSTREAM_USE)"> iostream.list
+       @echo "$(STDIO_WRAP_OBJECTS)" >> iostream.list
 
-stdio/stdio.list: force
+stmp-stdio:
        @rootme=`pwd`/ ; export rootme; cd stdio ; \
          $(MAKE) $(FLAGS_TO_PASS) stdio.list
 
-stdio.list: stdio/stdio.list
-       rm -f tstdio.list
-       sed 's,\([a-z_]*\.o\),stdio/\1,g' stdio/stdio.list > tstdio.list
-       mv tstdio.list stdio.list
-
 _G_config.h: ${srcdir}/gen-params
        rootme=`pwd`/ ; export rootme; \
        CC="$(CC)"; export CC; \
index d6359382bcfc96f5f839055973e72da5c23648ae..b14c3b17215500d23ea074b81312084a6c9ca040 100644 (file)
@@ -57,7 +57,7 @@ ${moveifchange} temp.mt target-mkfrag
 
 LIBDIR=yes
 TO_TOPDIR=../
-ALL='$(_G_CONFIG_H) libio.a iostream.list'
+ALL='$(_G_CONFIG_H) libio.a libiostream.a iostream.list'
 XCINCLUDES='-I. -I$(srcdir)'
 XCXXINCLUDES='-I. -I$(srcdir)'
 MOSTLYCLEAN='*.o pic stamp-picdir core iostream.list'
index f838bb3458f71ff2e41b48f4d8800c35acf6b1bb..f1b781e8a0fabfe3338ef7ba8a768d908c947eab 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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) 1990 The Regents of the University of California.
@@ -41,7 +42,9 @@ the executable file might be covered by the GNU General Public License. */
 
 /* Modified for GNU iostream by Per Bothner 1991, 1992. */
 
-#define _POSIX_SOURCE
+#ifndef _POSIX_SOURCE
+# define _POSIX_SOURCE
+#endif
 #include "libioP.h"
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -50,6 +53,11 @@ the executable file might be covered by the GNU General Public License. */
 #include <unistd.h>
 #endif
 
+#ifdef _LIBC
+# undef isatty
+# define isatty(Fd) __isatty (Fd)
+#endif
+
 /*
  * Allocate a file buffer, or switch to unbuffered I/O.
  * Per the ANSI C standard, ALL tty devices default to line buffered.
@@ -59,21 +67,23 @@ the executable file might be covered by the GNU General Public License. */
  */
 
 int
-DEFUN(_IO_file_doallocate, (fp),
-      register _IO_FILE *fp)
+_IO_file_doallocate (fp)
+     _IO_FILE *fp;
 {
-  register _IO_size_t size;
+  _IO_size_t size;
   int couldbetty;
-  register char *p;
+  char *p;
   struct stat st;
 
+#ifndef _LIBC
   /* If _IO_cleanup_registration_needed is non-zero, we should call the
      function it points to.  This is to make sure _IO_cleanup gets called
      on exit.  We call it from _IO_file_doallocate, since that is likely
      to get called by any program that does buffered I/O. */
   if (_IO_cleanup_registration_needed)
-    (*_IO_cleanup_registration_needed)();
-  
+    (*_IO_cleanup_registration_needed) ();
+#endif
+
   if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0)
     {
       couldbetty = 0;
@@ -85,18 +95,16 @@ DEFUN(_IO_file_doallocate, (fp),
     }
   else
     {
-      couldbetty = S_ISCHR(st.st_mode);
+      couldbetty = S_ISCHR (st.st_mode);
 #if _IO_HAVE_ST_BLKSIZE
       size = st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize;
 #else
       size = _IO_BUFSIZ;
 #endif
     }
-  p = ALLOC_BUF(size);
-  if (p == NULL)
-    return EOF;
-  _IO_setb(fp, p, p+size, 1);
-  if (couldbetty && isatty(fp->_fileno))
+  ALLOC_BUF (p, size, EOF);
+  _IO_setb (fp, p, p + size, 1);
+  if (couldbetty && isatty (fp->_fileno))
     fp->_flags |= _IO_LINE_BUF;
   return 1;
 }
index 812af94d0f95102513c6ffbd75a16db0d30cc34a..b3a3a24651fbe1cd92ae667ddc2fccec4112d8c9 100644 (file)
@@ -1,30 +1,33 @@
-/* 
-Copyright (C) 1993, 1995 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. */
-
-/*  written by Per Bothner (bothner@cygnus.com) */
-
-#define _POSIX_SOURCE
+/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
+   Written by Per Bothner <bothner@cygnus.com>.
+
+   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.  */
+
+
+#ifndef _POSIX_SOURCE
+# define _POSIX_SOURCE
+#endif
 #include "libioP.h"
 #include <fcntl.h>
 #include <sys/types.h>
@@ -35,11 +38,16 @@ the executable file might be covered by the GNU General Public License. */
 extern int errno;
 #endif
 
+
+#ifdef _LIBC
+# define open(Name, Flags, Prot) __open ((Name), (Flags), (Prot))
+#endif
+
 /* An fstream can be in at most one of put mode, get mode, or putback mode.
    Putback mode is a variant of get mode.
 
    In a filebuf, there is only one current position, instead of two
-   separate get and put pointers.  In get mode, the current posistion
+   separate get and put pointers.  In get mode, the current position
    is that of gptr(); in put mode that of pptr().
 
    The position in the buffer that corresponds to the position
@@ -73,14 +81,14 @@ extern int errno;
    (The pointers save_gptr() and save_egptr() are the values
    of gptr() and egptr() at the time putback mode was entered.)
    The OS position corresponds to that of save_egptr().
-   
+
    LINE BUFFERED OUTPUT:
    During line buffered output, _IO_write_base==base() && epptr()==base().
    However, ptr() may be anywhere between base() and ebuf().
    This forces a call to filebuf::overflow(int C) on every put.
    If there is more space in the buffer, and C is not a '\n',
    then C is inserted, and pptr() incremented.
-   
+
    UNBUFFERED STREAMS:
    If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer.
 */
@@ -90,8 +98,8 @@ extern int errno;
 
 
 void
-DEFUN(_IO_file_init, (fp),
-      register _IO_FILE *fp)
+_IO_file_init (fp)
+     _IO_FILE *fp;
 {
   /* POSIX.1 allows another file handle to be used to change the position
      of our file descriptor.  Hence we actually don't know the actual
@@ -104,11 +112,11 @@ DEFUN(_IO_file_init, (fp),
 }
 
 int
-DEFUN(_IO_file_close_it, (fp),
-      register _IO_FILE* fp)
+_IO_file_close_it (fp)
+     _IO_FILE *fp;
 {
   int write_status, close_status;
-  if (!_IO_file_is_open(fp))
+  if (!_IO_file_is_open (fp))
     return EOF;
 
   write_status = _IO_do_flush (fp);
@@ -118,11 +126,11 @@ DEFUN(_IO_file_close_it, (fp),
   close_status = _IO_SYSCLOSE (fp);
 
   /* Free buffer. */
-  _IO_setb(fp, NULL, NULL, 0);
-  _IO_setg(fp, NULL, NULL, NULL);
-  _IO_setp(fp, NULL, NULL);
+  _IO_setb (fp, NULL, NULL, 0);
+  _IO_setg (fp, NULL, NULL, NULL);
+  _IO_setp (fp, NULL, NULL);
 
-  _IO_un_link(fp);
+  _IO_un_link (fp);
   fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
   fp->_fileno = EOF;
   fp->_offset = _IO_pos_BAD;
@@ -131,86 +139,99 @@ DEFUN(_IO_file_close_it, (fp),
 }
 
 void
-DEFUN(_IO_file_finish, (fp),
-      register _IO_FILE* fp)
+_IO_file_finish (fp, dummy)
+     _IO_FILE *fp;
+     int dummy;
 {
-  if (_IO_file_is_open(fp))
+  if (_IO_file_is_open (fp))
     {
       _IO_do_flush (fp);
       if (!(fp->_flags & _IO_DELETE_DONT_CLOSE))
        _IO_SYSCLOSE (fp);
     }
-  _IO_default_finish(fp);
+  _IO_default_finish (fp, 0);
 }
 
 _IO_FILE *
-DEFUN(_IO_file_fopen, (fp, filename, mode),
-      register _IO_FILE *fp AND const char *filename AND const char *mode)
+_IO_file_fopen (fp, filename, mode)
+     _IO_FILE *fp;
+     const char *filename;
+     const char *mode;
 {
   int oflags = 0, omode;
   int read_write, fdesc;
   int oprot = 0666;
   if (_IO_file_is_open (fp))
     return 0;
-  switch (*mode++) {
-  case 'r':
-    omode = O_RDONLY;
-    read_write = _IO_NO_WRITES;
-    break;
-  case 'w':
-    omode = O_WRONLY;
-    oflags = O_CREAT|O_TRUNC;
-    read_write = _IO_NO_READS;
-    break;
-  case 'a':
-    omode = O_WRONLY;
-    oflags = O_CREAT|O_APPEND;
-    read_write = _IO_NO_READS|_IO_IS_APPENDING;
-    break;
-  default:
-    errno = EINVAL;
-    return NULL;
-  }
-  if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) {
-    omode = O_RDWR;
-    read_write &= _IO_IS_APPENDING;
-  }
-  fdesc = open(filename, omode|oflags, oprot);
+  switch (*mode++)
+    {
+    case 'r':
+      omode = O_RDONLY;
+      read_write = _IO_NO_WRITES;
+      break;
+    case 'w':
+      omode = O_WRONLY;
+      oflags = O_CREAT|O_TRUNC;
+      read_write = _IO_NO_READS;
+      break;
+    case 'a':
+      omode = O_WRONLY;
+      oflags = O_CREAT|O_APPEND;
+      read_write = _IO_NO_READS|_IO_IS_APPENDING;
+      break;
+    default:
+      __set_errno (EINVAL);
+      return NULL;
+    }
+  if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
+    {
+      omode = O_RDWR;
+      read_write &= _IO_IS_APPENDING;
+    }
+  fdesc = open (filename, omode|oflags, oprot);
   if (fdesc < 0)
     return NULL;
   fp->_fileno = fdesc;
-  _IO_mask_flags(fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
+  _IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
   if (read_write & _IO_IS_APPENDING)
     if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT)
-       == _IO_pos_BAD)
+       == _IO_pos_BAD && errno != ESPIPE)
       return NULL;
-  _IO_link_in(fp);
+  _IO_link_in (fp);
   return fp;
 }
 
-_IO_FILE*
-DEFUN(_IO_file_attach, (fp, fd),
-      _IO_FILE *fp AND int fd)
+_IO_FILE *
+_IO_file_attach (fp, fd)
+     _IO_FILE *fp;
+     int fd;
 {
-  if (_IO_file_is_open(fp))
+  if (_IO_file_is_open (fp))
     return NULL;
   fp->_fileno = fd;
   fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES);
   fp->_flags |= _IO_DELETE_DONT_CLOSE;
+  /* Get the current position of the file. */
+  /* We have to do that since that may be junk. */
   fp->_offset = _IO_pos_BAD;
+  if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT)
+      == _IO_pos_BAD && errno != ESPIPE)
+    return NULL;
   return fp;
 }
 
-_IO_FILE*
-DEFUN(_IO_file_setbuf, (fp, p, len),
-      register _IO_FILE *fp AND char* p AND _IO_ssize_t len)
+_IO_FILE *
+_IO_file_setbuf (fp, p, len)
+     _IO_FILE *fp;
+     char *p;
+     _IO_ssize_t len;
 {
-    if (_IO_default_setbuf(fp, p, len) == NULL)
-       return NULL;
+    if (_IO_default_setbuf (fp, p, len) == NULL)
+      return NULL;
 
     fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
       = fp->_IO_buf_base;
-    _IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
+    _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
 
     return fp;
 }
@@ -219,44 +240,42 @@ DEFUN(_IO_file_setbuf, (fp, p, len),
    Then mark FP as having empty buffers. */
 
 int
-DEFUN(_IO_do_write, (fp, data, to_do),
-      register _IO_FILE *fp AND const char* data AND _IO_size_t to_do)
+_IO_do_write (fp, data, to_do)
+     _IO_FILE *fp;
+     const char *data;
+     _IO_size_t to_do;
 {
   _IO_size_t count;
   if (to_do == 0)
     return 0;
-  else
+  if (fp->_flags & _IO_IS_APPENDING)
+    /* On a system without a proper O_APPEND implementation,
+       you would need to sys_seek(0, SEEK_END) here, but is
+       is not needed nor desirable for Unix- or Posix-like systems.
+       Instead, just indicate that offset (before and after) is
+       unpredictable. */
+    fp->_offset = _IO_pos_BAD;
+  else if (fp->_IO_read_end != fp->_IO_write_base)
     {
-      if (fp->_flags & _IO_IS_APPENDING)
-       /* On a system without a proper O_APPEND implementation,
-          you would need to sys_seek(0, SEEK_END) here, but is
-          is not needed nor desirable for Unix- or Posix-like systems.
-          Instead, just indicate that offset (before and after) is
-          unpredictable. */
-       fp->_offset = _IO_pos_BAD;
-      else if (fp->_IO_read_end != fp->_IO_write_base)
-       { 
-         _IO_pos_t new_pos
-           = _IO_SYSSEEK(fp, fp->_IO_write_base - fp->_IO_read_end, 1);
-         if (new_pos == _IO_pos_BAD)
-           return EOF;
-         fp->_offset = new_pos;
-       }
-      count = _IO_SYSWRITE (fp, data, to_do);
-      if (fp->_cur_column)
-       fp->_cur_column
-         = _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1;
+      _IO_pos_t new_pos
+       = _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1);
+      if (new_pos == _IO_pos_BAD)
+       return EOF;
+      fp->_offset = new_pos;
     }
-  _IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
+  count = _IO_SYSWRITE (fp, data, to_do);
+  if (fp->_cur_column)
+    fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1;
+  _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
   fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
-  fp->_IO_write_end = (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) ? fp->_IO_buf_base
-    : fp->_IO_buf_end;
+  fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+                      ? fp->_IO_buf_base : fp->_IO_buf_end);
   return count != to_do ? EOF : 0;
 }
 
 int
-DEFUN(_IO_file_underflow, (fp),
-      register _IO_FILE *fp)
+_IO_file_underflow (fp)
+     _IO_FILE *fp;
 {
   _IO_ssize_t count;
 #if 0
@@ -266,19 +285,31 @@ DEFUN(_IO_file_underflow, (fp),
 #endif
 
   if (fp->_flags & _IO_NO_READS)
-    return EOF;
+    {
+      __set_errno (EBADF);
+      return EOF;
+    }
   if (fp->_IO_read_ptr < fp->_IO_read_end)
-    return *(unsigned char*)fp->_IO_read_ptr;
+    return *(unsigned char *) fp->_IO_read_ptr;
 
   if (fp->_IO_buf_base == NULL)
-    _IO_doallocbuf(fp);
+    _IO_doallocbuf (fp);
 
   /* Flush all line buffered files before reading. */
   /* FIXME This can/should be moved to genops ?? */
   if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
-    _IO_flush_all_linebuffered();
+    _IO_flush_all_linebuffered ();
 
-  _IO_switch_to_get_mode(fp);
+  _IO_switch_to_get_mode (fp);
+
+  /* This is very tricky. We have to adjust those
+     pointers before we call _IO_SYSREAD () since
+     we may longjump () out while waiting for
+     input. Those pointers may be screwed up. H.J. */
+  fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
+  fp->_IO_read_end = fp->_IO_buf_base;
+  fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
+    = fp->_IO_buf_base;
 
   count = _IO_SYSREAD (fp, fp->_IO_buf_base,
                       fp->_IO_buf_end - fp->_IO_buf_base);
@@ -289,30 +320,32 @@ DEFUN(_IO_file_underflow, (fp),
       else
        fp->_flags |= _IO_ERR_SEEN, count = 0;
   }
-  fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
-  fp->_IO_read_end = fp->_IO_buf_base + count;
-  fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
-    = fp->_IO_buf_base;
+  fp->_IO_read_end += count;
   if (count == 0)
     return EOF;
   if (fp->_offset != _IO_pos_BAD)
-    _IO_pos_adjust(fp->_offset, count);
-  return *(unsigned char*)fp->_IO_read_ptr;
+    _IO_pos_adjust (fp->_offset, count);
+  return *(unsigned char *) fp->_IO_read_ptr;
 }
 
 int
-DEFUN(_IO_file_overflow, (f, ch),
-      register _IO_FILE* f AND int ch)
+_IO_file_overflow (f, ch)
+      _IO_FILE *f;
+      int ch;
 {
   if (f->_flags & _IO_NO_WRITES) /* SET ERROR */
-    return EOF;
+    {
+      f->_flags |= _IO_ERR_SEEN;
+      __set_errno (EBADF);
+      return EOF;
+    }
   /* If currently reading or no buffer allocated. */
   if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
     {
       /* Allocate a buffer if needed. */
       if (f->_IO_write_base == 0)
        {
-         _IO_doallocbuf(f);
+         _IO_doallocbuf (f);
          _IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base);
        }
       /* Otherwise must be currently reading.
@@ -334,35 +367,35 @@ DEFUN(_IO_file_overflow, (f, ch),
       f->_flags |= _IO_CURRENTLY_PUTTING;
     }
   if (ch == EOF)
-    return _IO_do_flush(f);
+    return _IO_do_flush (f);
   if (f->_IO_write_ptr == f->_IO_buf_end ) /* Buffer is really full */
-    if (_IO_do_flush(f) == EOF)
+    if (_IO_do_flush (f) == EOF)
       return EOF;
   *f->_IO_write_ptr++ = ch;
   if ((f->_flags & _IO_UNBUFFERED)
       || ((f->_flags & _IO_LINE_BUF) && ch == '\n'))
-    if (_IO_do_flush(f) == EOF)
+    if (_IO_do_flush (f) == EOF)
       return EOF;
-  return (unsigned char)ch;
+  return (unsigned char) ch;
 }
 
 int
-DEFUN(_IO_file_sync, (fp),
-      register _IO_FILE* fp)
+_IO_file_sync (fp)
+     _IO_FILE *fp;
 {
   _IO_size_t delta;
   /*    char* ptr = cur_ptr(); */
   if (fp->_IO_write_ptr > fp->_IO_write_base)
     if (_IO_do_flush(fp)) return EOF;
-  delta = fp->_IO_read_ptr - fp->_IO_read_end; 
+  delta = fp->_IO_read_ptr - fp->_IO_read_end;
   if (delta != 0)
     {
 #ifdef TODO
-      if (_IO_in_backup(fp))
-       delta -= eGptr() - Gbase();
+      if (_IO_in_backup (fp))
+       delta -= eGptr () - Gbase ();
 #endif
       _IO_off_t new_pos = _IO_SYSSEEK (fp, delta, 1);
-      if (new_pos != (_IO_off_t)EOF)
+      if (new_pos != (_IO_off_t) EOF)
        fp->_IO_read_end = fp->_IO_read_ptr;
 #ifdef ESPIPE
       else if (errno == ESPIPE)
@@ -378,12 +411,19 @@ DEFUN(_IO_file_sync, (fp),
 }
 
 _IO_pos_t
-DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
-      register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode)
+_IO_file_seekoff (fp, offset, dir, mode)
+     _IO_FILE *fp;
+     _IO_off_t offset;
+     int dir;
+     int mode;
 {
   _IO_pos_t result;
   _IO_off_t delta, new_offset;
   long count;
+  /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
+     offset of the underlying file must be exact.  */
+  int must_be_exact = (fp->_IO_read_base == fp->_IO_read_end
+                      && fp->_IO_write_base == fp->_IO_write_ptr);
 
   if (mode == 0)
     dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
@@ -396,14 +436,15 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
      end up flushing when we close(), it doesn't make much difference.)
      FIXME: simulate mem-papped files. */
 
-  if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode(fp))
-    if (_IO_switch_to_get_mode(fp)) return EOF;
+  if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode (fp))
+    if (_IO_switch_to_get_mode (fp))
+      return EOF;
 
   if (fp->_IO_buf_base == NULL)
     {
-      _IO_doallocbuf(fp);
-      _IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
-      _IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
+      _IO_doallocbuf (fp);
+      _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
+      _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
     }
 
   switch (dir)
@@ -414,7 +455,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
       if (fp->_offset == _IO_pos_BAD)
        goto dumb;
       /* Make offset absolute, assuming current pointer is file_ptr(). */
-      offset += _IO_pos_as_off(fp->_offset);
+      offset += _IO_pos_as_off (fp->_offset);
 
       dir = _IO_seek_set;
       break;
@@ -423,7 +464,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
     case _IO_seek_end:
       {
        struct stat st;
-       if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG(st.st_mode))
+       if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
          {
            offset += st.st_size;
            dir = _IO_seek_set;
@@ -439,46 +480,46 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
       && !_IO_in_backup (fp))
     {
       /* Offset relative to start of main get area. */
-      _IO_pos_t rel_offset = offset - fp->_offset
-       + (fp->_IO_read_end - fp->_IO_read_base);
+      _IO_pos_t rel_offset = (offset - fp->_offset
+                             + (fp->_IO_read_end - fp->_IO_read_base));
       if (rel_offset >= 0)
        {
 #if 0
-         if (_IO_in_backup(fp))
-           _IO_switch_to_main_get_area(fp);
+         if (_IO_in_backup (fp))
+           _IO_switch_to_main_get_area (fp);
 #endif
          if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
            {
-             _IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
-                      fp->_IO_read_end);
-             _IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
+             _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
+                       fp->_IO_read_end);
+             _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
              return offset;
            }
 #ifdef TODO
            /* If we have streammarkers, seek forward by reading ahead. */
-           if (_IO_have_markers(fp))
+           if (_IO_have_markers (fp))
              {
                int to_skip = rel_offset
                  - (fp->_IO_read_ptr - fp->_IO_read_base);
-               if (ignore(to_skip) != to_skip)
+               if (ignore (to_skip) != to_skip)
                  goto dumb;
                return offset;
              }
 #endif
        }
 #ifdef TODO
-      if (rel_offset < 0 && rel_offset >= Bbase() - Bptr())
+      if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())
        {
-         if (!_IO_in_backup(fp))
-           _IO_switch_to_backup_area(fp);
-         gbump(fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
+         if (!_IO_in_backup (fp))
+           _IO_switch_to_backup_area (fp);
+         gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
          return offset;
        }
 #endif
     }
 
 #ifdef TODO
-  _IO_unsave_markers(fp);
+  _IO_unsave_markers (fp);
 #endif
 
   if (fp->_flags & _IO_NO_READS)
@@ -500,7 +541,8 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
   else
     {
       count = _IO_SYSREAD (fp, fp->_IO_buf_base,
-                          fp->_IO_buf_end - fp->_IO_buf_base);
+                          (must_be_exact
+                           ? delta : fp->_IO_buf_end - fp->_IO_buf_base));
       if (count < delta)
        {
          /* We weren't allowed to read, but try to seek the remainder. */
@@ -509,31 +551,38 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
          goto dumb;
        }
     }
-  _IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base+delta, fp->_IO_buf_base+count);
-  _IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
+  _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,
+           fp->_IO_buf_base + count);
+  _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
   fp->_offset = result + count;
-  _IO_mask_flags(fp, 0, _IO_EOF_SEEN);
+  _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
   return offset;
  dumb:
 
-  _IO_unsave_markers(fp);
+  _IO_unsave_markers (fp);
   result = _IO_SYSSEEK (fp, offset, dir);
   if (result != EOF)
-    _IO_mask_flags(fp, 0, _IO_EOF_SEEN);
+    _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
   fp->_offset = result;
-  _IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
-  _IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
+  _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
+  _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
   return result;
 }
 
 _IO_ssize_t
-DEFUN(_IO_file_read, (fp, buf, size),
-      register _IO_FILE* fp AND void* buf AND _IO_ssize_t size)
+_IO_file_read (fp, buf, size)
+     _IO_FILE *fp;
+     void *buf;
+     _IO_ssize_t size;
 {
   for (;;)
     {
-      _IO_ssize_t count = _IO_read(fp->_fileno, buf, size);
-#ifdef EINTR
+      _IO_ssize_t count = _IO_read (fp->_fileno, buf, size);
+#if 0 && defined EINTR
+      /* We must not do this optimization since POSIX.1 explicitly
+        requests that the stream operations must return with the
+        error EINTR if this happens.  There must be the possibility
+        that stream operations time out.  --drepper  */
       if (count == -1 && errno == EINTR)
        continue;
 #endif
@@ -542,37 +591,46 @@ DEFUN(_IO_file_read, (fp, buf, size),
 }
 
 _IO_pos_t
-DEFUN(_IO_file_seek, (fp, offset, dir),
-      _IO_FILE *fp AND _IO_off_t offset AND int dir)
+_IO_file_seek (fp, offset, dir)
+     _IO_FILE *fp;
+     _IO_off_t offset;
+     int dir;
 {
-  return _IO_lseek(fp->_fileno, offset, dir);
+  return _IO_lseek (fp->_fileno, offset, dir);
 }
 
 int
-DEFUN(_IO_file_stat, (fp, st),
-      _IO_FILE *fp AND void* st)
+_IO_file_stat (fp, st)
+     _IO_FILE *fp;
+     void *st;
 {
-  return _IO_fstat(fp->_fileno, (struct stat*)st);
+  return _IO_fstat (fp->_fileno, (struct stat *) st);
 }
 
 int
-DEFUN(_IO_file_close, (fp),
-      _IO_FILE* fp)
+_IO_file_close (fp)
+     _IO_FILE *fp;
 {
-  return _IO_close(fp->_fileno);
+  return _IO_close (fp->_fileno);
 }
 
 _IO_ssize_t
-DEFUN(_IO_file_write, (f, data, n),
-      register _IO_FILE* f AND const void* data AND _IO_ssize_t n)
+_IO_file_write (f, data, n)
+     _IO_FILE *f;
+     const void *data;
+     _IO_ssize_t n;
 {
   _IO_ssize_t to_do = n;
   while (to_do > 0)
     {
-      _IO_ssize_t count = _IO_write(f->_fileno, data, to_do);
+      _IO_ssize_t count = _IO_write (f->_fileno, data, to_do);
       if (count == EOF)
        {
-#ifdef EINTR
+#if 0 && defined EINTR
+         /* We must not do this optimization since POSIX.1 explicitly
+            requests that the stream operations must return with the
+            error EINTR if this happens.  There must be the
+            possibility that stream operations time out.  --drepper  */
          if (errno == EINTR)
            continue;
          else
@@ -583,7 +641,7 @@ DEFUN(_IO_file_write, (f, data, n),
             }
         }
       to_do -= count;
-      data = (void*)((char*)data + count);
+      data = (void *) ((char *) data + count);
     }
   n -= to_do;
   if (f->_offset >= 0)
@@ -592,10 +650,12 @@ DEFUN(_IO_file_write, (f, data, n),
 }
 
 _IO_size_t
-DEFUN(_IO_file_xsputn, (f, data, n),
-      _IO_FILE *f AND const void *data AND _IO_size_t n)
+_IO_file_xsputn (f, data, n)
+     _IO_FILE *f;
+     const void *data;
+     _IO_size_t n;
 {
-  register const char *s = (char*) data;
+  register const char *s = (char *) data;
   _IO_size_t to_do = n;
   int must_flush = 0;
   _IO_size_t count;
@@ -612,14 +672,16 @@ DEFUN(_IO_file_xsputn, (f, data, n),
     {
       count = f->_IO_buf_end - f->_IO_write_ptr;
       if (count >= n)
-       { register const char *p;
+       {
+         register const char *p;
          for (p = s + n; p > s; )
            {
-             if (*--p == '\n') {
-               count = p - s + 1;
-               must_flush = 1;
-               break;
-             }
+             if (*--p == '\n')
+               {
+                 count = p - s + 1;
+                 must_flush = 1;
+                 break;
+               }
            }
        }
     }
@@ -628,23 +690,26 @@ DEFUN(_IO_file_xsputn, (f, data, n),
     {
       if (count > to_do)
        count = to_do;
-      if (count > 20) {
-       memcpy(f->_IO_write_ptr, s, count);
-       s += count;
-      }
+      if (count > 20)
+       {
+         memcpy (f->_IO_write_ptr, s, count);
+         s += count;
+       }
       else
        {
          register char *p = f->_IO_write_ptr;
-         register int i = (int)count;
-         while (--i >= 0) *p++ = *s++;
+         register int i = (int) count;
+         while (--i >= 0)
+           *p++ = *s++;
        }
       f->_IO_write_ptr += count;
       to_do -= count;
     }
   if (to_do + must_flush > 0)
-    { _IO_size_t block_size, dont_write;
+    {
+      _IO_size_t block_size, dont_write;
       /* Next flush the (full) buffer. */
-      if (__overflow(f, EOF) == EOF)
+      if (__overflow (f, EOF) == EOF)
        return n - to_do;
 
       /* Try to maintain alignment: write a whole number of blocks.
@@ -653,15 +718,15 @@ DEFUN(_IO_file_xsputn, (f, data, n),
       dont_write = block_size >= 128 ? to_do % block_size : 0;
 
       count = to_do - dont_write;
-      if (_IO_do_write(f, s, count) == EOF)
+      if (_IO_do_write (f, s, count) == EOF)
        return n - to_do;
       to_do = dont_write;
-      
+
       /* Now write out the remainder.  Normally, this will fit in the
         buffer, but it's somewhat messier for line-buffered files,
         so we let _IO_default_xsputn handle the general case. */
       if (dont_write)
-       to_do -= _IO_default_xsputn(f, s+count, dont_write);
+       to_do -= _IO_default_xsputn (f, s+count, dont_write);
     }
   return n - to_do;
 }
@@ -669,21 +734,24 @@ DEFUN(_IO_file_xsputn, (f, data, n),
 #if 0
 /* Work in progress */
 _IO_size_t
-DEFUN(_IO_file_xsgetn, (fp, data, n),
-      _IO_FILE *fp AND void *data AND _IO_size_t n)
+_IO_file_xsgetn (fp, data, n)
+     _IO_FILE *fp;
+     void *data;
+     _IO_size_t n;
 {
   register _IO_size_t more = n;
   register char *s = data;
   for (;;)
     {
-      _IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr; /* Data available. */
+      /* Data available. */
+      _IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr;
       if (count > 0)
        {
          if (count > more)
            count = more;
          if (count > 20)
            {
-             memcpy(s, fp->_IO_read_ptr, count);
+             memcpy (s, fp->_IO_read_ptr, count);
              s += count;
              fp->_IO_read_ptr += count;
            }
@@ -692,8 +760,9 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
          else
            {
              register char *p = fp->_IO_read_ptr;
-             register int i = (int)count;
-             while (--i >= 0) *s++ = *p++;
+             register int i = (int) count;
+             while (--i >= 0)
+               *s++ = *p++;
              fp->_IO_read_ptr = p;
             }
             more -= count;
@@ -708,11 +777,11 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
          /* If we're reading a lot of data, don't bother allocating
             a buffer.  But if we're only reading a bit, perhaps we should ??*/
          if (count <= 512 && fp->_IO_buf_base == NULL)
-           _IO_doallocbuf(fp);
+           _IO_doallocbuf (fp);
          if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
-           _IO_flush_all_linebuffered();
+           _IO_flush_all_linebuffered ();
 
-         _IO_switch_to_get_mode(fp); ???;
+         _IO_switch_to_get_mode (fp); ???;
          count = _IO_SYSREAD (fp, s, more);
          if (count <= 0)
             {
@@ -721,19 +790,20 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
               else
                 fp->_flags |= _IO_ERR_SEEN, count = 0;
             }
-         
+
          s += count;
          more -= count;
        }
 #endif
-      if (more == 0 || __underflow(fp) == EOF)
+      if (more == 0 || __underflow (fp) == EOF)
        break;
     }
   return n - more;
 }
 #endif
 
-struct _IO_jump_t _IO_file_jumps = {
+struct _IO_jump_t _IO_file_jumps =
+{
   JUMP_INIT_DUMMY,
   JUMP_INIT(finish, _IO_file_finish),
   JUMP_INIT(overflow, _IO_file_overflow),
index 23a6fdeaeac7bb5d8e076f0f59adeda14389b208..de9c826b9fed66822a835556f261bc4378879066 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993, 1995 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, 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.  */
 
 /* Generic or default I/O operations. */
 
@@ -31,41 +32,46 @@ the executable file might be covered by the GNU General Public License. */
 #include <string.h>
 
 void
-DEFUN(_IO_un_link, (fp),
-      _IO_FILE *fp)
-{
-  if (fp->_flags & _IO_LINKED) {
-    _IO_FILE **f;
-    for (f = &_IO_list_all; *f != NULL; f = &(*f)->_chain) {
-      if (*f == fp) {
-       *f = fp->_chain;
-       break;
-      }
+_IO_un_link (fp)
+     _IO_FILE *fp;
+{
+  if (fp->_flags & _IO_LINKED)
+    {
+      _IO_FILE **f;
+      for (f = &_IO_list_all; *f != NULL; f = &(*f)->_chain)
+       {
+         if (*f == fp)
+           {
+             *f = fp->_chain;
+             break;
+           }
+       }
+      fp->_flags &= ~_IO_LINKED;
     }
-    fp->_flags &= ~_IO_LINKED;
-  }
 }
 
 void
-DEFUN(_IO_link_in, (fp),
-      _IO_FILE *fp)
+_IO_link_in (fp)
+     _IO_FILE *fp;
 {
-    if ((fp->_flags & _IO_LINKED) == 0) {
+    if ((fp->_flags & _IO_LINKED) == 0)
+      {
        fp->_flags |= _IO_LINKED;
        fp->_chain = _IO_list_all;
        _IO_list_all = fp;
-    }
+      }
 }
 
 /* Return minimum _pos markers
    Assumes the current get area is the main get area. */
+static _IO_size_t _IO_least_marker __P ((_IO_FILE *fp));
 
-_IO_size_t
-DEFUN(_IO_least_marker, (fp),
-      register _IO_FILE *fp)
+static _IO_size_t
+_IO_least_marker (fp)
+     _IO_FILE *fp;
 {
   _IO_ssize_t least_so_far = fp->_IO_read_end - fp->_IO_read_base;
-  register struct _IO_marker *mark;
+  struct _IO_marker *mark;
   for (mark = fp->_markers; mark != NULL; mark = mark->_next)
     if (mark->_pos < least_so_far)
       least_so_far = mark->_pos;
@@ -75,41 +81,51 @@ DEFUN(_IO_least_marker, (fp),
 /* Switch current get area from backup buffer to (start of) main get area. */
 
 void
-DEFUN(_IO_switch_to_main_get_area, (fp),
-      _IO_FILE *fp)
+_IO_switch_to_main_get_area (fp)
+     _IO_FILE *fp;
 {
   char *tmp;
   fp->_flags &= ~_IO_IN_BACKUP;
   /* Swap _IO_read_end and _IO_save_end. */
-  tmp = fp->_IO_read_end; fp->_IO_read_end= fp->_IO_save_end; fp->_IO_save_end= tmp;
+  tmp = fp->_IO_read_end;
+  fp->_IO_read_end = fp->_IO_save_end;
+  fp->_IO_save_end= tmp;
   /* Swap _IO_read_base and _IO_save_base. */
-  tmp = fp->_IO_read_base; fp->_IO_read_base = fp->_IO_save_base; fp->_IO_save_base = tmp;
+  tmp = fp->_IO_read_base;
+  fp->_IO_read_base = fp->_IO_save_base;
+  fp->_IO_save_base = tmp;
+
   fp->_IO_read_ptr = fp->_IO_read_base;
 }
 
 /* Switch current get area from main get area to (end of) backup area. */
 
 void
-DEFUN(_IO_switch_to_backup_area, (fp),
-     register _IO_FILE *fp)
+_IO_switch_to_backup_area (fp)
+     _IO_FILE *fp;
 {
   char *tmp;
   fp->_flags |= _IO_IN_BACKUP;
   /* Swap _IO_read_end and _IO_save_end. */
-  tmp = fp->_IO_read_end; fp->_IO_read_end = fp->_IO_save_end; fp->_IO_save_end = tmp;
+  tmp = fp->_IO_read_end;
+  fp->_IO_read_end = fp->_IO_save_end;
+  fp->_IO_save_end = tmp;
   /* Swap _gbase and _IO_save_base. */
-  tmp = fp->_IO_read_base; fp->_IO_read_base = fp->_IO_save_base; fp->_IO_save_base = tmp;
+  tmp = fp->_IO_read_base;
+  fp->_IO_read_base = fp->_IO_save_base;
+  fp->_IO_save_base = tmp;
+
   fp->_IO_read_ptr = fp->_IO_read_end;
 }
 
 int
-DEFUN(_IO_switch_to_get_mode, (fp),
-     register _IO_FILE *fp)
+_IO_switch_to_get_mode (fp)
+     _IO_FILE *fp;
 {
   if (fp->_IO_write_ptr > fp->_IO_write_base)
     if (_IO_OVERFLOW (fp, EOF) == EOF)
       return EOF;
-  if (_IO_in_backup(fp))
+  if (_IO_in_backup (fp))
     fp->_IO_read_base = fp->_IO_backup_base;
   else
     {
@@ -126,11 +142,11 @@ DEFUN(_IO_switch_to_get_mode, (fp),
 }
 
 void
-DEFUN(_IO_free_backup_area, (fp),
-     register _IO_FILE *fp)
+_IO_free_backup_area (fp)
+     _IO_FILE *fp;
 {
   if (_IO_in_backup (fp))
-    _IO_switch_to_main_get_area(fp);  /* Just in case. */
+    _IO_switch_to_main_get_area (fp);  /* Just in case. */
   free (fp->_IO_save_base);
   fp->_IO_save_base = NULL;
   fp->_IO_save_end = NULL;
@@ -139,13 +155,14 @@ DEFUN(_IO_free_backup_area, (fp),
 
 #if 0
 int
-DEFUN(_IO_switch_to_put_mode, (fp),
-      register _IO_FILE *fp)
+_IO_switch_to_put_mode (fp)
+     _IO_FILE *fp;
 {
   fp->_IO_write_base = fp->_IO_read_ptr;
   fp->_IO_write_ptr = fp->_IO_read_ptr;
   /* Following is wrong if line- or un-buffered? */
-  fp->_IO_write_end = fp->_flags & _IO_IN_BACKUP ? fp->_IO_read_end : fp->_IO_buf_end;
+  fp->_IO_write_end = (fp->_flags & _IO_IN_BACKUP
+                      ? fp->_IO_read_end : fp->_IO_buf_end);
 
   fp->_IO_read_ptr = fp->_IO_read_end;
   fp->_IO_read_base = fp->_IO_read_end;
@@ -156,18 +173,21 @@ DEFUN(_IO_switch_to_put_mode, (fp),
 #endif
 
 int
-DEFUN(__overflow, (f, ch),
-      _IO_FILE *f AND int ch)
+__overflow (f, ch)
+     _IO_FILE *f;
+     int ch;
 {
   return _IO_OVERFLOW (f, ch);
 }
 
-static int
-DEFUN(save_for_backup, (fp),
-      _IO_FILE *fp)
+static int save_for_backup __P ((_IO_FILE *fp));
+
+     static int
+save_for_backup (fp)
+     _IO_FILE *fp;
 {
   /* Append [_IO_read_base.._IO_read_end] to backup area. */
-  int least_mark = _IO_least_marker(fp);
+  int least_mark = _IO_least_marker (fp);
   /* needed_size is how much space we need in the backup area. */
   int needed_size = (fp->_IO_read_end - fp->_IO_read_base) - least_mark;
   int current_Bsize = fp->_IO_save_end - fp->_IO_save_base;
@@ -178,22 +198,22 @@ DEFUN(save_for_backup, (fp),
     {
       char *new_buffer;
       avail = 100;
-      new_buffer = (char*)malloc(avail+needed_size);
+      new_buffer = (char *) malloc (avail + needed_size);
       if (new_buffer == NULL)
        return EOF;             /* FIXME */
       if (least_mark < 0)
        {
-         memcpy(new_buffer + avail,
-                fp->_IO_save_end + least_mark,
-                -least_mark);
-         memcpy(new_buffer +avail - least_mark,
-                fp->_IO_read_base,
-                fp->_IO_read_end - fp->_IO_read_base);
+         memcpy (new_buffer + avail,
+                 fp->_IO_save_end + least_mark,
+                 -least_mark);
+         memcpy (new_buffer + avail - least_mark,
+                 fp->_IO_read_base,
+                 fp->_IO_read_end - fp->_IO_read_base);
        }
       else
-       memcpy(new_buffer + avail,
-              fp->_IO_read_base + least_mark,
-              needed_size);
+       memcpy (new_buffer + avail,
+               fp->_IO_read_base + least_mark,
+               needed_size);
       if (fp->_IO_save_base)
        free (fp->_IO_save_base);
       fp->_IO_save_base = new_buffer;
@@ -204,17 +224,17 @@ DEFUN(save_for_backup, (fp),
       avail = current_Bsize - needed_size;
       if (least_mark < 0)
        {
-         memmove(fp->_IO_save_base + avail,
-                 fp->_IO_save_end + least_mark,
-                 -least_mark);
-         memcpy(fp->_IO_save_base + avail - least_mark,
-                fp->_IO_read_base,
-                fp->_IO_read_end - fp->_IO_read_base);
+         memmove (fp->_IO_save_base + avail,
+                  fp->_IO_save_end + least_mark,
+                  -least_mark);
+         memcpy (fp->_IO_save_base + avail - least_mark,
+                 fp->_IO_read_base,
+                 fp->_IO_read_end - fp->_IO_read_base);
        }
       else if (needed_size > 0)
-       memcpy(fp->_IO_save_base + avail,
-              fp->_IO_read_base + least_mark,
-              needed_size);
+       memcpy (fp->_IO_save_base + avail,
+               fp->_IO_read_base + least_mark,
+               needed_size);
     }
   /* FIXME: Dubious arithmetic if pointers are NULL */
   fp->_IO_backup_base = fp->_IO_save_base + avail;
@@ -226,59 +246,64 @@ DEFUN(save_for_backup, (fp),
 }
 
 int
-DEFUN(__underflow, (fp),
-      _IO_FILE *fp)
+__underflow (fp)
+     _IO_FILE *fp;
 {
-  if (_IO_in_put_mode(fp))
-    if (_IO_switch_to_get_mode(fp) == EOF) return EOF;
+  if (_IO_in_put_mode (fp))
+    if (_IO_switch_to_get_mode (fp) == EOF)
+      return EOF;
   if (fp->_IO_read_ptr < fp->_IO_read_end)
-    return *(unsigned char*)fp->_IO_read_ptr;
-  if (_IO_in_backup(fp))
+    return *(unsigned char *) fp->_IO_read_ptr;
+  if (_IO_in_backup (fp))
     {
-      _IO_switch_to_main_get_area(fp);
+      _IO_switch_to_main_get_area (fp);
       if (fp->_IO_read_ptr < fp->_IO_read_end)
        return *fp->_IO_read_ptr;
     }
-  if (_IO_have_markers(fp))
+  if (_IO_have_markers (fp))
     {
       if (save_for_backup (fp))
        return EOF;
     }
-  else if (_IO_have_backup(fp))
-    _IO_free_backup_area(fp);
+  else if (_IO_have_backup (fp))
+    _IO_free_backup_area (fp);
   return _IO_UNDERFLOW (fp);
 }
 
 int
-DEFUN(__uflow, (fp),
-     _IO_FILE *fp)
+__uflow (fp)
+     _IO_FILE *fp;
 {
-  if (_IO_in_put_mode(fp))
-    if (_IO_switch_to_get_mode(fp) == EOF) return EOF;
+  if (_IO_in_put_mode (fp))
+    if (_IO_switch_to_get_mode (fp) == EOF)
+      return EOF;
   if (fp->_IO_read_ptr < fp->_IO_read_end)
-    return *(unsigned char*)fp->_IO_read_ptr++;
-  if (_IO_in_backup(fp))
+    return *(unsigned char *) fp->_IO_read_ptr++;
+  if (_IO_in_backup (fp))
     {
-      _IO_switch_to_main_get_area(fp);
+      _IO_switch_to_main_get_area (fp);
       if (fp->_IO_read_ptr < fp->_IO_read_end)
        return *fp->_IO_read_ptr++;
     }
-  if (_IO_have_markers(fp))
+  if (_IO_have_markers (fp))
     {
       if (save_for_backup (fp))
        return EOF;
     }
-  else if (_IO_have_backup(fp))
-    _IO_free_backup_area(fp);
+  else if (_IO_have_backup (fp))
+    _IO_free_backup_area (fp);
   return _IO_UFLOW (fp);
 }
 
 void
-DEFUN(_IO_setb, (f, b, eb, a),
-      _IO_FILE *f AND char *b AND char *eb AND int a)
+_IO_setb (f, b, eb, a)
+     _IO_FILE *f;
+      char *b;
+     char *eb;
+     int a;
 {
   if (f->_IO_buf_base && !(f->_flags & _IO_USER_BUF))
-    FREE_BUF(f->_IO_buf_base);
+    FREE_BUF (f->_IO_buf_base, _IO_blen (f));
   f->_IO_buf_base = b;
   f->_IO_buf_end = eb;
   if (a)
@@ -288,52 +313,55 @@ DEFUN(_IO_setb, (f, b, eb, a),
 }
 
 void
-DEFUN(_IO_doallocbuf, (fp),
-      register _IO_FILE *fp)
+_IO_doallocbuf (fp)
+     _IO_FILE *fp;
 {
   if (fp->_IO_buf_base)
     return;
   if (!(fp->_flags & _IO_UNBUFFERED))
     if (_IO_DOALLOCATE (fp) != EOF)
       return;
-  _IO_setb(fp, fp->_shortbuf, fp->_shortbuf+1, 0);
+  _IO_setb (fp, fp->_shortbuf, fp->_shortbuf+1, 0);
 }
 
 int
-DEFUN(_IO_default_underflow, (fp),
-      _IO_FILE *fp)
+_IO_default_underflow (fp)
+     _IO_FILE *fp;
 {
   return EOF;
 }
 
 int
-DEFUN(_IO_default_uflow, (fp),
-      _IO_FILE *fp)
+_IO_default_uflow (fp)
+     _IO_FILE *fp;
 {
   int ch = _IO_UNDERFLOW (fp);
   if (ch == EOF)
     return EOF;
-  return *(unsigned char*)fp->_IO_read_ptr++;
+  return *(unsigned char *) fp->_IO_read_ptr++;
 }
 
 _IO_size_t
-DEFUN(_IO_default_xsputn, (f, data, n),
-      register _IO_FILE *f AND const void *data AND _IO_size_t n)
+_IO_default_xsputn (f, data, n)
+     _IO_FILE *f;
+     const void *data;
+     _IO_size_t n;
 {
-  register const char *s = (char*) data;
-  register _IO_size_t more = n;
+  const char *s = (char *) data;
+  _IO_size_t more = n;
   if (more <= 0)
     return 0;
   for (;;)
     {
-      _IO_ssize_t count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */
+      /* Space available. */
+      _IO_ssize_t count = f->_IO_write_end - f->_IO_write_ptr;
       if (count > 0)
        {
-         if (count > more)
+         if ((_IO_size_t) count > more)
            count = more;
          if (count > 20)
            {
-             memcpy(f->_IO_write_ptr, s, count);
+             memcpy (f->_IO_write_ptr, s, count);
              s += count;
              f->_IO_write_ptr += count;
             }
@@ -341,14 +369,15 @@ DEFUN(_IO_default_xsputn, (f, data, n),
            count = 0;
          else
            {
-             register char *p = f->_IO_write_ptr;
-             register _IO_ssize_t i;
-             for (i = count; --i >= 0; ) *p++ = *s++;
+             char *p = f->_IO_write_ptr;
+             _IO_ssize_t i;
+             for (i = count; --i >= 0; )
+               *p++ = *s++;
              f->_IO_write_ptr = p;
             }
          more -= count;
         }
-      if (more == 0 || __overflow(f, (unsigned char)*s++) == EOF)
+      if (more == 0 || __overflow (f, (unsigned char) *s++) == EOF)
        break;
       more--;
     }
@@ -356,29 +385,34 @@ DEFUN(_IO_default_xsputn, (f, data, n),
 }
 
 _IO_size_t
-DEFUN(_IO_sgetn, (fp, data, n),
-      _IO_FILE *fp AND void *data AND _IO_size_t n)
+_IO_sgetn (fp, data, n)
+     _IO_FILE *fp;
+     void *data;
+     _IO_size_t n;
 {
   /* FIXME handle putback buffer here! */
   return _IO_XSGETN (fp, data, n);
 }
 
 _IO_size_t
-DEFUN(_IO_default_xsgetn, (fp, data, n),
-      _IO_FILE *fp AND void *data AND _IO_size_t n)
+_IO_default_xsgetn (fp, data, n)
+     _IO_FILE *fp;
+     void *data;
+     _IO_size_t n;
 {
-  register _IO_size_t more = n;
-  register char *s = (char*) data;
+  _IO_size_t more = n;
+  char *s = (char*) data;
   for (;;)
     {
-      _IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr; /* Data available. */
+      /* Data available. */
+      _IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr;
       if (count > 0)
        {
-         if (count > more)
+         if ((_IO_size_t) count > more)
            count = more;
          if (count > 20)
            {
-             memcpy(s, fp->_IO_read_ptr, count);
+             memcpy (s, fp->_IO_read_ptr, count);
              s += count;
              fp->_IO_read_ptr += count;
            }
@@ -386,41 +420,47 @@ DEFUN(_IO_default_xsgetn, (fp, data, n),
            count = 0;
          else
            {
-             register char *p = fp->_IO_read_ptr;
-             register int i = (int)count;
-             while (--i >= 0) *s++ = *p++;
+             char *p = fp->_IO_read_ptr;
+             int i = (int) count;
+             while (--i >= 0)
+               *s++ = *p++;
              fp->_IO_read_ptr = p;
             }
             more -= count;
         }
-      if (more == 0 || __underflow(fp) == EOF)
+      if (more == 0 || __underflow (fp) == EOF)
        break;
     }
   return n - more;
 }
 
+#if 0
+/* Seems not to be needed. --drepper */
 int
-DEFUN(_IO_sync, (fp),
-      register _IO_FILE *fp)
+_IO_sync (fp)
+     _IO_FILE *fp;
 {
   return 0;
 }
+#endif
 
-_IO_FILE*
-DEFUN(_IO_default_setbuf, (fp, p, len),
-      register _IO_FILE *fp AND char* p AND _IO_ssize_t len)
+_IO_FILE *
+_IO_default_setbuf (fp, p, len)
+     _IO_FILE *fp;
+     char *p;
+     _IO_ssize_t len;
 {
     if (_IO_SYNC (fp) == EOF)
        return NULL;
     if (p == NULL || len == 0)
       {
        fp->_flags |= _IO_UNBUFFERED;
-       _IO_setb(fp, fp->_shortbuf, fp->_shortbuf+1, 0);
+       _IO_setb (fp, fp->_shortbuf, fp->_shortbuf+1, 0);
       }
     else
       {
        fp->_flags &= ~_IO_UNBUFFERED;
-       _IO_setb(fp, p, p+len, 0);
+       _IO_setb (fp, p, p+len, 0);
       }
     fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end = 0;
     fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_read_end = 0;
@@ -428,26 +468,29 @@ DEFUN(_IO_default_setbuf, (fp, p, len),
 }
 
 _IO_pos_t
-DEFUN(_IO_default_seekpos, (fp, pos, mode),
-      _IO_FILE *fp AND _IO_pos_t pos AND int mode)
+_IO_default_seekpos (fp, pos, mode)
+     _IO_FILE *fp;
+     _IO_pos_t pos;
+     int mode;
 {
-  return _IO_SEEKOFF (fp, _IO_pos_as_off(pos), 0, mode);
+  return _IO_SEEKOFF (fp, _IO_pos_as_off (pos), 0, mode);
 }
 
 int
-DEFUN(_IO_default_doallocate, (fp),
-      _IO_FILE *fp)
+_IO_default_doallocate (fp)
+     _IO_FILE *fp;
 {
-  char *buf = ALLOC_BUF(_IO_BUFSIZ);
-  if (buf == NULL)
-    return EOF;
-  _IO_setb(fp, buf, buf+_IO_BUFSIZ, 1);
+  char *buf;
+
+  ALLOC_BUF (buf, _IO_BUFSIZ, EOF);
+  _IO_setb (fp, buf, buf+_IO_BUFSIZ, 1);
   return 1;
 }
 
 void
-DEFUN(_IO_init, (fp, flags),
-      register _IO_FILE *fp AND int flags)
+_IO_init (fp, flags)
+     _IO_FILE *fp;
+     int flags;
 {
   fp->_flags = _IO_MAGIC|flags;
   fp->_IO_buf_base = NULL;
@@ -465,11 +508,14 @@ DEFUN(_IO_init, (fp, flags),
   fp->_IO_save_end = NULL;
   fp->_markers = NULL;
   fp->_cur_column = 0;
+#ifdef _IO_MTSAFE_IO
+  _IO_lock_init (*fp->_lock);
+#endif
 }
 
 int
-DEFUN(_IO_default_sync, (fp),
-      _IO_FILE *fp)
+_IO_default_sync (fp)
+     _IO_FILE *fp;
 {
   return 0;
 }
@@ -478,13 +524,14 @@ DEFUN(_IO_default_sync, (fp),
    current implementation, this function can get called twice! */
 
 void
-DEFUN(_IO_default_finish, (fp),
-      _IO_FILE *fp)
+_IO_default_finish (fp, dummy)
+     _IO_FILE *fp;
+     int dummy;
 {
   struct _IO_marker *mark;
   if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
     {
-      FREE_BUF(fp->_IO_buf_base);
+      FREE_BUF (fp->_IO_buf_base, _IO_blen (fp));
       fp->_IO_buf_base = fp->_IO_buf_end = NULL;
     }
 
@@ -497,27 +544,35 @@ DEFUN(_IO_default_finish, (fp),
       fp->_IO_save_base = NULL;
     }
 
-  _IO_un_link(fp);
+#ifdef _IO_MTSAFE_IO
+  _IO_lock_fini (*fp->_lock);
+#endif
+
+  _IO_un_link (fp);
 }
 
 _IO_pos_t
-DEFUN(_IO_default_seekoff, (fp, offset, dir, mode),
-      register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode)
+_IO_default_seekoff (fp, offset, dir, mode)
+     _IO_FILE *fp;
+     _IO_off_t offset;
+     int dir;
+     int mode;
 {
     return _IO_pos_BAD;
 }
 
 int
-DEFUN(_IO_sputbackc, (fp, c),
-      register _IO_FILE *fp AND int c)
+_IO_sputbackc (fp, c)
+     _IO_FILE *fp;
+     int c;
 {
   int result;
-  
+
   if (fp->_IO_read_ptr > fp->_IO_read_base
       && (unsigned char)fp->_IO_read_ptr[-1] == (unsigned char)c)
     {
       fp->_IO_read_ptr--;
-      result = (unsigned char)c;
+      result = (unsigned char) c;
     }
   else
     result = _IO_PBACKFAIL (fp, c);
@@ -529,15 +584,15 @@ DEFUN(_IO_sputbackc, (fp, c),
 }
 
 int
-DEFUN(_IO_sungetc, (fp),
-      register _IO_FILE *fp)
+_IO_sungetc (fp)
+     _IO_FILE *fp;
 {
   int result;
-  
+
   if (fp->_IO_read_ptr > fp->_IO_read_base)
     {
       fp->_IO_read_ptr--;
-      result = (unsigned char)*fp->_IO_read_ptr;
+      result = (unsigned char) *fp->_IO_read_ptr;
     }
   else
     result = _IO_PBACKFAIL (fp, EOF);
@@ -549,9 +604,12 @@ DEFUN(_IO_sungetc, (fp),
 }
 
 #if 0 /* Work in progress */
+/* Seems not to be needed.  */
+#if 0
 void
-DEFUN(_IO_set_column, (fp, c),
-      register _IO_FILE *fp AND int c)
+_IO_set_column (fp, c)
+     _IO_FILE *fp;
+     int c;
 {
   if (c == -1)
     fp->_column = -1;
@@ -560,39 +618,46 @@ DEFUN(_IO_set_column, (fp, c),
 }
 #else
 int
-DEFUN(_IO_set_column, (fp, i),
-      register _IO_FILE *fp AND int i)
+_IO_set_column (fp, i)
+     _IO_FILE *fp;
+     int i;
 {
-  fp->_cur_column = i+1;
+  fp->_cur_column = i + 1;
   return 0;
 }
 #endif
+#endif
 
 
 unsigned
-DEFUN(_IO_adjust_column, (start, line, count),
-      unsigned start AND const char *line AND int count)
+_IO_adjust_column (start, line, count)
+     unsigned start;
+     const char *line;
+     int count;
 {
-  register const char *ptr = line + count;
+  const char *ptr = line + count;
   while (ptr > line)
     if (*--ptr == '\n')
       return line + count - ptr - 1;
   return start + count;
 }
 
+#if 0
+/* Seems not to be needed. --drepper */
 int
-DEFUN(_IO_get_column, (fp),
-      register _IO_FILE *fp)
+_IO_get_column (fp)
+     _IO_FILE *fp;
 {
-  if (fp->_cur_column) 
-    return _IO_adjust_column(fp->_cur_column - 1,
+  if (fp->_cur_column)
+    return _IO_adjust_column (fp->_cur_column - 1,
                              fp->_IO_write_base,
                              fp->_IO_write_ptr - fp->_IO_write_base);
   return -1;
 }
+#endif
 
 int
-DEFUN_VOID(_IO_flush_all)
+_IO_flush_all ()
 {
   int result = 0;
   _IO_FILE *fp;
@@ -604,16 +669,18 @@ DEFUN_VOID(_IO_flush_all)
 }
 
 void
-DEFUN_VOID(_IO_flush_all_linebuffered)
+_IO_flush_all_linebuffered ()
 {
   _IO_FILE *fp;
   for (fp = _IO_list_all; fp != NULL; fp = fp->_chain)
-    if (fp->_flags & _IO_LINE_BUF)
+    if ((fp->_flags & _IO_NO_WRITES) == 0 && fp->_flags & _IO_LINE_BUF)
       _IO_OVERFLOW (fp, EOF);
 }
 
-void
-DEFUN_VOID(_IO_unbuffer_all)
+static void _IO_unbuffer_all __P ((void));
+
+static void
+_IO_unbuffer_all ()
 {
   _IO_FILE *fp;
   for (fp = _IO_list_all; fp != NULL; fp = fp->_chain)
@@ -622,43 +689,44 @@ DEFUN_VOID(_IO_unbuffer_all)
 }
 
 void
-DEFUN_VOID(_IO_cleanup)
+_IO_cleanup ()
 {
   _IO_flush_all ();
 
   /* We currently don't have a reliable mechanism for making sure that
      C++ static destructors are executed in the correct order.
-     So it is possible that other static destructord might want to
+     So it is possible that other static destructors might want to
      write to cout - and they're supposed to be able to do so.
 
-     The following will make the standard streambufs be unbuffered, 
+     The following will make the standard streambufs be unbuffered,
      which forces any output from late destructors to be written out. */
   _IO_unbuffer_all ();
 }
 
 void
-DEFUN(_IO_init_marker, (marker, fp),
-      struct _IO_marker *marker AND _IO_FILE *fp)
+_IO_init_marker (marker, fp)
+     struct _IO_marker *marker;
+     _IO_FILE *fp;
 {
   marker->_sbuf = fp;
-  if (_IO_in_put_mode(fp))
-    _IO_switch_to_get_mode(fp);
-  if (_IO_in_backup(fp))
+  if (_IO_in_put_mode (fp))
+    _IO_switch_to_get_mode (fp);
+  if (_IO_in_backup (fp))
     marker->_pos = fp->_IO_read_ptr - fp->_IO_read_end;
   else
     marker->_pos = fp->_IO_read_ptr - fp->_IO_read_base;
-  
+
   /* Should perhaps sort the chain? */
   marker->_next = fp->_markers;
   fp->_markers = marker;
 }
 
 void
-DEFUN(_IO_remove_marker, (marker),
-      register struct _IO_marker *marker)
+_IO_remove_marker (marker)
+     struct _IO_marker *marker;
 {
   /* Unlink from sb's chain. */
-  register struct _IO_marker **ptr = &marker->_sbuf->_markers;
+  struct _IO_marker **ptr = &marker->_sbuf->_markers;
   for (; ; ptr = &(*ptr)->_next)
     {
       if (*ptr == NULL)
@@ -678,21 +746,22 @@ DEFUN(_IO_remove_marker, (marker),
 #define BAD_DELTA EOF
 
 int
-DEFUN(_IO_marker_difference, (mark1, mark2),
-      struct _IO_marker *mark1 AND struct _IO_marker *mark2)
+_IO_marker_difference (mark1, mark2)
+     struct _IO_marker *mark1;
+     struct _IO_marker *mark2;
 {
   return mark1->_pos - mark2->_pos;
 }
 
-/* Return difference between MARK and current posistion of MARK's stream. */
+/* Return difference between MARK and current position of MARK's stream. */
 int
-DEFUN(_IO_marker_delta, (mark),
-      struct _IO_marker *mark)
+_IO_marker_delta (mark)
+     struct _IO_marker *mark;
 {
   int cur_pos;
   if (mark->_sbuf == NULL)
     return BAD_DELTA;
-  if (_IO_in_backup(mark->_sbuf))
+  if (_IO_in_backup (mark->_sbuf))
     cur_pos = mark->_sbuf->_IO_read_ptr - mark->_sbuf->_IO_read_end;
   else
     cur_pos = mark->_sbuf->_IO_read_ptr - mark->_sbuf->_IO_read_base;
@@ -700,135 +769,150 @@ DEFUN(_IO_marker_delta, (mark),
 }
 
 int
-DEFUN(_IO_seekmark, (fp, mark, delta),
-      _IO_FILE *fp AND struct _IO_marker *mark AND int delta)
+_IO_seekmark (fp, mark, delta)
+     _IO_FILE *fp;
+     struct _IO_marker *mark;
+     int delta;
 {
   if (mark->_sbuf != fp)
     return EOF;
  if (mark->_pos >= 0)
     {
-      if (_IO_in_backup(fp))
-       _IO_switch_to_main_get_area(fp);
+      if (_IO_in_backup (fp))
+       _IO_switch_to_main_get_area (fp);
       fp->_IO_read_ptr = fp->_IO_read_base + mark->_pos;
     }
   else
     {
-      if (!_IO_in_backup(fp))
-       _IO_switch_to_backup_area(fp);
+      if (!_IO_in_backup (fp))
+       _IO_switch_to_backup_area (fp);
       fp->_IO_read_ptr = fp->_IO_read_end + mark->_pos;
     }
   return 0;
 }
 
 void
-DEFUN(_IO_unsave_markers, (fp),
-     register _IO_FILE *fp)
+_IO_unsave_markers (fp)
+     _IO_FILE *fp;
 {
-  register struct _IO_marker *mark = fp->_markers;
+  struct _IO_marker *mark = fp->_markers;
   if (mark)
     {
 #ifdef TODO
-      streampos offset = seekoff(0, ios::cur, ios::in);
+      streampos offset = seekoff (0, ios::cur, ios::in);
       if (offset != EOF)
        {
-         offset += eGptr() - Gbase();
+         offset += eGptr () - Gbase ();
          for ( ; mark != NULL; mark = mark->_next)
-           mark->set_streampos(mark->_pos + offset);
+           mark->set_streampos (mark->_pos + offset);
        }
     else
       {
        for ( ; mark != NULL; mark = mark->_next)
-         mark->set_streampos(EOF);
+         mark->set_streampos (EOF);
       }
 #endif
       fp->_markers = 0;
     }
 
-  if (_IO_have_backup(fp))
-    _IO_free_backup_area(fp);
+  if (_IO_have_backup (fp))
+    _IO_free_backup_area (fp);
 }
 
+#if 0
+/* Seems not to be needed. --drepper */
 int
-DEFUN(_IO_nobackup_pbackfail, (fp, c),
-     register _IO_FILE *fp AND int c)
+_IO_nobackup_pbackfail (fp, c)
+     _IO_FILE *fp;
+     int c;
 {
   if (fp->_IO_read_ptr > fp->_IO_read_base)
        fp->_IO_read_ptr--;
   if (c != EOF && *fp->_IO_read_ptr != c)
       *fp->_IO_read_ptr = c;
-  return (unsigned char)c;
+  return (unsigned char) c;
 }
+#endif
 
 int
-DEFUN(_IO_default_pbackfail, (fp, c),
-      register _IO_FILE *fp AND int c)
+_IO_default_pbackfail (fp, c)
+     _IO_FILE *fp;
+     int c;
 {
   if (fp->_IO_read_ptr <= fp->_IO_read_base)
-      {
-       /* Need to handle a filebuf in write mode (switch to read mode). FIXME!*/
-       if (_IO_have_backup(fp) && !_IO_in_backup(fp))
-         _IO_switch_to_backup_area(fp);
-       
-       if (!_IO_have_backup(fp))
-         {
-           /* No backup buffer: allocate one. */
-           /* Use nshort buffer, if unused? (probably not)  FIXME */
-           int backup_size = 128;
-           char *bbuf = (char*)malloc(backup_size);
-           if (bbuf == NULL)
-             return EOF;
-           fp->_IO_save_base = bbuf;
-           fp->_IO_save_end = fp->_IO_save_base + backup_size;
-           fp->_IO_backup_base = fp->_IO_save_end;
-           _IO_switch_to_backup_area(fp);
-         }
-       else if (fp->_IO_read_ptr <= fp->_IO_read_base)
-         {
-           /* Increase size of existing backup buffer. */
-           _IO_size_t new_size;
-           _IO_size_t old_size = fp->_IO_read_end - fp->_IO_read_base;
-           char *new_buf;
-           new_size = 2 * old_size;
-           new_buf = (char*)malloc(new_size);
-           if (new_buf == NULL)
-             return EOF;
-           memcpy(new_buf+(new_size-old_size), fp->_IO_read_base, old_size);
-           free (fp->_IO_read_base);
-           _IO_setg(fp,
-                    new_buf, new_buf+(new_size-old_size), new_buf+new_size);
-           fp->_IO_backup_base = fp->_IO_read_ptr;
-         }
-      }
-  fp->_IO_read_ptr--;
+    {
+      /* Need to handle a filebuf in write mode (switch to read mode). FIXME!*/
+      if (_IO_have_backup (fp) && !_IO_in_backup (fp))
+       _IO_switch_to_backup_area (fp);
+
+      if (!_IO_have_backup (fp))
+       {
+         /* No backup buffer: allocate one. */
+         /* Use nshort buffer, if unused? (probably not)  FIXME */
+         int backup_size = 128;
+         char *bbuf = (char *) malloc (backup_size);
+         if (bbuf == NULL)
+           return EOF;
+         fp->_IO_save_base = bbuf;
+         fp->_IO_save_end = fp->_IO_save_base + backup_size;
+         fp->_IO_backup_base = fp->_IO_save_end;
+         _IO_switch_to_backup_area (fp);
+       }
+      else if (fp->_IO_read_ptr <= fp->_IO_read_base)
+       {
+         /* Increase size of existing backup buffer. */
+         _IO_size_t new_size;
+         _IO_size_t old_size = fp->_IO_read_end - fp->_IO_read_base;
+         char *new_buf;
+         new_size = 2 * old_size;
+         new_buf = (char *) malloc (new_size);
+         if (new_buf == NULL)
+           return EOF;
+         memcpy (new_buf + (new_size - old_size), fp->_IO_read_base,
+                 old_size);
+         free (fp->_IO_read_base);
+         _IO_setg (fp, new_buf, new_buf + (new_size - old_size),
+                   new_buf + new_size);
+         fp->_IO_backup_base = fp->_IO_read_ptr;
+       }
+    }
+  --fp->_IO_read_ptr;
   if (c != EOF && *fp->_IO_read_ptr != c)
     *fp->_IO_read_ptr = c;
-  return (unsigned char)*fp->_IO_read_ptr;
+  return (unsigned char) *fp->_IO_read_ptr;
 }
 
 _IO_pos_t
-DEFUN(_IO_default_seek, (fp, offset, dir),
-      _IO_FILE *fp AND _IO_off_t offset AND int dir)
+_IO_default_seek (fp, offset, dir)
+     _IO_FILE *fp;
+     _IO_off_t offset;
+     int dir;
 {
   return _IO_pos_BAD;
 }
 
 int
-DEFUN(_IO_default_stat, (fp, st),
-      _IO_FILE *fp AND void* st)
+_IO_default_stat (fp, st)
+     _IO_FILE *fp;
+     void* st;
 {
   return EOF;
 }
 
 _IO_ssize_t
-DEFUN(_IO_default_read, (fp, data, n),
-      register _IO_FILE* fp AND void* data AND _IO_ssize_t n)
+_IO_default_read (fp, data, n)
+     _IO_FILE* fp;
+     void *data;
+     _IO_ssize_t n;
 {
   return -1;
 }
 
 _IO_ssize_t
-DEFUN(_IO_default_write, (fp, data, n),
-      register _IO_FILE* fp AND const void* data AND _IO_ssize_t n)
+_IO_default_write (fp, data, n)
+     _IO_FILE *fp;
+     const void *data;
+     _IO_ssize_t n;
 {
   return 0;
 }
@@ -844,9 +928,17 @@ DEFUN(_IO_default_write, (fp, data, n),
 #else
 struct __io_defs {
     __io_defs() { }
-    ~__io_defs() { _IO_cleanup(); }
-};   
+    ~__io_defs() { _IO_cleanup (); }
+};
 __io_defs io_defs__;
 #endif
 
 #endif /* TODO */
+
+#ifdef weak_alias
+weak_alias (_IO_cleanup, _cleanup)
+#endif
+
+#ifdef text_set_element
+text_set_element(__libc_atexit, _cleanup);
+#endif
diff --git a/libio/include/empty.h b/libio/include/empty.h
new file mode 100644 (file)
index 0000000..42dc218
--- /dev/null
@@ -0,0 +1 @@
+/* this will be used later*/
index f3ae0964e826b99ca496f98a1749ac9cb8b67838..35f4a8b56916a724a4a09cd4c1fbc03457d7313a 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-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, 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"
 #ifdef __STDC__
@@ -28,20 +29,30 @@ the executable file might be covered by the GNU General Public License. */
 #endif
 
 int
-DEFUN(_IO_fclose, (fp),
-      register _IO_FILE *fp)
+_IO_fclose (fp)
+     _IO_FILE *fp;
 {
   int status;
+
   CHECK_FILE(fp, EOF);
+
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
   if (fp->_IO_file_flags & _IO_IS_FILEBUF)
-    status = _IO_file_close_it(fp);
+    status = _IO_file_close_it (fp);
   else
     status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
   _IO_FINISH (fp);
+  _IO_cleanup_region_end (1);
   if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
     {
       fp->_IO_file_flags = 0;
       free(fp);
     }
+
   return status;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fclose, fclose)
+#endif
index f8bc76869ad9f0122f16d95b24a686f01fd8c105..841e7032b803218d1ed94896755146dea4eb8628 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993, 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) 1993, 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.  */
 
 #ifdef __STDC__
 #include <stdlib.h>
@@ -33,12 +34,19 @@ the executable file might be covered by the GNU General Public License. */
 #endif
 
 _IO_FILE *
-DEFUN(_IO_fdopen, (fd, mode),
-      int fd AND const char *mode)
+_IO_fdopen (fd, mode)
+     int fd;
+     const char *mode;
 {
   int read_write;
   int posix_mode = 0;
-  struct _IO_FILE_plus *fp;
+  struct locked_FILE
+  {
+    struct _IO_FILE_plus fp;
+#ifdef _IO_MTSAFE_IO
+    _IO_lock_t lock;
+#endif
+  } *new_f;
   int fd_flags;
 
   switch (*mode++)
@@ -54,9 +62,7 @@ DEFUN(_IO_fdopen, (fd, mode),
       read_write = _IO_NO_READS|_IO_IS_APPENDING;
       break;
     default:
-#ifdef EINVAL
-      errno = EINVAL;
-#endif
+      MAYBE_SET_EINVAL;
       return NULL;
   }
   if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
@@ -96,26 +102,33 @@ DEFUN(_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);
+#ifdef _IO_MTSAFE_IO
+  new_f->fp.file._lock = &new_f->lock;
+#endif
+  _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,
-                  _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
+  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;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fdopen, fdopen)
+#endif
diff --git a/libio/iofeof.c b/libio/iofeof.c
new file mode 100644 (file)
index 0000000..d06de04
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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
+_IO_feof (fp)
+     _IO_FILE* fp;
+{
+  int result;
+  CHECK_FILE (fp, EOF);
+  _IO_flockfile (fp);
+  result = _IO_feof_unlocked (fp);
+  _IO_funlockfile (fp);
+  return result;
+}
+
+#ifdef weak_alias
+weak_alias (_IO_feof, feof)
+#endif
diff --git a/libio/ioferror.c b/libio/ioferror.c
new file mode 100644 (file)
index 0000000..855627a
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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
+_IO_ferror (fp)
+     _IO_FILE* fp;
+{
+  int result;
+  CHECK_FILE (fp, EOF);
+  _IO_flockfile (fp);
+  result = _IO_ferror_unlocked (fp);
+  _IO_funlockfile (fp);
+  return result;
+}
+
+#ifdef weak_alias
+weak_alias (_IO_ferror, ferror)
+#endif
index ecb816d419863de81abf7bb6bf22c8cdfa5469bd..540c99d535ee8c72551240133121a2f88828a7ef 100644 (file)
@@ -1,38 +1,49 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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
-DEFUN(_IO_fflush, (fp),
-      register _IO_FILE *fp)
+_IO_fflush (fp)
+     _IO_FILE *fp;
 {
   if (fp == NULL)
-    return _IO_flush_all();
+    return _IO_flush_all ();
   else
     {
-      CHECK_FILE(fp, EOF);
-      return _IO_SYNC (fp) ? EOF : 0;
+      int result;
+      CHECK_FILE (fp, EOF);
+      _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+      _IO_flockfile (fp);
+      result = _IO_SYNC (fp) ? EOF : 0;
+      _IO_cleanup_region_end (1);
+      return result;
     }
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fflush, fflush)
+#endif
diff --git a/libio/iofflush_u.c b/libio/iofflush_u.c
new file mode 100644 (file)
index 0000000..b46ae4a
--- /dev/null
@@ -0,0 +1,40 @@
+/* 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
+fflush_unlocked (fp)
+     _IO_FILE *fp;
+{
+  if (fp == NULL)
+    return _IO_flush_all ();
+  else
+    {
+      CHECK_FILE (fp, EOF);
+      return _IO_SYNC (fp) ? EOF : 0;
+    }
+}
index 5e7a8632102a7f13d3c4e92ccfced61739fdfdda..716be4bca107b19e151f2c802dbc2b7d8322350a 100644 (file)
@@ -1,46 +1,55 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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 <errno.h>
-/* ANSI explicily requires setting errno to a positive value on failure. */
+/* ANSI explicitly requires setting errno to a positive value on failure. */
 
 int
-DEFUN(_IO_fgetpos, (fp, posp),
-      _IO_FILE* fp AND _IO_fpos_t *posp)
+_IO_fgetpos (fp, posp)
+     _IO_FILE* fp;
+     _IO_fpos_t *posp;
 {
   _IO_fpos_t pos;
-  CHECK_FILE(fp, EOF);
-  pos = _IO_seekoff(fp, 0, _IO_seek_cur, 0);
+  CHECK_FILE (fp, EOF);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0);
+  _IO_cleanup_region_end (1);
   if (pos == _IO_pos_BAD)
     {
 #ifdef EIO
       if (errno == 0)
-       errno = EIO;
+       __set_errno (EIO);
 #endif
       return EOF;
     }
   *posp = pos;
   return 0;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fgetpos, fgetpos)
+#endif
index 7b0b708a208347ff915af081bbe006a13bdba924..74754d5d1ea811e84b2a4794e385114e3f2f556d 100644 (file)
@@ -1,40 +1,56 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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>
 
-char*
-DEFUN(_IO_fgets, (buf, n, fp),
-      char* buf AND int n AND _IO_FILE* fp)
+char *
+_IO_fgets (buf, n, fp)
+     char *buf;
+     int n;
+     _IO_FILE *fp;
 {
   _IO_size_t count;
-  CHECK_FILE(fp, NULL);
+  char *result;
+  CHECK_FILE (fp, NULL);
   if (n <= 0)
     return NULL;
-  count = _IO_getline(fp, buf, n - 1, '\n', 1);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  count = _IO_getline (fp, buf, n - 1, '\n', 1);
   if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN))
-    return NULL;
-  buf[count] = 0;
-  return buf;
+    result = NULL;
+  else
+    {
+      buf[count] = '\0';
+      result = buf;
+    }
+  _IO_cleanup_region_end (1);
+  return result;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fgets, fgets)
+#endif
index 96910520ce73b818be3b5b018ec5a10ac5dce92f..1dbeccb81a8fcf5c9f9c278dc691b1e7b4dac8e1 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-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"
 #ifdef __STDC__
@@ -28,22 +29,36 @@ the executable file might be covered by the GNU General Public License. */
 #endif
 
 _IO_FILE *
-DEFUN(_IO_fopen, (filename, mode),
-      const char *filename AND const char *mode)
+_IO_fopen (filename, mode)
+     const char *filename;
+     const char *mode;
 {
-  struct _IO_FILE_plus *fp =
-    (struct _IO_FILE_plus*)malloc(sizeof(struct _IO_FILE_plus));
-  if (fp == NULL)
+  struct locked_FILE
+  {
+    struct _IO_FILE_plus fp;
+#ifdef _IO_MTSAFE_IO
+    _IO_lock_t lock;
+#endif
+  } *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);
+#ifdef _IO_MTSAFE_IO
+  new_f->fp.file._lock = &new_f->lock;
+#endif
+  _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_fopen(&fp->file, filename, mode) != NULL)
-        return (_IO_FILE*)fp;
-  _IO_un_link(&fp->file);
-  free (fp);
+  if (_IO_file_fopen (&new_f->fp.file, filename, mode) != NULL)
+        return (_IO_FILE *) &new_f->fp;
+  _IO_un_link (&new_f->fp.file);
+  free (new_f);
   return NULL;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fopen, fopen)
+#endif
index 11c76421809f4dc89e074e84327fe44a6a293d9c..4dc9d3f6617e9b0be62ff531208eab664e03b591 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
@@ -31,18 +32,20 @@ the executable file might be covered by the GNU General Public License. */
 #endif
 
 int
-_IO_fprintf
 #ifdef __STDC__
-  (_IO_FILE *fp, const char* format, ...)
+_IO_fprintf (_IO_FILE *fp, const char* format, ...)
 #else
-(fp, format, va_alist) _IO_FILE *fp; char *format; va_dcl
+_IO_fprintf (fp, format, va_alist)
+     _IO_FILE *fp;
+     char *format;
+     va_dcl
 #endif
 {
   int ret;
   va_list args;
-  CHECK_FILE(fp, -1);
-  _IO_va_start(args, format);
-  ret = _IO_vfprintf(fp, format, args);
-  va_end(args);
+  CHECK_FILE (fp, -1);
+  _IO_va_start (args, format);
+  ret = _IO_vfprintf (fp, format, args);
+  va_end (args);
   return ret;
 }
index 7a2580f7e35645159dea29badf41ecadb868eba9..1a329bbe26fc20b5c7f3a872c1af2381437880ee 100644 (file)
@@ -1,37 +1,49 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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 <string.h>
 
 int
-DEFUN(_IO_fputs, (str, fp),
-      const char *str AND _IO_FILE *fp)
+_IO_fputs (str, fp)
+      const char *str;
+      _IO_FILE *fp;
 {
-  _IO_size_t len = strlen(str);
-  CHECK_FILE(fp, EOF);
-  if (_IO_sputn(fp, str, len) != len)
-    return EOF;
-  return 1;
+  _IO_size_t len = strlen (str);
+  int result;
+  CHECK_FILE (fp, EOF);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  if (_IO_sputn (fp, str, len) != len)
+    result = EOF;
+  else
+    result = 1;
+  _IO_cleanup_region_end (1);
+  return result;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fputs, fputs)
+#endif
index 8516cf30c1473ef6f4e6badb8b889b1a1a00b4f7..c83d2b638c97d99fee08538d368521c897e5aac5 100644 (file)
@@ -1,38 +1,49 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
 _IO_size_t
-DEFUN(_IO_fread, (buf, size, count, fp),
-      void *buf AND _IO_size_t size AND _IO_size_t count AND _IO_FILE* fp)
+_IO_fread (buf, size, count, fp)
+     void *buf;
+     _IO_size_t size;
+     _IO_size_t count;
+     _IO_FILE *fp;
 {
   _IO_size_t bytes_requested = size*count;
   _IO_size_t bytes_read;
-  CHECK_FILE(fp, 0);
+  CHECK_FILE (fp, 0);
   if (bytes_requested == 0)
     return 0;
-  bytes_read = _IO_sgetn(fp, (char *)buf, bytes_requested);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  bytes_read = _IO_sgetn (fp, (char *) buf, bytes_requested);
+  _IO_cleanup_region_end (1);
   return bytes_requested == bytes_read ? count : bytes_read / size;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fread, fread)
+#endif
index ac8a3deb12d1a943c03ba81f4a7e9d68041bd8e7..a8d816f5a393a549393c62b267ec729f9685e99b 100644 (file)
@@ -1,43 +1,56 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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 <errno.h>
 
 int
-DEFUN(_IO_fsetpos, (fp, posp),
-      _IO_FILE* fp AND const _IO_fpos_t *posp)
+_IO_fsetpos (fp, posp)
+     _IO_FILE *fp;
+     const _IO_fpos_t *posp;
 {
-  CHECK_FILE(fp, EOF);
-  if (_IO_seekpos(fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD)
+  int result;
+  CHECK_FILE (fp, EOF);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  if (_IO_seekpos (fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD)
     {
-      /*ANSI explicily requires setting errno to a positive value on failure.*/
+      /* ANSI explicitly requires setting errno to a positive value on
+        failure.  */
 #ifdef EIO
       if (errno == 0)
-       errno = EIO;
+       __set_errno (EIO);
 #endif
-      return EOF;
+      result = EOF;
     }
-  return 0;
+  else
+    result = 0;
+  _IO_cleanup_region_end (1);
+  return result;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fsetpos, fsetpos)
+#endif
index d49ddaac82137e17c87c52f4f6c96680840b79e2..d8a1ce1d24239a66e5e2937beb10cca59456f1d9 100644 (file)
@@ -1,45 +1,53 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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 <errno.h>
 /* ANSI explicily requires setting errno to a positive value on failure. */
 
 long int
-DEFUN(_IO_ftell, (fp),
-      _IO_FILE* fp)
+_IO_ftell (fp)
+     _IO_FILE *fp;
 {
   _IO_pos_t pos;
-  CHECK_FILE(fp, -1L);
-  pos = _IO_seekoff(fp, 0, _IO_seek_cur, 0);
+  CHECK_FILE (fp, -1L);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0);
+  _IO_cleanup_region_end (1);
   if (pos == _IO_pos_BAD)
     {
 #ifdef EIO
       if (errno == 0)
-       errno = EIO;
+       __set_errno (EIO);
 #endif
       return -1L;
     }
-  return _IO_pos_as_off(pos);
+  return _IO_pos_as_off (pos);
 }
+
+#ifdef weak_alias
+weak_alias (_IO_ftell, ftell)
+#endif
index eb3cd32b028a05e9e09ff9f3ee0bae0af11808de..5bc525ffc704d6c4d5cd3cd4074f2f3edbf1b676 100644 (file)
@@ -1,44 +1,54 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
 _IO_size_t
-DEFUN(_IO_fwrite, (buf, size, count, fp),
-      const void* buf AND _IO_size_t size AND _IO_size_t count
-      AND _IO_FILE *fp)
+_IO_fwrite (buf, size, count, fp)
+     const void *buf;
+     _IO_size_t size;
+     _IO_size_t count;
+     _IO_FILE *fp;
 {
-  _IO_size_t request = size*count;
+  _IO_size_t request = size * count;
   _IO_size_t written;
-  CHECK_FILE(fp, 0);
+  CHECK_FILE (fp, 0);
   if (request == 0)
     return 0;
-  written = _IO_sputn(fp, (const char *)buf, request);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  written = _IO_sputn (fp, (const char *) buf, request);
+  _IO_cleanup_region_end (1);
   /* Many traditional implementations return 0 if size==0 && count > 0,
-     but ANSI seems to require us to return count in this case. */
+     but ANSI requires us to return count in this case. */
   if (written == request)
     return count;
   else
-    return written/size;
+    return written / size;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_fwrite, fwrite)
+#endif
diff --git a/libio/iogetc.c b/libio/iogetc.c
new file mode 100644 (file)
index 0000000..f7465f1
--- /dev/null
@@ -0,0 +1,48 @@
+/* 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 _IO_getc
+
+int
+_IO_getc (fp)
+     _IO_FILE *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;
+}
+
+#undef getc
+
+#ifdef weak_alias
+weak_alias (_IO_getc, getc)
+#endif
index ee6c0bf1f197e2aab139a5ad45d6927292a384a0..50918b3e8dcc1e3ebc95d49acad6b80c11d9f69c 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1994 Free Software Foundation
+/* Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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.  */
 
 #ifdef __STDC__
 #include <stdlib.h>
@@ -36,36 +37,49 @@ the executable file might be covered by the GNU General Public License. */
    null terminator), or -1 on error or EOF.  */
 
 _IO_ssize_t
-DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
-      char **lineptr AND _IO_size_t *n AND int delimiter AND _IO_FILE *fp)
+_IO_getdelim (lineptr, n, delimiter, fp)
+     char **lineptr;
+     _IO_size_t *n;
+     int delimiter;
+     _IO_FILE *fp;
 {
-  register _IO_ssize_t cur_len = 0;
+  int result;
+  _IO_ssize_t cur_len = 0;
   _IO_ssize_t len;
 
   if (lineptr == NULL || n == NULL)
     {
-#ifdef EINVAL
-      errno = EINVAL;
-#endif
+      MAYBE_SET_EINVAL;
       return -1;
     }
   CHECK_FILE (fp, -1);
-  if (_IO_ferror (fp))
-    return -1;
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  if (_IO_ferror_unlocked (fp))
+    {
+      result = -1;
+      goto unlock_return;
+    }
 
   if (*lineptr == NULL || *n == 0)
     {
       *n = 120;
       *lineptr = (char *) malloc (*n);
       if (*lineptr == NULL)
-       return -1;
+       {
+         result = -1;
+         goto unlock_return;
+       }
     }
 
   len = fp->_IO_read_end - fp->_IO_read_ptr;
   if (len <= 0)
     {
       if (__underflow (fp) == EOF)
-       return -1;
+       {
+         result = -1;
+         goto unlock_return;
+       }
       len = fp->_IO_read_end - fp->_IO_read_ptr;
     }
 
@@ -76,16 +90,19 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
       t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
       if (t != NULL)
        len = (t - fp->_IO_read_ptr) + 1;
-      /* make enough space for len+1 (for final NUL) bytes. */
+      /* Make enough space for len+1 (for final NUL) bytes.  */
       needed = cur_len + len + 1;
       if (needed > *n)
        {
-         if (t == NULL && needed < 2 * *n)
+         if (needed < 2 * *n)
            needed = 2 * *n;  /* Be generous. */
          *n = needed;
          *lineptr = (char *) realloc (*lineptr, needed);
          if (*lineptr == NULL)
-           return -1;
+           {
+             result = -1;
+             goto unlock_return;
+           }
        }
       memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
       fp->_IO_read_ptr += len;
@@ -95,5 +112,14 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
       len = fp->_IO_read_end - fp->_IO_read_ptr;
     }
   (*lineptr)[cur_len] = '\0';
-  return cur_len;
+  result = cur_len;
+
+unlock_return:
+  _IO_cleanup_region_end (1);
+  return result;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_getdelim, __getdelim)
+weak_alias (_IO_getdelim, getdelim)
+#endif
index 278905d135d374796b625956ccfb5f3dc7d1890b..bd1a7431f362349b6be064b186896af71c1d1832 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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 <string.h>
@@ -34,38 +35,41 @@ the executable file might be covered by the GNU General Public License. */
    If extract_delim > 0, insert delim in output. */
 
 _IO_size_t
-DEFUN(_IO_getline, (fp, buf, n, delim, extract_delim),
-      _IO_FILE *fp AND char* buf AND _IO_size_t n
-      AND int delim AND int extract_delim)
+_IO_getline (fp, buf, n, delim, extract_delim)
+     _IO_FILE *fp;
+     char *buf;
+     _IO_size_t n;
+     int delim;
+     int extract_delim;
 {
-  register char *ptr = buf;
+  char *ptr = buf;
   do
     {
       _IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr;
       char *t;
       if (len <= 0)
-       if (__underflow(fp) == EOF)
+       if (__underflow (fp) == EOF)
          break;
        else
          len = fp->_IO_read_end - fp->_IO_read_ptr;
-      if (len >= n)
+      if ((_IO_size_t) len >= n)
        len = n;
-      t = (char*)memchr((void*)fp->_IO_read_ptr, delim, len);
+      t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
       if (t != NULL)
        {
          _IO_size_t old_len = ptr-buf;
          len = t - fp->_IO_read_ptr;
          if (extract_delim >= 0)
            {
-             t++;
+             ++t;
              if (extract_delim > 0)
-               len++;
+               ++len;
            }
-         memcpy((void*)ptr, (void*)fp->_IO_read_ptr, len);
+         memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
          fp->_IO_read_ptr = t;
          return old_len + len;
        }
-      memcpy((void*)ptr, (void*)fp->_IO_read_ptr, len);
+      memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
       fp->_IO_read_ptr += len;
       ptr += len;
       n -= len;
index f45d9c16e3fd1403201aa2bc80099a193f82bf9e..9e88ca1037ae55c70fd7b08fa748a1f43396356e 100644 (file)
@@ -1,47 +1,71 @@
-/* 
-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, 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 <limits.h>
 
 char*
-DEFUN(_IO_gets, (buf),
-      char* buf)
+_IO_gets (buf)
+     char *buf;
 {
   _IO_size_t count;
-  int ch = _IO_getc (_IO_stdin);
+  int ch;
+  char *retval;
+
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                           _IO_stdin);
+  _IO_flockfile (_IO_stdin);
+  ch = _IO_getc_unlocked (_IO_stdin);
   if (ch == EOF)
-    return NULL;
+    {
+      retval = NULL;
+      goto unlock_return;
+    }
   if (ch == '\n')
     count = 0;
   else
     {
-      buf[0] = (char)ch;
-      count = _IO_getline(_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
+      buf[0] = (char) ch;
+      count = _IO_getline (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
       if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
-       return NULL;
+       {
+         retval = NULL;
+         goto unlock_return;
+       }
     }
   buf[count] = 0;
-  return buf;
+  retval = buf;
+unlock_return:
+  _IO_cleanup_region_end (1);
+  return retval;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_gets, gets)
+#endif
+
+#ifdef _LIBC
+link_warning (gets, "the `gets' function is dangerous and should not be used.")
+#endif
index 0e502b712c3bf726aa8634f57487d5fe59dcd042..087715b349b8a4aed5850749f8395ff43eb6a538 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
@@ -31,34 +32,38 @@ static char const zeroes[PADSIZE] =
 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
 
 _IO_ssize_t
-DEFUN(_IO_padn, (fp, pad, count),
-      _IO_FILE *fp AND int pad AND _IO_ssize_t count)
+_IO_padn (fp, pad, count)
+      _IO_FILE *fp;
+      int pad;
+      _IO_ssize_t count;
 {
   char padbuf[PADSIZE];
   const char *padptr;
-  register int i;
-  _IO_size_t written = 0, w;
-  
+  int i;
+  _IO_size_t written = 0;
+  _IO_size_t w;
+
   if (pad == ' ')
     padptr = blanks;
   else if (pad == '0')
     padptr = zeroes;
   else
     {
-      for (i = PADSIZE; --i >= 0; ) padbuf[i] = pad;
+      for (i = PADSIZE; --i >= 0; )
+       padbuf[i] = pad;
       padptr = padbuf;
     }
   for (i = count; i >= PADSIZE; i -= PADSIZE)
     {
-      w = _IO_sputn(fp, padptr, PADSIZE);
+      w = _IO_sputn (fp, padptr, PADSIZE);
       written += w;
       if (w != PADSIZE)
        return written;
     }
-      
+
   if (i > 0)
     {
-      w = _IO_sputn(fp, padptr, i);
+      w = _IO_sputn (fp, padptr, i);
       written += w;
     }
   return written;
index ef6ad12449f1cb0b3518c6acb366604ae31ef054..434008609f476c2f161188fa58a3b3bfbd8609a7 100644 (file)
@@ -1,55 +1,60 @@
-/* 
-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. */
-
-/*  written by Per Bothner (bothner@cygnus.com) */
-
-#define _POSIX_SOURCE
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
+   Written by Per Bothner <bothner@cygnus.com>.
+
+   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.  */
+
+#ifndef _POSIX_SOURCE
+# define _POSIX_SOURCE
+#endif
 #include "libioP.h"
-#include <sys/types.h>
 #if _IO_HAVE_SYS_WAIT
 #include <signal.h>
 #include <unistd.h>
 #ifdef __STDC__
 #include <stdlib.h>
 #endif
+#ifdef _LIBC
+# include <unistd.h>
+#endif
+#include <sys/types.h>
 #include <sys/wait.h>
 
 #ifndef _IO_fork
 #define _IO_fork vfork /* defined in libiberty, if needed */
-_IO_pid_t _IO_fork();
+extern _IO_pid_t _IO_fork __P ((void));
 #endif
 
 #endif /* _IO_HAVE_SYS_WAIT */
 
 #ifndef _IO_pipe
 #define _IO_pipe pipe
-extern int _IO_pipe();
+extern int _IO_pipe __P ((int des[2]));
 #endif
 
 #ifndef _IO_dup2
 #define _IO_dup2 dup2
-extern int _IO_dup2();
+extern int _IO_dup2 __P ((int fd, int fd2));
 #endif
 
 #ifndef _IO_waitpid
@@ -75,17 +80,19 @@ typedef struct _IO_proc_file _IO_proc_file;
 static struct _IO_proc_file *proc_file_chain = NULL;
 
 _IO_FILE *
-DEFUN(_IO_proc_open, (fp, command, mode),
-      _IO_FILE* fp AND const char *command AND const char *mode)
+_IO_proc_open (fp, command, mode)
+     _IO_FILE *fp;
+     const char *command;
+     const char *mode;
 {
 #if _IO_HAVE_SYS_WAIT
-  int read_or_write;
+  volatile int read_or_write;
+  volatile int parent_end, child_end;
   int pipe_fds[2];
-  int parent_end, child_end;
   _IO_pid_t child_pid;
-  if (_IO_file_is_open(fp))
+  if (_IO_file_is_open (fp))
     return NULL;
-  if (_IO_pipe(pipe_fds) < 0)
+  if (_IO_pipe (pipe_fds) < 0)
     return NULL;
   if (mode[0] == 'r')
     {
@@ -99,17 +106,17 @@ DEFUN(_IO_proc_open, (fp, command, mode),
       child_end = pipe_fds[0];
       read_or_write = _IO_NO_READS;
     }
-  ((_IO_proc_file*)fp)->pid = child_pid = _IO_fork();
+  ((_IO_proc_file *) fp)->pid = child_pid = _IO_fork ();
   if (child_pid == 0)
     {
       int child_std_end = mode[0] == 'r' ? 1 : 0;
-      _IO_close(parent_end);
+      _IO_close (parent_end);
       if (child_end != child_std_end)
        {
-         _IO_dup2(child_end, child_std_end);
-         _IO_close(child_end);
+         _IO_dup2 (child_end, child_std_end);
+         _IO_close (child_end);
        }
-      /* Posix.2:  "popen() shall ensure that any streams from previous
+      /* POSIX.2:  "popen() shall ensure that any streams from previous
          popen() calls that remain open in the parent process are closed
         in the new child process." */
       while (proc_file_chain)
@@ -118,20 +125,20 @@ DEFUN(_IO_proc_open, (fp, command, mode),
          proc_file_chain = proc_file_chain->next;
        }
 
-      _IO_execl("/bin/sh", "sh", "-c", command, (char *)0);
-      _IO__exit(127);
+      _IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
+      _IO__exit (127);
     }
-  _IO_close(child_end);
+  _IO_close (child_end);
   if (child_pid < 0)
     {
-      _IO_close(parent_end);
+      _IO_close (parent_end);
       return NULL;
     }
-  _IO_fileno(fp) = parent_end;
+  _IO_fileno (fp) = parent_end;
 
   /* Link into proc_file_chain. */
-  ((_IO_proc_file*)fp)->next = proc_file_chain;
-  proc_file_chain = (_IO_proc_file*)fp;
+  ((_IO_proc_file *) fp)->next = proc_file_chain;
+  proc_file_chain = (_IO_proc_file *) fp;
 
   _IO_mask_flags (fp, read_or_write, _IO_NO_READS|_IO_NO_WRITES);
   return fp;
@@ -141,28 +148,45 @@ DEFUN(_IO_proc_open, (fp, command, mode),
 }
 
 _IO_FILE *
-DEFUN(_IO_popen, (command, mode),
-      const char *command AND const char *mode)
+_IO_popen (command, mode)
+     const char *command;
+     const char *mode;
 {
-  _IO_proc_file *fpx = (_IO_proc_file*)malloc(sizeof(_IO_proc_file));
-  _IO_FILE *fp = (_IO_FILE*)fpx;
-  if (fp == NULL)
+  struct locked_FILE
+  {
+    struct _IO_proc_file fpx;
+#ifdef _IO_MTSAFE_IO
+    _IO_lock_t lock;
+#endif
+  } *new_f;
+  _IO_FILE *fp;
+
+  new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
+  if (new_f == NULL)
     return NULL;
-  _IO_init(fp, 0);
-  _IO_JUMPS(fp) = &_IO_proc_jumps;
-  _IO_file_init(fp);
+#ifdef _IO_MTSAFE_IO
+  new_f->fpx.file.file._lock = &new_f->lock;
+#endif
+  fp = (_IO_FILE*)&new_f->fpx;
+  _IO_init (fp, 0);
+  _IO_JUMPS (fp) = &_IO_proc_jumps;
+  _IO_file_init (fp);
 #if  !_IO_UNIFIED_JUMPTABLES
-  ((struct _IO_FILE_plus*)fp)->vtable = NULL;
+  ((struct _IO_FILE_plus *) fp)->vtable = NULL;
 #endif
   if (_IO_proc_open (fp, command, mode) != NULL)
     return fp;
-  free (fpx);
+  free (new_f);
   return NULL;
 }
 
+#ifdef strong_alias
+strong_alias (_IO_popen, popen);
+#endif
+
 int
-DEFUN(_IO_proc_close, (fp),
-      _IO_FILE *fp)
+_IO_proc_close (fp)
+     _IO_FILE *fp;
 {
   /* This is not name-space clean. FIXME! */
 #if _IO_HAVE_SYS_WAIT
@@ -170,11 +194,11 @@ DEFUN(_IO_proc_close, (fp),
   _IO_proc_file **ptr = &proc_file_chain;
   _IO_pid_t wait_pid;
   int status = -1;
-  
+
   /* Unlink from proc_file_chain. */
   for ( ; *ptr != NULL; ptr = &(*ptr)->next)
     {
-      if (*ptr == (_IO_proc_file*)fp)
+      if (*ptr == (_IO_proc_file *) fp)
        {
          *ptr = (*ptr)->next;
          status = 0;
@@ -182,7 +206,7 @@ DEFUN(_IO_proc_close, (fp),
        }
     }
 
-  if (status < 0 || _IO_close(_IO_fileno(fp)) < 0)
+  if (status < 0 || _IO_close (_IO_fileno(fp)) < 0)
     return -1;
   /* POSIX.2 Rationale:  "Some historical implementations either block
      or ignore the signals SIGINT, SIGQUIT, and SIGHUP while waiting
@@ -190,8 +214,9 @@ DEFUN(_IO_proc_close, (fp),
      described in POSIX.2, such implementations are not conforming." */
   do
     {
-      wait_pid = _IO_waitpid (((_IO_proc_file*)fp)->pid, &wstatus, 0);
-    } while (wait_pid == -1 && errno == EINTR);
+      wait_pid = _IO_waitpid (((_IO_proc_file *) fp)->pid, &wstatus, 0);
+    }
+  while (wait_pid == -1 && errno == EINTR);
   if (wait_pid == -1)
     return -1;
   return wstatus;
diff --git a/libio/ioputc.c b/libio/ioputc.c
new file mode 100644 (file)
index 0000000..3c35c36
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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 _IO_putc
+
+int
+_IO_putc (c, fp)
+     int c;
+     _IO_FILE *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;
+}
+
+#undef putc
+
+#ifdef weak_alias
+weak_alias (_IO_putc, putc)
+#endif
index f0a81642853dff8c60a574f720be5725edbeaac6..ab5e6aaa4cc95aa490a93828b6a40df6d4d51918 100644 (file)
@@ -1,38 +1,49 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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 <string.h>
 
 int
-DEFUN(_IO_puts, (str),
-      const char *str)
+_IO_puts (str)
+     const char *str;
 {
-  _IO_size_t len = strlen(str);
-  if (_IO_sputn(_IO_stdout, str, len) != len)
-    return EOF;
-  if (_IO_putc('\n', _IO_stdout) == EOF)
-    return EOF;
-  return len+1;
+  int result;
+  _IO_size_t len = strlen (str);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
+                           _IO_stdout);
+  _IO_flockfile (_IO_stdout);
+  if (_IO_sputn (_IO_stdout, str, len) == len
+      && _IO_putc_unlocked ('\n', _IO_stdout) != EOF)
+    result = len + 1;
+  else
+    result = EOF;
+  _IO_cleanup_region_end (1);
+  return result;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_puts, puts)
+#endif
index 06f4b9d2fe1037b0cb6a6c51f7617a96ed9250e4..8c642165f637aaa3e09f1f1f0fb5505e4a9fa45a 100644 (file)
@@ -1,32 +1,36 @@
-/* 
-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>
 
 _IO_pos_t
-DEFUN(_IO_seekoff, (fp, offset, dir, mode),
-      _IO_FILE* fp AND _IO_off_t offset AND int dir AND int mode)
+_IO_seekoff (fp, offset, dir, mode)
+     _IO_FILE *fp;
+     _IO_off_t offset;
+     int dir;
+     int mode;
 {
   /* If we have a backup buffer, get rid of it, since the __seekoff
      callback may not know to do the right thing about it.
index 1884f9df8f7c89e407f1a297aad1522b05a437fb..1ae88fb84823781770f2f7521c191ce4e2ba9d7f 100644 (file)
@@ -1,32 +1,35 @@
-/* 
-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>
 
 _IO_pos_t
-DEFUN(_IO_seekpos, (fp, pos, mode),
-      _IO_FILE* fp AND _IO_pos_t pos AND int mode)
+_IO_seekpos (fp, pos, mode)
+     _IO_FILE *fp;
+     _IO_pos_t pos;
+     int mode;
 {
   /* If we have a backup buffer, get rid of it, since the __seekoff
      callback may not know to do the right thing about it.
index eb78d75d9ab203d867fc15654124c6321515e881..f140a9ad046eb68daabb015bdcd9754d1113bb94 100644 (file)
@@ -1,36 +1,46 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
 void
-DEFUN(_IO_setbuffer, (fp, buf, size),
-      _IO_FILE *fp AND char *buf AND _IO_size_t size)
+_IO_setbuffer (fp, buf, size)
+     _IO_FILE *fp;
+     char *buf;
+     _IO_size_t size;
 {
-  CHECK_FILE(fp, );
+  CHECK_FILE (fp, );
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
   fp->_flags &= ~_IO_LINE_BUF;
   if (!buf)
     size = 0;
   (void) _IO_SETBUF (fp, buf, size);
+  _IO_cleanup_region_end (1);
 }
+
+#ifdef weak_alias
+weak_alias (_IO_setbuffer, setbuffer)
+#endif
index 1b2da4f104c987e59a99ad814a335d9c1af3b5b4..65eeea51a6faa6fce20eeafc4ff64b8dc069f6ab 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
@@ -29,10 +30,16 @@ the executable file might be covered by the GNU General Public License. */
 #define _IONBF 2 /* No buffering. */
 
 int
-DEFUN(_IO_setvbuf, (fp, buf, mode, size),
-      _IO_FILE* fp AND char* buf AND int mode AND _IO_size_t size)
+_IO_setvbuf (fp, buf, mode, size)
+     _IO_FILE *fp;
+     char *buf;
+     int mode;
+     _IO_size_t size;
 {
-  CHECK_FILE(fp, EOF);
+  int result;
+  CHECK_FILE (fp, EOF);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
   switch (mode)
     {
     case _IOFBF:
@@ -55,24 +62,39 @@ DEFUN(_IO_setvbuf, (fp, buf, mode, size),
                 A possibly cleaner alternative would be to add an
                 extra flag, but then flags are a finite resource.  */
              if (_IO_DOALLOCATE (fp) < 0)
-               return EOF;
+               {
+                 result = EOF;
+                 goto unlock_return;
+               }
              fp->_IO_file_flags &= ~_IO_LINE_BUF;
            }
-         return 0;
+         result = 0;
+         goto unlock_return;
        }
       break;
     case _IOLBF:
       fp->_IO_file_flags &= ~_IO_UNBUFFERED;
       fp->_IO_file_flags |= _IO_LINE_BUF;
       if (buf == NULL)
-       return 0;
+       {
+         result = 0;
+         goto unlock_return;
+       }
       break;
     case _IONBF:
       buf = NULL;
       size = 0;
       break;
     default:
-      return EOF;
+      result = EOF;
+      goto unlock_return;
     }
-  return _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
+  result = _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
+unlock_return:
+  _IO_cleanup_region_end (1);
+  return result;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_setvbuf, setvbuf)
+#endif
index b873eb4455d50ac3d2ad3a3d3157881bdcbd2214..704a6dbd72d949efcaa8c73f9df849bbb9f6b7c8 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
@@ -31,17 +32,19 @@ the executable file might be covered by the GNU General Public License. */
 #endif
 
 int
-_IO_sprintf
 #ifdef __STDC__
-  (char *string, const char* format, ...)
+_IO_sprintf (char *string, const char* format, ...)
 #else
-(string, format, va_alist) char *string; char *format; va_dcl
+_IO_sprintf (string, format, va_alist)
+     char *string;
+     char *format;
+     va_dcl
 #endif
 {
   int ret;
   va_list args;
-  _IO_va_start(args, format);
-  ret = _IO_vsprintf(string, format, args);
-  va_end(args);
+  _IO_va_start (args, format);
+  ret = _IO_vsprintf (string, format, args);
+  va_end (args);
   return ret;
 }
index d663b42430ca09174f5f2c1ca22950a777b45abd..a6ede4302980fec13b518c9309b4285de37f6d94 100644 (file)
@@ -1,4 +1,4 @@
-/*  This is part of libio/iostream, providing -*- C++ -*- input/output. 
+/*  This is part of libio/iostream, providing -*- C++ -*- input/output.
 Copyright (C) 1993 Free Software Foundation
 
 This file is part of the GNU IO Library.  This library is free
@@ -96,7 +96,11 @@ class ostream : virtual public ios
 #endif
     ostream& operator<<(double n);
     ostream& operator<<(float n) { return operator<<((double)n); }
+#if _G_HAVE_LONG_DOUBLE_IO
+    ostream& operator<<(long double n);
+#else
     ostream& operator<<(long double n) { return operator<<((double)n); }
+#endif
     ostream& operator<<(__omanip func) { return (*func)(*this); }
     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
     ostream& operator<<(streambuf*);
index 033f652a06700b9373268d04bfa7b95a2128de11..07f38e747bf363e42a5183f547cba527b8b2e37b 100644 (file)
@@ -1,35 +1,46 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
 int
-DEFUN(_IO_ungetc, (c, fp),
-      int c AND _IO_FILE *fp)
+_IO_ungetc (c, fp)
+     int c;
+     _IO_FILE *fp;
 {
-  CHECK_FILE(fp, EOF);
+  int result;
+  CHECK_FILE (fp, EOF);
   if (c == EOF)
     return EOF;
-  return _IO_sputbackc(fp, (unsigned char)c);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  result = _IO_sputbackc (fp, (unsigned char) c);
+  _IO_cleanup_region_end (1);
+  return result;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_ungetc, ungetc)
+#endif
index 06d926d3590308a3a2d147c8601475de792f5fab..34919588ce10083baf3cdef72596f9b59464c0be 100644 (file)
@@ -1,40 +1,57 @@
-/* 
-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 "strfile.h"
 
 int
-DEFUN(_IO_vsprintf, (string, format, args),
-      char *string AND const char *format AND _IO_va_list args)
+_IO_vsprintf (string, format, args)
+     char *string;
+     const char *format;
+     _IO_va_list args;
 {
   _IO_strfile sf;
+#ifdef _IO_MTSAFE_IO
+  _IO_lock_t lock;
+#endif
   int ret;
-  _IO_init((_IO_FILE*)&sf, 0);
-  _IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps;
-  _IO_str_init_static ((_IO_FILE*)&sf, string, -1, string);
-  ret = _IO_vfprintf((_IO_FILE*)&sf, format, args);
-  _IO_putc('\0', (_IO_FILE*)&sf);
+
+#ifdef _IO_MTSAFE_IO
+  sf._sbf._f._lock = &lock;
+#endif
+  _IO_init (&sf._sbf._f, 0);
+  _IO_JUMPS (&sf._sbf._f) = &_IO_str_jumps;
+  _IO_str_init_static (&sf._sbf._f, string, -1, string);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, &sf);
+  _IO_flockfile (&sf._sbf._f);
+  ret = _IO_vfprintf (&sf._sbf._f, format, args);
+  _IO_putc_unlocked ('\0', &sf._sbf._f);
+  _IO_cleanup_region_end (1);
   return ret;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_vsprintf, vsprintf)
+#endif
index 529778098a5536dc0942a4bd9a3c76e941e0231d..21600f53efb24e917cb41be7c4c7e0b9b273b31e 100644 (file)
@@ -1,37 +1,54 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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"
 
 int
-DEFUN(_IO_vsscanf, (string, format, args),
-      const char *string AND const char *format AND _IO_va_list args)
+_IO_vsscanf (string, format, args)
+     const char *string;
+     const char *format;
+     _IO_va_list args;
 {
+  int ret;
   _IO_strfile sf;
-  _IO_init((_IO_FILE*)&sf, 0);
-  _IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps;
-  _IO_str_init_static ((_IO_FILE*)&sf, (char*)string, 0, NULL);
-  return _IO_vfscanf((_IO_FILE*)&sf, format, args, NULL);
+#ifdef _IO_MTSAFE_IO
+  _IO_lock_t lock;
+  sf._sbf._f._lock = &lock;
+#endif
+  _IO_init (&sf._sbf._f, 0);
+  _IO_JUMPS (&sf._sbf._f) = &_IO_str_jumps;
+  _IO_str_init_static (&sf._sbf._f, (char*)string, 0, NULL);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, &sf);
+  _IO_flockfile (&sf._sbf._f);
+  ret = _IO_vfscanf (&sf._sbf._f, format, args, NULL);
+  _IO_cleanup_region_end (1);
+  return ret;
 }
+
+#ifdef weak_alias
+weak_alias (_IO_vsscanf, __vsscanf)
+weak_alias (_IO_vsscanf, vsscanf)
+#endif
index c7aea0a6c2455f17e4f438785d3a537db827a71a..c79b623920516bf05f9fdf2c76ee884f6f8ca5b3 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation
 
 This file is part of the GNU IO Library.  This library is free
@@ -153,6 +153,14 @@ the executable file might be covered by the GNU General Public License. */
 
 struct _IO_jump_t;  struct _IO_FILE;
 
+/* Handle lock.  */
+#ifdef _IO_MTSAFE_IO
+# include <stdio-lock.h>
+#else
+typedef void _IO_lock_t;
+#endif
+
+
 struct _IO_marker {
   struct _IO_marker *_next;
   struct _IO_FILE *_sbuf;
@@ -196,20 +204,22 @@ struct _IO_FILE {
   char *_IO_save_end; /* Pointer to end of non-current get area. */
 
   struct _IO_marker *_markers;
-  
+
   struct _IO_FILE *_chain;
-  
+
   int _fileno;
   int _blksize;
   _IO_off_t _offset;
-  
+
 #define __HAVE_COLUMN /* temporary */
   /* 1+column number of pbase(); 0 is unknown. */
   unsigned short _cur_column;
   char _unused;
   char _shortbuf[1];
-  
+
   /*  char* _save_gptr;  char* _save_egptr; */
+
+  _IO_lock_t *_lock;
 };
 
 #ifndef __cplusplus
@@ -222,6 +232,26 @@ extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
 #define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
 #define _IO_stderr ((_IO_FILE*)(&_IO_stderr_))
 
+
+/* Define the user-visible type, with user-friendly member names.  */
+typedef struct
+{
+  _IO_ssize_t (*read) __P ((struct _IO_FILE *, void *, _IO_ssize_t));
+  _IO_ssize_t (*write) __P ((struct _IO_FILE *, const void *, _IO_ssize_t));
+  _IO_fpos_t (*seek) __P ((struct _IO_FILE *, _IO_off_t, int));
+  int (*close) __P ((struct _IO_FILE *));
+} _IO_cookie_io_functions_t;
+
+/* Special file type for fopencookie function.  */
+struct _IO_cookie_file
+{
+  struct _IO_FILE file;
+  const void *vtable;
+  void *cookie;
+  _IO_cookie_io_functions_t io_functions;
+};
+
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -230,26 +260,47 @@ extern int __underflow __P((_IO_FILE*));
 extern int __uflow __P((_IO_FILE*));
 extern int __overflow __P((_IO_FILE*, int));
 
-#define _IO_getc(_fp) \
+#define _IO_getc_unlocked(_fp) \
        ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow(_fp) \
        : *(unsigned char*)(_fp)->_IO_read_ptr++)
-#define _IO_peekc(_fp) \
+#define _IO_peekc_unlocked(_fp) \
        ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
          && __underflow(_fp) == EOF ? EOF \
        : *(unsigned char*)(_fp)->_IO_read_ptr)
 
-#define _IO_putc(_ch, _fp) \
+#define _IO_putc_unlocked(_ch, _fp) \
    (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
     ? __overflow(_fp, (unsigned char)(_ch)) \
     : (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch)))
 
-#define _IO_feof(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
-#define _IO_ferror(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
+#define _IO_feof_unclocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
+#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
+
+extern int _IO_getc __P ((_IO_FILE *__fp));
+extern int _IO_putc __P ((int __c, _IO_FILE *__fp));
+extern int _IO_feof __P ((_IO_FILE *__fp));
+extern int _IO_ferror __P ((_IO_FILE *__fp));
+
+extern int _IO_peekc_locked __P ((_IO_FILE *__fp));
 
 /* This one is for Emacs. */
 #define _IO_PENDING_OUTPUT_COUNT(_fp)  \
        ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
 
+extern void _IO_flockfile __P ((_IO_FILE *));
+extern void _IO_funlockfile __P ((_IO_FILE *));
+extern int _IO_ftrylockfile __P ((_IO_FILE *));
+
+#ifndef _IO_MTSAFE_IO
+# define _IO_flockfile(_fp) /**/
+# define _IO_funlockfile(_fp) /**/
+# define _IO_ftrylockfile(_fp) /**/
+# define _IO_cleanup_region_start(_fct, _fp) /**/
+# define _IO_cleanup_region_end(_Doit) /**/
+#endif /* !_IO_MTSAFE_IO */
+
+#define _IO_peekc(_fp) _IO_peekc_locked (_fp)
+
 extern int _IO_vfscanf __P((_IO_FILE*, const char*, _IO_va_list, int*));
 extern int _IO_vfprintf __P((_IO_FILE*, const char*, _IO_va_list));
 extern _IO_ssize_t _IO_padn __P((_IO_FILE *, int, _IO_ssize_t));
index 7efc519aad5b850c6205b7abe4062fcd61c81d24..ea3f36e33952b247d9a4936dc0cc694a9a1f46f7 100644 (file)
@@ -1,31 +1,37 @@
-/* 
-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 <errno.h>
 #ifndef errno
 extern int errno;
 #endif
+#ifndef __set_errno
+/* This is a GNU libc special.  Simply set errno to the  given value here.  */
+#define __set_errno(Val) (errno = (Val))
+#endif
+#include <stdio-lock.h>
 
 #include "iolibio.h"
 
@@ -100,8 +106,8 @@ extern "C" {
 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
    It does not delete (free) it, but does everything else to finalize it/
    It matches the streambuf::~streambuf virtual destructor.  */
-typedef void (*_IO_finish_t) __P((_IO_FILE*)); /* finalize */
-#define _IO_FINISH(FP) JUMP0(__finish, FP)
+typedef void (*_IO_finish_t) __P((_IO_FILE*, int)); /* finalize */
+#define _IO_FINISH(FP) JUMP1(__finish, FP, 0)
 
 /* The 'overflow' hook flushes the buffer.
    The second argument is a character, or EOF.
@@ -266,6 +272,9 @@ struct _IO_FILE_plus {
 
 /* Generic functions */
 
+extern _IO_fpos_t _IO_seekoff __P((_IO_FILE*, _IO_off_t, int, int));
+extern _IO_fpos_t _IO_seekpos __P((_IO_FILE*, _IO_fpos_t, int));
+
 extern int _IO_switch_to_get_mode __P((_IO_FILE*));
 extern void _IO_init __P((_IO_FILE*, int));
 extern int _IO_sputbackc __P((_IO_FILE*, int));
@@ -291,7 +300,7 @@ extern int _IO_seekmark __P((_IO_FILE *, struct _IO_marker *, int));
 extern int _IO_default_underflow __P((_IO_FILE*));
 extern int _IO_default_uflow __P((_IO_FILE*));
 extern int _IO_default_doallocate __P((_IO_FILE*));
-extern void _IO_default_finish __P((_IO_FILE *));
+extern void _IO_default_finish __P((_IO_FILE *, int));
 extern int _IO_default_pbackfail __P((_IO_FILE*, int));
 extern _IO_FILE* _IO_default_setbuf __P((_IO_FILE *, char*, _IO_ssize_t));
 extern _IO_size_t _IO_default_xsputn __P((_IO_FILE *, const void*, _IO_size_t));
@@ -347,7 +356,7 @@ extern _IO_ssize_t _IO_file_read __P((_IO_FILE*, void*, _IO_ssize_t));
 extern int _IO_file_sync __P((_IO_FILE*));
 extern int _IO_file_close_it __P((_IO_FILE*));
 extern _IO_fpos_t _IO_file_seek __P((_IO_FILE *, _IO_off_t, int));
-extern void _IO_file_finish __P((_IO_FILE*));
+extern void _IO_file_finish __P((_IO_FILE*, int));
 
 /* Other file functions. */
 extern _IO_FILE* _IO_file_attach __P((_IO_FILE *, int));
@@ -361,12 +370,20 @@ extern int _IO_str_underflow __P((_IO_FILE*));
 extern int _IO_str_overflow __P((_IO_FILE *, int));
 extern int _IO_str_pbackfail __P((_IO_FILE*, int));
 extern _IO_fpos_t _IO_str_seekoff __P((_IO_FILE*,_IO_off_t,int,int));
+extern void _IO_str_finish __P ((_IO_FILE*, int));
 
 /* Other strfile functions */
 extern void _IO_str_init_static __P((_IO_FILE *, char*, int, char*));
 extern void _IO_str_init_readonly __P((_IO_FILE *, const char*, int));
 extern _IO_ssize_t _IO_str_count __P ((_IO_FILE*));
 
+extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
+                              _IO_va_list args));
+extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
+extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
+                              __const char *format, _IO_va_list args));
+
+
 extern _IO_size_t _IO_getline __P((_IO_FILE*,char*,_IO_size_t,int,int));
 extern _IO_ssize_t _IO_getdelim __P((char**, _IO_size_t*, int, _IO_FILE*));
 extern double _IO_strtod __P((const char *, char **));
@@ -394,8 +411,52 @@ extern void (*_IO_cleanup_registration_needed) __P ((void));
 #endif
 #endif
 
-#define FREE_BUF(_B) free(_B)
-#define ALLOC_BUF(_S) (char*)malloc(_S)
+#if _G_HAVE_MMAP
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+
+#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+#if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
+#undef _G_HAVE_MMAP
+#define _G_HAVE_MMAP 0
+#endif
+
+#endif /* _G_HAVE_MMAP */
+
+#if _G_HAVE_MMAP
+
+#define ROUND_TO_PAGE(_S) \
+       (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
+
+#define FREE_BUF(_B, _S) \
+       munmap ((_B), ROUND_TO_PAGE (_S))
+#define ALLOC_BUF(_B, _S, _R) \
+       do {                                                                  \
+         (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S),                        \
+                               PROT_READ | PROT_WRITE,                       \
+                               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);          \
+         if ((_B) == (char *) -1)                                            \
+           return _R;                                                        \
+       } while (0)
+
+#else /* _G_HAVE_MMAP */
+
+#define FREE_BUF(_B, _S) \
+       free(_B)
+#define ALLOC_BUF(_B, _S, _R) \
+       do {                                                                  \
+         (_B) = (char*)malloc(_S);                                           \
+         if ((_B) == NULL)                                                   \
+           return _R;                                                        \
+       } while (0)
+
+#endif /* _G_HAVE_MMAP */
 
 #ifndef OS_FSTAT
 #define OS_FSTAT fstat
@@ -433,10 +494,18 @@ extern int _IO_fstat __P((int, struct stat *));
 }
 #endif
 
+#ifdef _IO_MTSAFE_IO
+/* check following! */
+#define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
+       { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
+         0, 0, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
+#else
 /* check following! */
 #define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD}
+#endif
 
 /* VTABLE_LABEL defines NAME as of the CLASS class.
    CNLENGTH is strlen(#CLASS).  */
@@ -480,7 +549,7 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
 #endif
 
 #ifdef EINVAL
-#define MAYBE_SET_EINVAL errno = EINVAL
+#define MAYBE_SET_EINVAL __set_errno (EINVAL)
 #else
 #define MAYBE_SET_EINVAL /* nothing */
 #endif
@@ -490,7 +559,7 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
        if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
        else { COERCE_FILE(FILE); \
               if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
-         { errno = EINVAL; return RET; }}
+         { MAYBE_SET_EINVAL; return RET; }}
 #else
 #define CHECK_FILE(FILE,RET) \
        COERCE_FILE(FILE)
index 320afd06d9be44065b8a640a346ec296b3716d5f..e430e602c8dcd6bbafdb4211dc1f2e4de5ecd5ef 100644 (file)
@@ -137,7 +137,7 @@ general_parsebuf::general_parsebuf(streambuf *buf, int delete_arg_buf)
     delete_buf = delete_arg_buf;
     sbuf = buf;
     int buf_size = 128;
-    char* buffer = ALLOC_BUF(buf_size);
+    char* buffer = (char*)malloc(buf_size);
     setb(buffer, buffer+buf_size, 1);
 //    setg(buffer, buffer, buffer);
 }
diff --git a/libio/peekc.c b/libio/peekc.c
new file mode 100644 (file)
index 0000000..0b3b514
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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 _IO_peekc
+
+int
+_IO_peekc_locked (fp)
+     _IO_FILE *fp;
+{
+  int result;
+  CHECK_FILE (fp, EOF);
+  _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+  _IO_flockfile (fp);
+  result = _IO_peekc_unlocked (fp);
+  _IO_cleanup_region_end (1);
+  return result;
+}
index 1d0ef85be90b36090e8860fe5d7d30ac2f490ea5..8453e33c34cd8a18d89eed06ad2f25f97cb30b5d 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993, 1994 Free Software Foundation
+/* Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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.  */
 
 
 /* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
@@ -31,10 +32,16 @@ the executable file might be covered by the GNU General Public License. */
 
 #include "libioP.h"
 
-
+#ifdef _IO_MTSAFE_IO
+#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
+  static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
+  struct _IO_FILE_plus NAME \
+    = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}
+#else
 #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
   struct _IO_FILE_plus NAME \
     = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}
+#endif
 
 DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
 DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS);
diff --git a/libio/stdio-lock.h b/libio/stdio-lock.h
new file mode 100644 (file)
index 0000000..42dc218
--- /dev/null
@@ -0,0 +1 @@
+/* this will be used later*/
index 76ce5b7a8756aebec7dead85f118134812e1d7c9..788c055e8d15c0ee7e8aed952fae8d47d204f1be 100644 (file)
@@ -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
index 8df66a7c19309cbb35b395f91e650f9a5acdb0b2..680c8a497a4116b7339097c75599a71dd99feaab 100644 (file)
@@ -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
 
index ee9780bdaf5ed78d84fd72a8d25ed83e2dd3f70b..4776250ff8d943b2ce7311f81a9214638ae1fde3 100644 (file)
@@ -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)
-     FILEfp;
+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 (file)
index 0000000..2a1ba70
--- /dev/null
@@ -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 (file)
index 0000000..4773599
--- /dev/null
@@ -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 (file)
index 0000000..6e13e53
--- /dev/null
@@ -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);
+}
index cf6410a887fbfdb88e45040f5500e26f4b173516..174e60fa3fd27afb4c5e2b5983617742f5cad8ca 100644 (file)
@@ -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;
 }
index c0bc55ce9a1b0f7c892e1b7e8030fe76ea34a78f..7ff93e6a8138839d825718280f4407b639e88ab6 100644 (file)
@@ -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
index e87b042bfba3a9c2f7b58eb2c7b8a773acc1739b..22cdfab9a8442b3a5cc6810c06b23cfaca3d1e23 100644 (file)
@@ -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 (file)
index 0000000..48701e1
--- /dev/null
@@ -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);
+}
index da3dc1d64118bf4cec690396e67c65ef52ba5729..ff57d6033dc1d8cea749433db69add146d610d9f 100644 (file)
@@ -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;
 }
index b80067da1c0a7509640189d33ec2c841c008e821..f2563d33f28f4cdca470293fc8adad583a95f24f 100644 (file)
@@ -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 (file)
index 0000000..f074427
--- /dev/null
@@ -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);
+}
index 88610dc49e260e4c2f686ae375e923035a21fdc5..93194b3912d91def27b6096639945f7f671d1349 100644 (file)
@@ -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 (file)
index 0000000..bfbe56b
--- /dev/null
@@ -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 (file)
index 0000000..b4d94e8
--- /dev/null
@@ -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);
+}
index a0a972fb5396d1e869461e93f4684a523f7f665e..f97af04870138596c1c672a07b144593d90e133f 100644 (file)
@@ -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 (file)
index 0000000..f8f387a
--- /dev/null
@@ -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);
+}
index 01fe20a75dd15aa434d1b2670aa04c4dd5c53be5..bce27575fd8a677ed397f56ea3e1c1d6fd106dd5 100644 (file)
@@ -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_FILEfp;
+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);
 }
index 5002e3d0733b55949c61819d1431a26d216c09be..ac323a31b5ba3a05cadd94ee9eb8d0abe01f3051 100644 (file)
@@ -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);
 }
index c447f954e9fb258bd4cff0c06f3fdf5b60913dfc..e4e029faeac2f71833e7ebc93dd752991685904b 100644 (file)
@@ -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);
 }
index 4ef4b52a21c8a76de44ba0438e7052920b0db33c..8b92ae270e6d56f34b2a377d732f062b508e33a9 100644 (file)
@@ -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
index 8db41b76187fc00a8c7df383e42f66d57ff5c58c..3f35af299ab7cbd0fa94becb8195b03a32d78626 100644 (file)
-/*
-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
index d66af097aa5056d8f57dd6ededed6742a09b7072..8f7908b8403d4351f355df903b5cb57d6c32bcdd 100644 (file)
@@ -213,7 +213,7 @@ streambuf::streambuf(int flags)
 #endif
 }
 
-streambuf::~streambuf() { _IO_default_finish(this); }
+streambuf::~streambuf() { _IO_default_finish(this,0); }
 
 streampos
 streambuf::seekoff(streamoff, _seek_dir, int /*=ios::in|ios::out*/)
index ea9a5478c260bfd9ffb7cb1fec2c05ea997acea0..a492f636d874ec5f4913aca942e2f5a54f86b14a 100644 (file)
@@ -138,7 +138,7 @@ class ios : public _ios_fields {
        bin = _IOS_BIN, // Deprecated - ANSI uses ios::binary.
        binary = _IOS_BIN };
     enum seek_dir { beg, cur, end};
-    // ANSI: typedef enum seek_dir seekdir; etc
+    typedef enum seek_dir seekdir;
     // NOTE: If adding flags here, before to update ios::bitalloc().
     enum { skipws=_IO_SKIPWS,
           left=_IO_LEFT, right=_IO_RIGHT, internal=_IO_INTERNAL,
index a24c9e0b65c994cf838efc7cacac06213d8ded85..a0e47021f6ec2b6aa29fd4371d74231be6e88ced 100644 (file)
@@ -1,34 +1,35 @@
-/* 
-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 <libio.h>
 #ifdef TODO
 Merge into  libio.h ?
 #endif
 
-typedef void *(*_IO_alloc_type) __P((_IO_size_t));
-typedef void (*_IO_free_type) __P((void*));
+typedef void *(*_IO_alloc_type) __P ((_IO_size_t));
+typedef void (*_IO_free_type) __P ((void*));
 
 struct _IO_str_fields
 {
index 3162cd966e0613f60c8b1c9da79c7f104c363191..a9f812e04511cf9d23962cea0b6b9c292afb57da 100644 (file)
@@ -1,26 +1,27 @@
-/* 
-Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU IO Library.
 
-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 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.
+   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.
+   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. */
+   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 "strfile.h"
 #include "libioP.h"
@@ -28,7 +29,7 @@ the executable file might be covered by the GNU General Public License. */
 
 #if 0
 /* The following definitions are for exposition only.
-   They map the terminlogy used in the ANSI/ISO C++ draft standard
+   They map the terminology used in the ANSI/ISO C++ draft standard
    to the implementation. */
 
 /* allocated:  set  when a dynamic array object has been allocated, and
@@ -59,16 +60,19 @@ the executable file might be covered by the GNU General Public License. */
 #endif
 
 void
-DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
-      _IO_FILE *fp AND char *ptr AND int size AND char *pstart)
+_IO_str_init_static (fp, ptr, size, pstart)
+     _IO_FILE *fp;
+     char *ptr;
+     int size;
+     char *pstart;
 {
   if (size == 0)
-    size = strlen(ptr);
+    size = strlen (ptr);
   else if (size < 0)
     {
       /* If size is negative 'the characters are assumed to
         continue indefinitely.'  This is kind of messy ... */
-      _G_int32_t s;
+      int s;
       size = 512;
       /* Try increasing powers of 2, as long as we don't wrap around. */
       for (; s = 2*size, s > 0 && ptr + s > ptr && s < 0x4000000L; )
@@ -80,7 +84,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
            size += s;
        }
     }
-  _IO_setb(fp, ptr, ptr+size, 0);
+  _IO_setb (fp, ptr, ptr + size, 0);
 
   fp->_IO_write_base = ptr;
   fp->_IO_read_base = ptr;
@@ -88,7 +92,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
   if (pstart)
     {
       fp->_IO_write_ptr = pstart;
-      fp->_IO_write_end = ptr+size;
+      fp->_IO_write_end = ptr + size;
       fp->_IO_read_end = pstart;
     }
   else
@@ -98,20 +102,23 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
       fp->_IO_read_end = ptr+size;
     }
   /* A null _allocate_buffer function flags the strfile as being static. */
-  (((_IO_strfile*)(fp))->_s._allocate_buffer) =  (_IO_alloc_type)0;
+  (((_IO_strfile *) fp)->_s._allocate_buffer) =  (_IO_alloc_type)0;
 }
 
 void
-DEFUN(_IO_str_init_readonly, (fp, ptr, size),
-      _IO_FILE *fp AND const char *ptr AND int size)
+_IO_str_init_readonly (fp, ptr, size)
+     _IO_FILE *fp;
+     const char *ptr;
+     int size;
 {
-  _IO_str_init_static (fp, (char*)ptr, size, NULL);
+  _IO_str_init_static (fp, (char *) ptr, size, NULL);
   fp->_IO_file_flags |= _IO_NO_WRITES;
 }
 
 int
-DEFUN(_IO_str_overflow, (fp, c),
-      register _IO_FILE* fp AND int c)
+_IO_str_overflow (fp, c)
+     _IO_FILE *fp;
+     int c;
 {
   int flush_only = c == EOF;
   _IO_size_t pos;
@@ -124,7 +131,7 @@ DEFUN(_IO_str_overflow, (fp, c),
       fp->_IO_read_ptr = fp->_IO_read_end;
     }
   pos =  fp->_IO_write_ptr - fp->_IO_write_base;
-  if (pos >= _IO_blen(fp) + flush_only)
+  if (pos >= (_IO_size_t) (_IO_blen (fp) + flush_only))
     {
       if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */
        return EOF;
@@ -132,9 +139,9 @@ DEFUN(_IO_str_overflow, (fp, c),
        {
          char *new_buf;
          char *old_buf = fp->_IO_buf_base;
-         _IO_size_t new_size = 2 * _IO_blen(fp) + 100;
+         _IO_size_t new_size = 2 * _IO_blen (fp) + 100;
          new_buf
-           = (char*)(*((_IO_strfile*)fp)->_s._allocate_buffer)(new_size);
+           = (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size);
          if (new_buf == NULL)
            {
              /*          __ferror(fp) = 1; */
@@ -142,16 +149,16 @@ DEFUN(_IO_str_overflow, (fp, c),
            }
          if (fp->_IO_buf_base)
            {
-             memcpy(new_buf, old_buf, _IO_blen(fp));
-             (*((_IO_strfile*)fp)->_s._free_buffer)(fp->_IO_buf_base);
+             memcpy (new_buf, old_buf, _IO_blen (fp));
+             (*((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base);
              /* Make sure _IO_setb won't try to delete _IO_buf_base. */
              fp->_IO_buf_base = NULL;
            }
 #if 0
          if (lenp == &LEN(fp)) /* use '\0'-filling */
-             memset(new_buf + pos, 0, blen() - pos);
+             memset (new_buf + pos, 0, blen() - pos);
 #endif
-         _IO_setb(fp, new_buf, new_buf + new_size, 1);
+         _IO_setb (fp, new_buf, new_buf + new_size, 1);
          fp->_IO_read_base = new_buf + (fp->_IO_read_base - old_buf);
          fp->_IO_read_ptr = new_buf + (fp->_IO_read_ptr - old_buf);
          fp->_IO_read_end = new_buf + (fp->_IO_read_end - old_buf);
@@ -170,8 +177,8 @@ DEFUN(_IO_str_overflow, (fp, c),
 }
 
 int
-DEFUN(_IO_str_underflow, (fp),
-      register _IO_FILE* fp)
+_IO_str_underflow (fp)
+     _IO_FILE *fp;
 {
   if (fp->_IO_write_ptr > fp->_IO_read_end)
     fp->_IO_read_end = fp->_IO_write_ptr;
@@ -190,19 +197,22 @@ DEFUN(_IO_str_underflow, (fp),
 /* The size of the valid part of the buffer.  */
 
 _IO_ssize_t
-DEFUN(_IO_str_count, (fp),
-      register _IO_FILE *fp)
+_IO_str_count (fp)
+     _IO_FILE *fp;
 {
-  return (fp->_IO_write_ptr > fp->_IO_read_end ? fp->_IO_write_ptr
-         : fp->_IO_read_end)
-    - fp->_IO_read_base;
-}     
+  return ((fp->_IO_write_ptr > fp->_IO_read_end
+          ? fp->_IO_write_ptr : fp->_IO_read_end)
+         - fp->_IO_read_base);
+}
 
 _IO_pos_t
-DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
-      register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode)
+_IO_str_seekoff (fp, offset, dir, mode)
+     _IO_FILE *fp;
+     _IO_off_t offset;
+     int dir;
+     int mode;
 {
-  _IO_ssize_t cur_size = _IO_str_count(fp);
+  _IO_ssize_t cur_size = _IO_str_count (fp);
   _IO_pos_t new_pos = EOF;
 
   /* Move the get pointer, if requested. */
@@ -219,7 +229,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
        default: /* case _IO_seek_set: */
          break;
        }
-      if (offset < 0 || (_IO_size_t)offset > cur_size)
+      if (offset < 0 || (_IO_ssize_t) offset > cur_size)
        return EOF;
       fp->_IO_read_ptr = fp->_IO_read_base + offset;
       fp->_IO_read_end = fp->_IO_read_base + cur_size;
@@ -240,7 +250,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
        default: /* case _IO_seek_set: */
          break;
        }
-      if (offset < 0 || (_IO_size_t)offset > cur_size)
+      if (offset < 0 || (_IO_ssize_t) offset > cur_size)
        return EOF;
       fp->_IO_write_ptr = fp->_IO_write_base + offset;
       new_pos = offset;
@@ -249,26 +259,29 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
 }
 
 int
-DEFUN(_IO_str_pbackfail, (fp, c),
-      register _IO_FILE *fp AND int c)
+_IO_str_pbackfail (fp, c)
+     _IO_FILE *fp;
+     int c;
 {
   if ((fp->_flags & _IO_NO_WRITES) && c != EOF)
     return EOF;
-  return _IO_default_pbackfail(fp, c);
+  return _IO_default_pbackfail (fp, c);
 }
 
 void
-DEFUN (_IO_str_finish, (fp),
-      register _IO_FILE* fp)
+_IO_str_finish (fp, dummy)
+     _IO_FILE *fp;
+     int dummy;
 {
   if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
-    (((_IO_strfile*)fp)->_s._free_buffer)(fp->_IO_buf_base);
+    (((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base);
   fp->_IO_buf_base = NULL;
 
-  _IO_default_finish(fp);
+  _IO_default_finish (fp, 0);
 }
 
-struct _IO_jump_t _IO_str_jumps = {
+struct _IO_jump_t _IO_str_jumps =
+{
   JUMP_INIT_DUMMY,
   JUMP_INIT(finish, _IO_str_finish),
   JUMP_INIT(overflow, _IO_str_overflow),