Commit dbfcb4be by Brendan Kehoe

Insert libio rewrite and its various changes from devo.

From-SVN: r15129
parent 1496c1bb
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) 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. * testsuite/Makefile.in (check): Don't depend on site.exp.
(just-check): Depend on site.exp. (just-check): Depend on site.exp.
Wed Aug 20 02:01:34 1997 Jason Merrill <jason@yorick.cygnus.com> Wed Aug 20 02:01:34 1997 Jason Merrill <jason@yorick.cygnus.com>
......
...@@ -29,7 +29,8 @@ IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \ ...@@ -29,7 +29,8 @@ IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \
iofgetpos.o iofread.o iofscanf.o \ iofgetpos.o iofread.o iofscanf.o \
iofsetpos.o iogetdelim.o iogetline.o \ iofsetpos.o iogetdelim.o iogetline.o \
ioprintf.o ioseekoff.o ioseekpos.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 # These emulate stdio functionality, but with a different name (_IO_ungetc
# instead of ungetc), and using _IO_FILE instead of FILE. # instead of ungetc), and using _IO_FILE instead of FILE.
...@@ -40,7 +41,7 @@ IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \ ...@@ -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). # 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 \ 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 \ 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 \ IOSTREAM_OBJECTS = builtinbuf.o filebuf.o fstream.o \
indstream.o ioassign.o ioextend.o iomanip.o iostream.o \ indstream.o ioassign.o ioextend.o iomanip.o iostream.o \
...@@ -82,16 +83,12 @@ tpipe: tpipe.o libio.a ...@@ -82,16 +83,12 @@ tpipe: tpipe.o libio.a
iostream.list: stamp-picdir $(_G_CONFIG_H) $(LIBIOSTREAM_DEP) iostream.list: stamp-picdir $(_G_CONFIG_H) $(LIBIOSTREAM_DEP)
@echo "$(LIBIOSTREAM_USE)"> iostream.list @echo "$(LIBIOSTREAM_USE)"> iostream.list
@echo "$(STDIO_WRAP_OBJECTS)" >> iostream.list
stdio/stdio.list: force stmp-stdio:
@rootme=`pwd`/ ; export rootme; cd stdio ; \ @rootme=`pwd`/ ; export rootme; cd stdio ; \
$(MAKE) $(FLAGS_TO_PASS) stdio.list $(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 _G_config.h: ${srcdir}/gen-params
rootme=`pwd`/ ; export rootme; \ rootme=`pwd`/ ; export rootme; \
CC="$(CC)"; export CC; \ CC="$(CC)"; export CC; \
......
...@@ -57,7 +57,7 @@ ${moveifchange} temp.mt target-mkfrag ...@@ -57,7 +57,7 @@ ${moveifchange} temp.mt target-mkfrag
LIBDIR=yes LIBDIR=yes
TO_TOPDIR=../ TO_TOPDIR=../
ALL='$(_G_CONFIG_H) libio.a iostream.list' ALL='$(_G_CONFIG_H) libio.a libiostream.a iostream.list'
XCINCLUDES='-I. -I$(srcdir)' XCINCLUDES='-I. -I$(srcdir)'
XCXXINCLUDES='-I. -I$(srcdir)' XCXXINCLUDES='-I. -I$(srcdir)'
MOSTLYCLEAN='*.o pic stamp-picdir core iostream.list' MOSTLYCLEAN='*.o pic stamp-picdir core iostream.list'
......
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ 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. * 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. */ ...@@ -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. */ /* Modified for GNU iostream by Per Bothner 1991, 1992. */
#define _POSIX_SOURCE #ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h" #include "libioP.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -50,6 +53,11 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -50,6 +53,11 @@ the executable file might be covered by the GNU General Public License. */
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef _LIBC
# undef isatty
# define isatty(Fd) __isatty (Fd)
#endif
/* /*
* Allocate a file buffer, or switch to unbuffered I/O. * Allocate a file buffer, or switch to unbuffered I/O.
* Per the ANSI C standard, ALL tty devices default to line buffered. * 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. */ ...@@ -59,21 +67,23 @@ the executable file might be covered by the GNU General Public License. */
*/ */
int int
DEFUN(_IO_file_doallocate, (fp), _IO_file_doallocate (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
register _IO_size_t size; _IO_size_t size;
int couldbetty; int couldbetty;
register char *p; char *p;
struct stat st; struct stat st;
#ifndef _LIBC
/* If _IO_cleanup_registration_needed is non-zero, we should call the /* 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 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 on exit. We call it from _IO_file_doallocate, since that is likely
to get called by any program that does buffered I/O. */ to get called by any program that does buffered I/O. */
if (_IO_cleanup_registration_needed) if (_IO_cleanup_registration_needed)
(*_IO_cleanup_registration_needed)(); (*_IO_cleanup_registration_needed) ();
#endif
if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0) if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0)
{ {
couldbetty = 0; couldbetty = 0;
...@@ -85,18 +95,16 @@ DEFUN(_IO_file_doallocate, (fp), ...@@ -85,18 +95,16 @@ DEFUN(_IO_file_doallocate, (fp),
} }
else else
{ {
couldbetty = S_ISCHR(st.st_mode); couldbetty = S_ISCHR (st.st_mode);
#if _IO_HAVE_ST_BLKSIZE #if _IO_HAVE_ST_BLKSIZE
size = st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize; size = st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize;
#else #else
size = _IO_BUFSIZ; size = _IO_BUFSIZ;
#endif #endif
} }
p = ALLOC_BUF(size); ALLOC_BUF (p, size, EOF);
if (p == NULL) _IO_setb (fp, p, p + size, 1);
return EOF; if (couldbetty && isatty (fp->_fileno))
_IO_setb(fp, p, p+size, 1);
if (couldbetty && isatty(fp->_fileno))
fp->_flags |= _IO_LINE_BUF; fp->_flags |= _IO_LINE_BUF;
return 1; return 1;
} }
/* /* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
Copyright (C) 1993, 1995 Free Software Foundation This file is part of the GNU IO Library.
Written by Per Bothner <bothner@cygnus.com>.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the This library is free software; you can redistribute it and/or
terms of the GNU General Public License as published by the modify it under the terms of the GNU General Public License as
Free Software Foundation; either version 2, or (at your option) published by the Free Software Foundation; either version 2, or (at
any later version. your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
the resulting executable to be covered by the GNU General Public License. compiled with a GNU compiler to produce an executable, this does
This exception does not however invalidate any other reasons why not cause the resulting executable to be covered by the GNU General
the executable file might be covered by the GNU General Public License. */ Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
/* written by Per Bothner (bothner@cygnus.com) */ General Public License. */
#define _POSIX_SOURCE
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h" #include "libioP.h"
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -35,11 +38,16 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -35,11 +38,16 @@ the executable file might be covered by the GNU General Public License. */
extern int errno; extern int errno;
#endif #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. /* An fstream can be in at most one of put mode, get mode, or putback mode.
Putback mode is a variant of get mode. Putback mode is a variant of get mode.
In a filebuf, there is only one current position, instead of two 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(). is that of gptr(); in put mode that of pptr().
The position in the buffer that corresponds to the position The position in the buffer that corresponds to the position
...@@ -73,14 +81,14 @@ extern int errno; ...@@ -73,14 +81,14 @@ extern int errno;
(The pointers save_gptr() and save_egptr() are the values (The pointers save_gptr() and save_egptr() are the values
of gptr() and egptr() at the time putback mode was entered.) of gptr() and egptr() at the time putback mode was entered.)
The OS position corresponds to that of save_egptr(). The OS position corresponds to that of save_egptr().
LINE BUFFERED OUTPUT: LINE BUFFERED OUTPUT:
During line buffered output, _IO_write_base==base() && epptr()==base(). During line buffered output, _IO_write_base==base() && epptr()==base().
However, ptr() may be anywhere between base() and ebuf(). However, ptr() may be anywhere between base() and ebuf().
This forces a call to filebuf::overflow(int C) on every put. 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', If there is more space in the buffer, and C is not a '\n',
then C is inserted, and pptr() incremented. then C is inserted, and pptr() incremented.
UNBUFFERED STREAMS: UNBUFFERED STREAMS:
If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer. If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer.
*/ */
...@@ -90,8 +98,8 @@ extern int errno; ...@@ -90,8 +98,8 @@ extern int errno;
void void
DEFUN(_IO_file_init, (fp), _IO_file_init (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
/* POSIX.1 allows another file handle to be used to change the position /* 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 of our file descriptor. Hence we actually don't know the actual
...@@ -104,11 +112,11 @@ DEFUN(_IO_file_init, (fp), ...@@ -104,11 +112,11 @@ DEFUN(_IO_file_init, (fp),
} }
int int
DEFUN(_IO_file_close_it, (fp), _IO_file_close_it (fp)
register _IO_FILE* fp) _IO_FILE *fp;
{ {
int write_status, close_status; int write_status, close_status;
if (!_IO_file_is_open(fp)) if (!_IO_file_is_open (fp))
return EOF; return EOF;
write_status = _IO_do_flush (fp); write_status = _IO_do_flush (fp);
...@@ -118,11 +126,11 @@ DEFUN(_IO_file_close_it, (fp), ...@@ -118,11 +126,11 @@ DEFUN(_IO_file_close_it, (fp),
close_status = _IO_SYSCLOSE (fp); close_status = _IO_SYSCLOSE (fp);
/* Free buffer. */ /* Free buffer. */
_IO_setb(fp, NULL, NULL, 0); _IO_setb (fp, NULL, NULL, 0);
_IO_setg(fp, NULL, NULL, NULL); _IO_setg (fp, NULL, NULL, NULL);
_IO_setp(fp, NULL, NULL); _IO_setp (fp, NULL, NULL);
_IO_un_link(fp); _IO_un_link (fp);
fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS; fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
fp->_fileno = EOF; fp->_fileno = EOF;
fp->_offset = _IO_pos_BAD; fp->_offset = _IO_pos_BAD;
...@@ -131,86 +139,99 @@ DEFUN(_IO_file_close_it, (fp), ...@@ -131,86 +139,99 @@ DEFUN(_IO_file_close_it, (fp),
} }
void void
DEFUN(_IO_file_finish, (fp), _IO_file_finish (fp, dummy)
register _IO_FILE* fp) _IO_FILE *fp;
int dummy;
{ {
if (_IO_file_is_open(fp)) if (_IO_file_is_open (fp))
{ {
_IO_do_flush (fp); _IO_do_flush (fp);
if (!(fp->_flags & _IO_DELETE_DONT_CLOSE)) if (!(fp->_flags & _IO_DELETE_DONT_CLOSE))
_IO_SYSCLOSE (fp); _IO_SYSCLOSE (fp);
} }
_IO_default_finish(fp); _IO_default_finish (fp, 0);
} }
_IO_FILE * _IO_FILE *
DEFUN(_IO_file_fopen, (fp, filename, mode), _IO_file_fopen (fp, filename, mode)
register _IO_FILE *fp AND const char *filename AND const char *mode) _IO_FILE *fp;
const char *filename;
const char *mode;
{ {
int oflags = 0, omode; int oflags = 0, omode;
int read_write, fdesc; int read_write, fdesc;
int oprot = 0666; int oprot = 0666;
if (_IO_file_is_open (fp)) if (_IO_file_is_open (fp))
return 0; return 0;
switch (*mode++) { switch (*mode++)
case 'r': {
omode = O_RDONLY; case 'r':
read_write = _IO_NO_WRITES; omode = O_RDONLY;
break; read_write = _IO_NO_WRITES;
case 'w': break;
omode = O_WRONLY; case 'w':
oflags = O_CREAT|O_TRUNC; omode = O_WRONLY;
read_write = _IO_NO_READS; oflags = O_CREAT|O_TRUNC;
break; read_write = _IO_NO_READS;
case 'a': break;
omode = O_WRONLY; case 'a':
oflags = O_CREAT|O_APPEND; omode = O_WRONLY;
read_write = _IO_NO_READS|_IO_IS_APPENDING; oflags = O_CREAT|O_APPEND;
break; read_write = _IO_NO_READS|_IO_IS_APPENDING;
default: break;
errno = EINVAL; default:
return NULL; __set_errno (EINVAL);
} return NULL;
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) { }
omode = O_RDWR; if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
read_write &= _IO_IS_APPENDING; {
} omode = O_RDWR;
fdesc = open(filename, omode|oflags, oprot); read_write &= _IO_IS_APPENDING;
}
fdesc = open (filename, omode|oflags, oprot);
if (fdesc < 0) if (fdesc < 0)
return NULL; return NULL;
fp->_fileno = fdesc; 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 (read_write & _IO_IS_APPENDING)
if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT) 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; return NULL;
_IO_link_in(fp); _IO_link_in (fp);
return fp; return fp;
} }
_IO_FILE* _IO_FILE *
DEFUN(_IO_file_attach, (fp, fd), _IO_file_attach (fp, fd)
_IO_FILE *fp AND int fd) _IO_FILE *fp;
int fd;
{ {
if (_IO_file_is_open(fp)) if (_IO_file_is_open (fp))
return NULL; return NULL;
fp->_fileno = fd; fp->_fileno = fd;
fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES); fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES);
fp->_flags |= _IO_DELETE_DONT_CLOSE; 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; 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; return fp;
} }
_IO_FILE* _IO_FILE *
DEFUN(_IO_file_setbuf, (fp, p, len), _IO_file_setbuf (fp, p, len)
register _IO_FILE *fp AND char* p AND _IO_ssize_t len) _IO_FILE *fp;
char *p;
_IO_ssize_t len;
{ {
if (_IO_default_setbuf(fp, p, len) == NULL) if (_IO_default_setbuf (fp, p, len) == NULL)
return NULL; return NULL;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
= fp->_IO_buf_base; = 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; return fp;
} }
...@@ -219,44 +240,42 @@ DEFUN(_IO_file_setbuf, (fp, p, len), ...@@ -219,44 +240,42 @@ DEFUN(_IO_file_setbuf, (fp, p, len),
Then mark FP as having empty buffers. */ Then mark FP as having empty buffers. */
int int
DEFUN(_IO_do_write, (fp, data, to_do), _IO_do_write (fp, data, to_do)
register _IO_FILE *fp AND const char* data AND _IO_size_t to_do) _IO_FILE *fp;
const char *data;
_IO_size_t to_do;
{ {
_IO_size_t count; _IO_size_t count;
if (to_do == 0) if (to_do == 0)
return 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) _IO_pos_t new_pos
/* On a system without a proper O_APPEND implementation, = _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1);
you would need to sys_seek(0, SEEK_END) here, but is if (new_pos == _IO_pos_BAD)
is not needed nor desirable for Unix- or Posix-like systems. return EOF;
Instead, just indicate that offset (before and after) is fp->_offset = new_pos;
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_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_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_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
: fp->_IO_buf_end; ? fp->_IO_buf_base : fp->_IO_buf_end);
return count != to_do ? EOF : 0; return count != to_do ? EOF : 0;
} }
int int
DEFUN(_IO_file_underflow, (fp), _IO_file_underflow (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
_IO_ssize_t count; _IO_ssize_t count;
#if 0 #if 0
...@@ -266,19 +285,31 @@ DEFUN(_IO_file_underflow, (fp), ...@@ -266,19 +285,31 @@ DEFUN(_IO_file_underflow, (fp),
#endif #endif
if (fp->_flags & _IO_NO_READS) if (fp->_flags & _IO_NO_READS)
return EOF; {
__set_errno (EBADF);
return EOF;
}
if (fp->_IO_read_ptr < fp->_IO_read_end) 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) if (fp->_IO_buf_base == NULL)
_IO_doallocbuf(fp); _IO_doallocbuf (fp);
/* Flush all line buffered files before reading. */ /* Flush all line buffered files before reading. */
/* FIXME This can/should be moved to genops ?? */ /* FIXME This can/should be moved to genops ?? */
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED)) 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, count = _IO_SYSREAD (fp, fp->_IO_buf_base,
fp->_IO_buf_end - fp->_IO_buf_base); fp->_IO_buf_end - fp->_IO_buf_base);
...@@ -289,30 +320,32 @@ DEFUN(_IO_file_underflow, (fp), ...@@ -289,30 +320,32 @@ DEFUN(_IO_file_underflow, (fp),
else else
fp->_flags |= _IO_ERR_SEEN, count = 0; fp->_flags |= _IO_ERR_SEEN, count = 0;
} }
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base; fp->_IO_read_end += count;
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;
if (count == 0) if (count == 0)
return EOF; return EOF;
if (fp->_offset != _IO_pos_BAD) if (fp->_offset != _IO_pos_BAD)
_IO_pos_adjust(fp->_offset, count); _IO_pos_adjust (fp->_offset, count);
return *(unsigned char*)fp->_IO_read_ptr; return *(unsigned char *) fp->_IO_read_ptr;
} }
int int
DEFUN(_IO_file_overflow, (f, ch), _IO_file_overflow (f, ch)
register _IO_FILE* f AND int ch) _IO_FILE *f;
int ch;
{ {
if (f->_flags & _IO_NO_WRITES) /* SET ERROR */ 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 currently reading or no buffer allocated. */
if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0) if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
{ {
/* Allocate a buffer if needed. */ /* Allocate a buffer if needed. */
if (f->_IO_write_base == 0) 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); _IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base);
} }
/* Otherwise must be currently reading. /* Otherwise must be currently reading.
...@@ -334,35 +367,35 @@ DEFUN(_IO_file_overflow, (f, ch), ...@@ -334,35 +367,35 @@ DEFUN(_IO_file_overflow, (f, ch),
f->_flags |= _IO_CURRENTLY_PUTTING; f->_flags |= _IO_CURRENTLY_PUTTING;
} }
if (ch == EOF) 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 (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; return EOF;
*f->_IO_write_ptr++ = ch; *f->_IO_write_ptr++ = ch;
if ((f->_flags & _IO_UNBUFFERED) if ((f->_flags & _IO_UNBUFFERED)
|| ((f->_flags & _IO_LINE_BUF) && ch == '\n')) || ((f->_flags & _IO_LINE_BUF) && ch == '\n'))
if (_IO_do_flush(f) == EOF) if (_IO_do_flush (f) == EOF)
return EOF; return EOF;
return (unsigned char)ch; return (unsigned char) ch;
} }
int int
DEFUN(_IO_file_sync, (fp), _IO_file_sync (fp)
register _IO_FILE* fp) _IO_FILE *fp;
{ {
_IO_size_t delta; _IO_size_t delta;
/* char* ptr = cur_ptr(); */ /* char* ptr = cur_ptr(); */
if (fp->_IO_write_ptr > fp->_IO_write_base) if (fp->_IO_write_ptr > fp->_IO_write_base)
if (_IO_do_flush(fp)) return EOF; 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) if (delta != 0)
{ {
#ifdef TODO #ifdef TODO
if (_IO_in_backup(fp)) if (_IO_in_backup (fp))
delta -= eGptr() - Gbase(); delta -= eGptr () - Gbase ();
#endif #endif
_IO_off_t new_pos = _IO_SYSSEEK (fp, delta, 1); _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; fp->_IO_read_end = fp->_IO_read_ptr;
#ifdef ESPIPE #ifdef ESPIPE
else if (errno == ESPIPE) else if (errno == ESPIPE)
...@@ -378,12 +411,19 @@ DEFUN(_IO_file_sync, (fp), ...@@ -378,12 +411,19 @@ DEFUN(_IO_file_sync, (fp),
} }
_IO_pos_t _IO_pos_t
DEFUN(_IO_file_seekoff, (fp, offset, dir, mode), _IO_file_seekoff (fp, offset, dir, mode)
register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode) _IO_FILE *fp;
_IO_off_t offset;
int dir;
int mode;
{ {
_IO_pos_t result; _IO_pos_t result;
_IO_off_t delta, new_offset; _IO_off_t delta, new_offset;
long count; 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) if (mode == 0)
dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */ dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
...@@ -396,14 +436,15 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode), ...@@ -396,14 +436,15 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
end up flushing when we close(), it doesn't make much difference.) end up flushing when we close(), it doesn't make much difference.)
FIXME: simulate mem-papped files. */ FIXME: simulate mem-papped files. */
if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode(fp)) if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode (fp))
if (_IO_switch_to_get_mode(fp)) return EOF; if (_IO_switch_to_get_mode (fp))
return EOF;
if (fp->_IO_buf_base == NULL) if (fp->_IO_buf_base == NULL)
{ {
_IO_doallocbuf(fp); _IO_doallocbuf (fp);
_IO_setp(fp, 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_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
} }
switch (dir) switch (dir)
...@@ -414,7 +455,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode), ...@@ -414,7 +455,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
if (fp->_offset == _IO_pos_BAD) if (fp->_offset == _IO_pos_BAD)
goto dumb; goto dumb;
/* Make offset absolute, assuming current pointer is file_ptr(). */ /* 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; dir = _IO_seek_set;
break; break;
...@@ -423,7 +464,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode), ...@@ -423,7 +464,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
case _IO_seek_end: case _IO_seek_end:
{ {
struct stat st; 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; offset += st.st_size;
dir = _IO_seek_set; dir = _IO_seek_set;
...@@ -439,46 +480,46 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode), ...@@ -439,46 +480,46 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
&& !_IO_in_backup (fp)) && !_IO_in_backup (fp))
{ {
/* Offset relative to start of main get area. */ /* Offset relative to start of main get area. */
_IO_pos_t rel_offset = offset - fp->_offset _IO_pos_t rel_offset = (offset - fp->_offset
+ (fp->_IO_read_end - fp->_IO_read_base); + (fp->_IO_read_end - fp->_IO_read_base));
if (rel_offset >= 0) if (rel_offset >= 0)
{ {
#if 0 #if 0
if (_IO_in_backup(fp)) if (_IO_in_backup (fp))
_IO_switch_to_main_get_area(fp); _IO_switch_to_main_get_area (fp);
#endif #endif
if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base) if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
{ {
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset, _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
fp->_IO_read_end); fp->_IO_read_end);
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base); _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
return offset; return offset;
} }
#ifdef TODO #ifdef TODO
/* If we have streammarkers, seek forward by reading ahead. */ /* If we have streammarkers, seek forward by reading ahead. */
if (_IO_have_markers(fp)) if (_IO_have_markers (fp))
{ {
int to_skip = rel_offset int to_skip = rel_offset
- (fp->_IO_read_ptr - fp->_IO_read_base); - (fp->_IO_read_ptr - fp->_IO_read_base);
if (ignore(to_skip) != to_skip) if (ignore (to_skip) != to_skip)
goto dumb; goto dumb;
return offset; return offset;
} }
#endif #endif
} }
#ifdef TODO #ifdef TODO
if (rel_offset < 0 && rel_offset >= Bbase() - Bptr()) if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())
{ {
if (!_IO_in_backup(fp)) if (!_IO_in_backup (fp))
_IO_switch_to_backup_area(fp); _IO_switch_to_backup_area (fp);
gbump(fp->_IO_read_end + rel_offset - fp->_IO_read_ptr); gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
return offset; return offset;
} }
#endif #endif
} }
#ifdef TODO #ifdef TODO
_IO_unsave_markers(fp); _IO_unsave_markers (fp);
#endif #endif
if (fp->_flags & _IO_NO_READS) if (fp->_flags & _IO_NO_READS)
...@@ -500,7 +541,8 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode), ...@@ -500,7 +541,8 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
else else
{ {
count = _IO_SYSREAD (fp, fp->_IO_buf_base, 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) if (count < delta)
{ {
/* We weren't allowed to read, but try to seek the remainder. */ /* We weren't allowed to read, but try to seek the remainder. */
...@@ -509,31 +551,38 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode), ...@@ -509,31 +551,38 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
goto dumb; goto dumb;
} }
} }
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base+delta, fp->_IO_buf_base+count); _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base); fp->_IO_buf_base + count);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_offset = result + count; fp->_offset = result + count;
_IO_mask_flags(fp, 0, _IO_EOF_SEEN); _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
return offset; return offset;
dumb: dumb:
_IO_unsave_markers(fp); _IO_unsave_markers (fp);
result = _IO_SYSSEEK (fp, offset, dir); result = _IO_SYSSEEK (fp, offset, dir);
if (result != EOF) if (result != EOF)
_IO_mask_flags(fp, 0, _IO_EOF_SEEN); _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
fp->_offset = result; fp->_offset = result;
_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);
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base); _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
return result; return result;
} }
_IO_ssize_t _IO_ssize_t
DEFUN(_IO_file_read, (fp, buf, size), _IO_file_read (fp, buf, size)
register _IO_FILE* fp AND void* buf AND _IO_ssize_t size) _IO_FILE *fp;
void *buf;
_IO_ssize_t size;
{ {
for (;;) for (;;)
{ {
_IO_ssize_t count = _IO_read(fp->_fileno, buf, size); _IO_ssize_t count = _IO_read (fp->_fileno, buf, size);
#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 (count == -1 && errno == EINTR) if (count == -1 && errno == EINTR)
continue; continue;
#endif #endif
...@@ -542,37 +591,46 @@ DEFUN(_IO_file_read, (fp, buf, size), ...@@ -542,37 +591,46 @@ DEFUN(_IO_file_read, (fp, buf, size),
} }
_IO_pos_t _IO_pos_t
DEFUN(_IO_file_seek, (fp, offset, dir), _IO_file_seek (fp, offset, dir)
_IO_FILE *fp AND _IO_off_t offset AND int 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 int
DEFUN(_IO_file_stat, (fp, st), _IO_file_stat (fp, st)
_IO_FILE *fp AND void* st) _IO_FILE *fp;
void *st;
{ {
return _IO_fstat(fp->_fileno, (struct stat*)st); return _IO_fstat (fp->_fileno, (struct stat *) st);
} }
int int
DEFUN(_IO_file_close, (fp), _IO_file_close (fp)
_IO_FILE* fp) _IO_FILE *fp;
{ {
return _IO_close(fp->_fileno); return _IO_close (fp->_fileno);
} }
_IO_ssize_t _IO_ssize_t
DEFUN(_IO_file_write, (f, data, n), _IO_file_write (f, data, n)
register _IO_FILE* f AND const void* data AND _IO_ssize_t n) _IO_FILE *f;
const void *data;
_IO_ssize_t n;
{ {
_IO_ssize_t to_do = n; _IO_ssize_t to_do = n;
while (to_do > 0) 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) 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) if (errno == EINTR)
continue; continue;
else else
...@@ -583,7 +641,7 @@ DEFUN(_IO_file_write, (f, data, n), ...@@ -583,7 +641,7 @@ DEFUN(_IO_file_write, (f, data, n),
} }
} }
to_do -= count; to_do -= count;
data = (void*)((char*)data + count); data = (void *) ((char *) data + count);
} }
n -= to_do; n -= to_do;
if (f->_offset >= 0) if (f->_offset >= 0)
...@@ -592,10 +650,12 @@ DEFUN(_IO_file_write, (f, data, n), ...@@ -592,10 +650,12 @@ DEFUN(_IO_file_write, (f, data, n),
} }
_IO_size_t _IO_size_t
DEFUN(_IO_file_xsputn, (f, data, n), _IO_file_xsputn (f, data, n)
_IO_FILE *f AND const void *data AND _IO_size_t 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; _IO_size_t to_do = n;
int must_flush = 0; int must_flush = 0;
_IO_size_t count; _IO_size_t count;
...@@ -612,14 +672,16 @@ DEFUN(_IO_file_xsputn, (f, data, n), ...@@ -612,14 +672,16 @@ DEFUN(_IO_file_xsputn, (f, data, n),
{ {
count = f->_IO_buf_end - f->_IO_write_ptr; count = f->_IO_buf_end - f->_IO_write_ptr;
if (count >= n) if (count >= n)
{ register const char *p; {
register const char *p;
for (p = s + n; p > s; ) for (p = s + n; p > s; )
{ {
if (*--p == '\n') { if (*--p == '\n')
count = p - s + 1; {
must_flush = 1; count = p - s + 1;
break; must_flush = 1;
} break;
}
} }
} }
} }
...@@ -628,23 +690,26 @@ DEFUN(_IO_file_xsputn, (f, data, n), ...@@ -628,23 +690,26 @@ DEFUN(_IO_file_xsputn, (f, data, n),
{ {
if (count > to_do) if (count > to_do)
count = to_do; count = to_do;
if (count > 20) { if (count > 20)
memcpy(f->_IO_write_ptr, s, count); {
s += count; memcpy (f->_IO_write_ptr, s, count);
} s += count;
}
else else
{ {
register char *p = f->_IO_write_ptr; register char *p = f->_IO_write_ptr;
register int i = (int)count; register int i = (int) count;
while (--i >= 0) *p++ = *s++; while (--i >= 0)
*p++ = *s++;
} }
f->_IO_write_ptr += count; f->_IO_write_ptr += count;
to_do -= count; to_do -= count;
} }
if (to_do + must_flush > 0) 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. */ /* Next flush the (full) buffer. */
if (__overflow(f, EOF) == EOF) if (__overflow (f, EOF) == EOF)
return n - to_do; return n - to_do;
/* Try to maintain alignment: write a whole number of blocks. /* Try to maintain alignment: write a whole number of blocks.
...@@ -653,15 +718,15 @@ DEFUN(_IO_file_xsputn, (f, data, n), ...@@ -653,15 +718,15 @@ DEFUN(_IO_file_xsputn, (f, data, n),
dont_write = block_size >= 128 ? to_do % block_size : 0; dont_write = block_size >= 128 ? to_do % block_size : 0;
count = to_do - dont_write; 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; return n - to_do;
to_do = dont_write; to_do = dont_write;
/* Now write out the remainder. Normally, this will fit in the /* Now write out the remainder. Normally, this will fit in the
buffer, but it's somewhat messier for line-buffered files, buffer, but it's somewhat messier for line-buffered files,
so we let _IO_default_xsputn handle the general case. */ so we let _IO_default_xsputn handle the general case. */
if (dont_write) 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; return n - to_do;
} }
...@@ -669,21 +734,24 @@ DEFUN(_IO_file_xsputn, (f, data, n), ...@@ -669,21 +734,24 @@ DEFUN(_IO_file_xsputn, (f, data, n),
#if 0 #if 0
/* Work in progress */ /* Work in progress */
_IO_size_t _IO_size_t
DEFUN(_IO_file_xsgetn, (fp, data, n), _IO_file_xsgetn (fp, data, n)
_IO_FILE *fp AND void *data AND _IO_size_t n) _IO_FILE *fp;
void *data;
_IO_size_t n;
{ {
register _IO_size_t more = n; register _IO_size_t more = n;
register char *s = data; register char *s = data;
for (;;) 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 > 0)
{ {
if (count > more) if (count > more)
count = more; count = more;
if (count > 20) if (count > 20)
{ {
memcpy(s, fp->_IO_read_ptr, count); memcpy (s, fp->_IO_read_ptr, count);
s += count; s += count;
fp->_IO_read_ptr += count; fp->_IO_read_ptr += count;
} }
...@@ -692,8 +760,9 @@ DEFUN(_IO_file_xsgetn, (fp, data, n), ...@@ -692,8 +760,9 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
else else
{ {
register char *p = fp->_IO_read_ptr; register char *p = fp->_IO_read_ptr;
register int i = (int)count; register int i = (int) count;
while (--i >= 0) *s++ = *p++; while (--i >= 0)
*s++ = *p++;
fp->_IO_read_ptr = p; fp->_IO_read_ptr = p;
} }
more -= count; more -= count;
...@@ -708,11 +777,11 @@ DEFUN(_IO_file_xsgetn, (fp, data, n), ...@@ -708,11 +777,11 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
/* If we're reading a lot of data, don't bother allocating /* 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 ??*/ a buffer. But if we're only reading a bit, perhaps we should ??*/
if (count <= 512 && fp->_IO_buf_base == NULL) if (count <= 512 && fp->_IO_buf_base == NULL)
_IO_doallocbuf(fp); _IO_doallocbuf (fp);
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED)) 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); count = _IO_SYSREAD (fp, s, more);
if (count <= 0) if (count <= 0)
{ {
...@@ -721,19 +790,20 @@ DEFUN(_IO_file_xsgetn, (fp, data, n), ...@@ -721,19 +790,20 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
else else
fp->_flags |= _IO_ERR_SEEN, count = 0; fp->_flags |= _IO_ERR_SEEN, count = 0;
} }
s += count; s += count;
more -= count; more -= count;
} }
#endif #endif
if (more == 0 || __underflow(fp) == EOF) if (more == 0 || __underflow (fp) == EOF)
break; break;
} }
return n - more; return n - more;
} }
#endif #endif
struct _IO_jump_t _IO_file_jumps = { struct _IO_jump_t _IO_file_jumps =
{
JUMP_INIT_DUMMY, JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_file_finish), JUMP_INIT(finish, _IO_file_finish),
JUMP_INIT(overflow, _IO_file_overflow), JUMP_INIT(overflow, _IO_file_overflow),
......
/* /* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
Copyright (C) 1993, 1995 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
/* Generic or default I/O operations. */ /* Generic or default I/O operations. */
...@@ -31,41 +32,46 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -31,41 +32,46 @@ the executable file might be covered by the GNU General Public License. */
#include <string.h> #include <string.h>
void void
DEFUN(_IO_un_link, (fp), _IO_un_link (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
if (fp->_flags & _IO_LINKED) { if (fp->_flags & _IO_LINKED)
_IO_FILE **f; {
for (f = &_IO_list_all; *f != NULL; f = &(*f)->_chain) { _IO_FILE **f;
if (*f == fp) { for (f = &_IO_list_all; *f != NULL; f = &(*f)->_chain)
*f = fp->_chain; {
break; if (*f == fp)
} {
*f = fp->_chain;
break;
}
}
fp->_flags &= ~_IO_LINKED;
} }
fp->_flags &= ~_IO_LINKED;
}
} }
void void
DEFUN(_IO_link_in, (fp), _IO_link_in (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
if ((fp->_flags & _IO_LINKED) == 0) { if ((fp->_flags & _IO_LINKED) == 0)
{
fp->_flags |= _IO_LINKED; fp->_flags |= _IO_LINKED;
fp->_chain = _IO_list_all; fp->_chain = _IO_list_all;
_IO_list_all = fp; _IO_list_all = fp;
} }
} }
/* Return minimum _pos markers /* Return minimum _pos markers
Assumes the current get area is the main get area. */ Assumes the current get area is the main get area. */
static _IO_size_t _IO_least_marker __P ((_IO_FILE *fp));
_IO_size_t static _IO_size_t
DEFUN(_IO_least_marker, (fp), _IO_least_marker (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
_IO_ssize_t least_so_far = fp->_IO_read_end - fp->_IO_read_base; _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) for (mark = fp->_markers; mark != NULL; mark = mark->_next)
if (mark->_pos < least_so_far) if (mark->_pos < least_so_far)
least_so_far = mark->_pos; least_so_far = mark->_pos;
...@@ -75,41 +81,51 @@ DEFUN(_IO_least_marker, (fp), ...@@ -75,41 +81,51 @@ DEFUN(_IO_least_marker, (fp),
/* Switch current get area from backup buffer to (start of) main get area. */ /* Switch current get area from backup buffer to (start of) main get area. */
void void
DEFUN(_IO_switch_to_main_get_area, (fp), _IO_switch_to_main_get_area (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
char *tmp; char *tmp;
fp->_flags &= ~_IO_IN_BACKUP; fp->_flags &= ~_IO_IN_BACKUP;
/* Swap _IO_read_end and _IO_save_end. */ /* 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. */ /* 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; fp->_IO_read_ptr = fp->_IO_read_base;
} }
/* Switch current get area from main get area to (end of) backup area. */ /* Switch current get area from main get area to (end of) backup area. */
void void
DEFUN(_IO_switch_to_backup_area, (fp), _IO_switch_to_backup_area (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
char *tmp; char *tmp;
fp->_flags |= _IO_IN_BACKUP; fp->_flags |= _IO_IN_BACKUP;
/* Swap _IO_read_end and _IO_save_end. */ /* 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. */ /* 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; fp->_IO_read_ptr = fp->_IO_read_end;
} }
int int
DEFUN(_IO_switch_to_get_mode, (fp), _IO_switch_to_get_mode (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
if (fp->_IO_write_ptr > fp->_IO_write_base) if (fp->_IO_write_ptr > fp->_IO_write_base)
if (_IO_OVERFLOW (fp, EOF) == EOF) if (_IO_OVERFLOW (fp, EOF) == EOF)
return EOF; return EOF;
if (_IO_in_backup(fp)) if (_IO_in_backup (fp))
fp->_IO_read_base = fp->_IO_backup_base; fp->_IO_read_base = fp->_IO_backup_base;
else else
{ {
...@@ -126,11 +142,11 @@ DEFUN(_IO_switch_to_get_mode, (fp), ...@@ -126,11 +142,11 @@ DEFUN(_IO_switch_to_get_mode, (fp),
} }
void void
DEFUN(_IO_free_backup_area, (fp), _IO_free_backup_area (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
if (_IO_in_backup (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); free (fp->_IO_save_base);
fp->_IO_save_base = NULL; fp->_IO_save_base = NULL;
fp->_IO_save_end = NULL; fp->_IO_save_end = NULL;
...@@ -139,13 +155,14 @@ DEFUN(_IO_free_backup_area, (fp), ...@@ -139,13 +155,14 @@ DEFUN(_IO_free_backup_area, (fp),
#if 0 #if 0
int int
DEFUN(_IO_switch_to_put_mode, (fp), _IO_switch_to_put_mode (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
fp->_IO_write_base = fp->_IO_read_ptr; fp->_IO_write_base = fp->_IO_read_ptr;
fp->_IO_write_ptr = fp->_IO_read_ptr; fp->_IO_write_ptr = fp->_IO_read_ptr;
/* Following is wrong if line- or un-buffered? */ /* 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_ptr = fp->_IO_read_end;
fp->_IO_read_base = fp->_IO_read_end; fp->_IO_read_base = fp->_IO_read_end;
...@@ -156,18 +173,21 @@ DEFUN(_IO_switch_to_put_mode, (fp), ...@@ -156,18 +173,21 @@ DEFUN(_IO_switch_to_put_mode, (fp),
#endif #endif
int int
DEFUN(__overflow, (f, ch), __overflow (f, ch)
_IO_FILE *f AND int ch) _IO_FILE *f;
int ch;
{ {
return _IO_OVERFLOW (f, ch); return _IO_OVERFLOW (f, ch);
} }
static int static int save_for_backup __P ((_IO_FILE *fp));
DEFUN(save_for_backup, (fp),
_IO_FILE *fp) static int
save_for_backup (fp)
_IO_FILE *fp;
{ {
/* Append [_IO_read_base.._IO_read_end] to backup area. */ /* 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. */ /* 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 needed_size = (fp->_IO_read_end - fp->_IO_read_base) - least_mark;
int current_Bsize = fp->_IO_save_end - fp->_IO_save_base; int current_Bsize = fp->_IO_save_end - fp->_IO_save_base;
...@@ -178,22 +198,22 @@ DEFUN(save_for_backup, (fp), ...@@ -178,22 +198,22 @@ DEFUN(save_for_backup, (fp),
{ {
char *new_buffer; char *new_buffer;
avail = 100; avail = 100;
new_buffer = (char*)malloc(avail+needed_size); new_buffer = (char *) malloc (avail + needed_size);
if (new_buffer == NULL) if (new_buffer == NULL)
return EOF; /* FIXME */ return EOF; /* FIXME */
if (least_mark < 0) if (least_mark < 0)
{ {
memcpy(new_buffer + avail, memcpy (new_buffer + avail,
fp->_IO_save_end + least_mark, fp->_IO_save_end + least_mark,
-least_mark); -least_mark);
memcpy(new_buffer +avail - least_mark, memcpy (new_buffer + avail - least_mark,
fp->_IO_read_base, fp->_IO_read_base,
fp->_IO_read_end - fp->_IO_read_base); fp->_IO_read_end - fp->_IO_read_base);
} }
else else
memcpy(new_buffer + avail, memcpy (new_buffer + avail,
fp->_IO_read_base + least_mark, fp->_IO_read_base + least_mark,
needed_size); needed_size);
if (fp->_IO_save_base) if (fp->_IO_save_base)
free (fp->_IO_save_base); free (fp->_IO_save_base);
fp->_IO_save_base = new_buffer; fp->_IO_save_base = new_buffer;
...@@ -204,17 +224,17 @@ DEFUN(save_for_backup, (fp), ...@@ -204,17 +224,17 @@ DEFUN(save_for_backup, (fp),
avail = current_Bsize - needed_size; avail = current_Bsize - needed_size;
if (least_mark < 0) if (least_mark < 0)
{ {
memmove(fp->_IO_save_base + avail, memmove (fp->_IO_save_base + avail,
fp->_IO_save_end + least_mark, fp->_IO_save_end + least_mark,
-least_mark); -least_mark);
memcpy(fp->_IO_save_base + avail - least_mark, memcpy (fp->_IO_save_base + avail - least_mark,
fp->_IO_read_base, fp->_IO_read_base,
fp->_IO_read_end - fp->_IO_read_base); fp->_IO_read_end - fp->_IO_read_base);
} }
else if (needed_size > 0) else if (needed_size > 0)
memcpy(fp->_IO_save_base + avail, memcpy (fp->_IO_save_base + avail,
fp->_IO_read_base + least_mark, fp->_IO_read_base + least_mark,
needed_size); needed_size);
} }
/* FIXME: Dubious arithmetic if pointers are NULL */ /* FIXME: Dubious arithmetic if pointers are NULL */
fp->_IO_backup_base = fp->_IO_save_base + avail; fp->_IO_backup_base = fp->_IO_save_base + avail;
...@@ -226,59 +246,64 @@ DEFUN(save_for_backup, (fp), ...@@ -226,59 +246,64 @@ DEFUN(save_for_backup, (fp),
} }
int int
DEFUN(__underflow, (fp), __underflow (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
if (_IO_in_put_mode(fp)) if (_IO_in_put_mode (fp))
if (_IO_switch_to_get_mode(fp) == EOF) return EOF; if (_IO_switch_to_get_mode (fp) == EOF)
return EOF;
if (fp->_IO_read_ptr < fp->_IO_read_end) if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char*)fp->_IO_read_ptr; return *(unsigned char *) fp->_IO_read_ptr;
if (_IO_in_backup(fp)) 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) if (fp->_IO_read_ptr < fp->_IO_read_end)
return *fp->_IO_read_ptr; return *fp->_IO_read_ptr;
} }
if (_IO_have_markers(fp)) if (_IO_have_markers (fp))
{ {
if (save_for_backup (fp)) if (save_for_backup (fp))
return EOF; return EOF;
} }
else if (_IO_have_backup(fp)) else if (_IO_have_backup (fp))
_IO_free_backup_area(fp); _IO_free_backup_area (fp);
return _IO_UNDERFLOW (fp); return _IO_UNDERFLOW (fp);
} }
int int
DEFUN(__uflow, (fp), __uflow (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
if (_IO_in_put_mode(fp)) if (_IO_in_put_mode (fp))
if (_IO_switch_to_get_mode(fp) == EOF) return EOF; if (_IO_switch_to_get_mode (fp) == EOF)
return EOF;
if (fp->_IO_read_ptr < fp->_IO_read_end) if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char*)fp->_IO_read_ptr++; return *(unsigned char *) fp->_IO_read_ptr++;
if (_IO_in_backup(fp)) 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) if (fp->_IO_read_ptr < fp->_IO_read_end)
return *fp->_IO_read_ptr++; return *fp->_IO_read_ptr++;
} }
if (_IO_have_markers(fp)) if (_IO_have_markers (fp))
{ {
if (save_for_backup (fp)) if (save_for_backup (fp))
return EOF; return EOF;
} }
else if (_IO_have_backup(fp)) else if (_IO_have_backup (fp))
_IO_free_backup_area(fp); _IO_free_backup_area (fp);
return _IO_UFLOW (fp); return _IO_UFLOW (fp);
} }
void void
DEFUN(_IO_setb, (f, b, eb, a), _IO_setb (f, b, eb, a)
_IO_FILE *f AND char *b AND char *eb AND int a) _IO_FILE *f;
char *b;
char *eb;
int a;
{ {
if (f->_IO_buf_base && !(f->_flags & _IO_USER_BUF)) 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_base = b;
f->_IO_buf_end = eb; f->_IO_buf_end = eb;
if (a) if (a)
...@@ -288,52 +313,55 @@ DEFUN(_IO_setb, (f, b, eb, a), ...@@ -288,52 +313,55 @@ DEFUN(_IO_setb, (f, b, eb, a),
} }
void void
DEFUN(_IO_doallocbuf, (fp), _IO_doallocbuf (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
if (fp->_IO_buf_base) if (fp->_IO_buf_base)
return; return;
if (!(fp->_flags & _IO_UNBUFFERED)) if (!(fp->_flags & _IO_UNBUFFERED))
if (_IO_DOALLOCATE (fp) != EOF) if (_IO_DOALLOCATE (fp) != EOF)
return; return;
_IO_setb(fp, fp->_shortbuf, fp->_shortbuf+1, 0); _IO_setb (fp, fp->_shortbuf, fp->_shortbuf+1, 0);
} }
int int
DEFUN(_IO_default_underflow, (fp), _IO_default_underflow (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
return EOF; return EOF;
} }
int int
DEFUN(_IO_default_uflow, (fp), _IO_default_uflow (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
int ch = _IO_UNDERFLOW (fp); int ch = _IO_UNDERFLOW (fp);
if (ch == EOF) if (ch == EOF)
return EOF; return EOF;
return *(unsigned char*)fp->_IO_read_ptr++; return *(unsigned char *) fp->_IO_read_ptr++;
} }
_IO_size_t _IO_size_t
DEFUN(_IO_default_xsputn, (f, data, n), _IO_default_xsputn (f, data, n)
register _IO_FILE *f AND const void *data AND _IO_size_t n) _IO_FILE *f;
const void *data;
_IO_size_t n;
{ {
register const char *s = (char*) data; const char *s = (char *) data;
register _IO_size_t more = n; _IO_size_t more = n;
if (more <= 0) if (more <= 0)
return 0; return 0;
for (;;) 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 > 0)
{ {
if (count > more) if ((_IO_size_t) count > more)
count = more; count = more;
if (count > 20) if (count > 20)
{ {
memcpy(f->_IO_write_ptr, s, count); memcpy (f->_IO_write_ptr, s, count);
s += count; s += count;
f->_IO_write_ptr += count; f->_IO_write_ptr += count;
} }
...@@ -341,14 +369,15 @@ DEFUN(_IO_default_xsputn, (f, data, n), ...@@ -341,14 +369,15 @@ DEFUN(_IO_default_xsputn, (f, data, n),
count = 0; count = 0;
else else
{ {
register char *p = f->_IO_write_ptr; char *p = f->_IO_write_ptr;
register _IO_ssize_t i; _IO_ssize_t i;
for (i = count; --i >= 0; ) *p++ = *s++; for (i = count; --i >= 0; )
*p++ = *s++;
f->_IO_write_ptr = p; f->_IO_write_ptr = p;
} }
more -= count; more -= count;
} }
if (more == 0 || __overflow(f, (unsigned char)*s++) == EOF) if (more == 0 || __overflow (f, (unsigned char) *s++) == EOF)
break; break;
more--; more--;
} }
...@@ -356,29 +385,34 @@ DEFUN(_IO_default_xsputn, (f, data, n), ...@@ -356,29 +385,34 @@ DEFUN(_IO_default_xsputn, (f, data, n),
} }
_IO_size_t _IO_size_t
DEFUN(_IO_sgetn, (fp, data, n), _IO_sgetn (fp, data, n)
_IO_FILE *fp AND void *data AND _IO_size_t n) _IO_FILE *fp;
void *data;
_IO_size_t n;
{ {
/* FIXME handle putback buffer here! */ /* FIXME handle putback buffer here! */
return _IO_XSGETN (fp, data, n); return _IO_XSGETN (fp, data, n);
} }
_IO_size_t _IO_size_t
DEFUN(_IO_default_xsgetn, (fp, data, n), _IO_default_xsgetn (fp, data, n)
_IO_FILE *fp AND void *data AND _IO_size_t n) _IO_FILE *fp;
void *data;
_IO_size_t n;
{ {
register _IO_size_t more = n; _IO_size_t more = n;
register char *s = (char*) data; char *s = (char*) data;
for (;;) 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 > 0)
{ {
if (count > more) if ((_IO_size_t) count > more)
count = more; count = more;
if (count > 20) if (count > 20)
{ {
memcpy(s, fp->_IO_read_ptr, count); memcpy (s, fp->_IO_read_ptr, count);
s += count; s += count;
fp->_IO_read_ptr += count; fp->_IO_read_ptr += count;
} }
...@@ -386,41 +420,47 @@ DEFUN(_IO_default_xsgetn, (fp, data, n), ...@@ -386,41 +420,47 @@ DEFUN(_IO_default_xsgetn, (fp, data, n),
count = 0; count = 0;
else else
{ {
register char *p = fp->_IO_read_ptr; char *p = fp->_IO_read_ptr;
register int i = (int)count; int i = (int) count;
while (--i >= 0) *s++ = *p++; while (--i >= 0)
*s++ = *p++;
fp->_IO_read_ptr = p; fp->_IO_read_ptr = p;
} }
more -= count; more -= count;
} }
if (more == 0 || __underflow(fp) == EOF) if (more == 0 || __underflow (fp) == EOF)
break; break;
} }
return n - more; return n - more;
} }
#if 0
/* Seems not to be needed. --drepper */
int int
DEFUN(_IO_sync, (fp), _IO_sync (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
return 0; return 0;
} }
#endif
_IO_FILE* _IO_FILE *
DEFUN(_IO_default_setbuf, (fp, p, len), _IO_default_setbuf (fp, p, len)
register _IO_FILE *fp AND char* p AND _IO_ssize_t len) _IO_FILE *fp;
char *p;
_IO_ssize_t len;
{ {
if (_IO_SYNC (fp) == EOF) if (_IO_SYNC (fp) == EOF)
return NULL; return NULL;
if (p == NULL || len == 0) if (p == NULL || len == 0)
{ {
fp->_flags |= _IO_UNBUFFERED; fp->_flags |= _IO_UNBUFFERED;
_IO_setb(fp, fp->_shortbuf, fp->_shortbuf+1, 0); _IO_setb (fp, fp->_shortbuf, fp->_shortbuf+1, 0);
} }
else else
{ {
fp->_flags &= ~_IO_UNBUFFERED; 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_write_base = fp->_IO_write_ptr = fp->_IO_write_end = 0;
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_read_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), ...@@ -428,26 +468,29 @@ DEFUN(_IO_default_setbuf, (fp, p, len),
} }
_IO_pos_t _IO_pos_t
DEFUN(_IO_default_seekpos, (fp, pos, mode), _IO_default_seekpos (fp, pos, mode)
_IO_FILE *fp AND _IO_pos_t pos AND int 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 int
DEFUN(_IO_default_doallocate, (fp), _IO_default_doallocate (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
char *buf = ALLOC_BUF(_IO_BUFSIZ); char *buf;
if (buf == NULL)
return EOF; ALLOC_BUF (buf, _IO_BUFSIZ, EOF);
_IO_setb(fp, buf, buf+_IO_BUFSIZ, 1); _IO_setb (fp, buf, buf+_IO_BUFSIZ, 1);
return 1; return 1;
} }
void void
DEFUN(_IO_init, (fp, flags), _IO_init (fp, flags)
register _IO_FILE *fp AND int flags) _IO_FILE *fp;
int flags;
{ {
fp->_flags = _IO_MAGIC|flags; fp->_flags = _IO_MAGIC|flags;
fp->_IO_buf_base = NULL; fp->_IO_buf_base = NULL;
...@@ -465,11 +508,14 @@ DEFUN(_IO_init, (fp, flags), ...@@ -465,11 +508,14 @@ DEFUN(_IO_init, (fp, flags),
fp->_IO_save_end = NULL; fp->_IO_save_end = NULL;
fp->_markers = NULL; fp->_markers = NULL;
fp->_cur_column = 0; fp->_cur_column = 0;
#ifdef _IO_MTSAFE_IO
_IO_lock_init (*fp->_lock);
#endif
} }
int int
DEFUN(_IO_default_sync, (fp), _IO_default_sync (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
return 0; return 0;
} }
...@@ -478,13 +524,14 @@ DEFUN(_IO_default_sync, (fp), ...@@ -478,13 +524,14 @@ DEFUN(_IO_default_sync, (fp),
current implementation, this function can get called twice! */ current implementation, this function can get called twice! */
void void
DEFUN(_IO_default_finish, (fp), _IO_default_finish (fp, dummy)
_IO_FILE *fp) _IO_FILE *fp;
int dummy;
{ {
struct _IO_marker *mark; struct _IO_marker *mark;
if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF)) 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; fp->_IO_buf_base = fp->_IO_buf_end = NULL;
} }
...@@ -497,27 +544,35 @@ DEFUN(_IO_default_finish, (fp), ...@@ -497,27 +544,35 @@ DEFUN(_IO_default_finish, (fp),
fp->_IO_save_base = NULL; 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 _IO_pos_t
DEFUN(_IO_default_seekoff, (fp, offset, dir, mode), _IO_default_seekoff (fp, offset, dir, mode)
register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode) _IO_FILE *fp;
_IO_off_t offset;
int dir;
int mode;
{ {
return _IO_pos_BAD; return _IO_pos_BAD;
} }
int int
DEFUN(_IO_sputbackc, (fp, c), _IO_sputbackc (fp, c)
register _IO_FILE *fp AND int c) _IO_FILE *fp;
int c;
{ {
int result; int result;
if (fp->_IO_read_ptr > fp->_IO_read_base if (fp->_IO_read_ptr > fp->_IO_read_base
&& (unsigned char)fp->_IO_read_ptr[-1] == (unsigned char)c) && (unsigned char)fp->_IO_read_ptr[-1] == (unsigned char)c)
{ {
fp->_IO_read_ptr--; fp->_IO_read_ptr--;
result = (unsigned char)c; result = (unsigned char) c;
} }
else else
result = _IO_PBACKFAIL (fp, c); result = _IO_PBACKFAIL (fp, c);
...@@ -529,15 +584,15 @@ DEFUN(_IO_sputbackc, (fp, c), ...@@ -529,15 +584,15 @@ DEFUN(_IO_sputbackc, (fp, c),
} }
int int
DEFUN(_IO_sungetc, (fp), _IO_sungetc (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
int result; int result;
if (fp->_IO_read_ptr > fp->_IO_read_base) if (fp->_IO_read_ptr > fp->_IO_read_base)
{ {
fp->_IO_read_ptr--; fp->_IO_read_ptr--;
result = (unsigned char)*fp->_IO_read_ptr; result = (unsigned char) *fp->_IO_read_ptr;
} }
else else
result = _IO_PBACKFAIL (fp, EOF); result = _IO_PBACKFAIL (fp, EOF);
...@@ -549,9 +604,12 @@ DEFUN(_IO_sungetc, (fp), ...@@ -549,9 +604,12 @@ DEFUN(_IO_sungetc, (fp),
} }
#if 0 /* Work in progress */ #if 0 /* Work in progress */
/* Seems not to be needed. */
#if 0
void void
DEFUN(_IO_set_column, (fp, c), _IO_set_column (fp, c)
register _IO_FILE *fp AND int c) _IO_FILE *fp;
int c;
{ {
if (c == -1) if (c == -1)
fp->_column = -1; fp->_column = -1;
...@@ -560,39 +618,46 @@ DEFUN(_IO_set_column, (fp, c), ...@@ -560,39 +618,46 @@ DEFUN(_IO_set_column, (fp, c),
} }
#else #else
int int
DEFUN(_IO_set_column, (fp, i), _IO_set_column (fp, i)
register _IO_FILE *fp AND int i) _IO_FILE *fp;
int i;
{ {
fp->_cur_column = i+1; fp->_cur_column = i + 1;
return 0; return 0;
} }
#endif #endif
#endif
unsigned unsigned
DEFUN(_IO_adjust_column, (start, line, count), _IO_adjust_column (start, line, count)
unsigned start AND const char *line AND int count) unsigned start;
const char *line;
int count;
{ {
register const char *ptr = line + count; const char *ptr = line + count;
while (ptr > line) while (ptr > line)
if (*--ptr == '\n') if (*--ptr == '\n')
return line + count - ptr - 1; return line + count - ptr - 1;
return start + count; return start + count;
} }
#if 0
/* Seems not to be needed. --drepper */
int int
DEFUN(_IO_get_column, (fp), _IO_get_column (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
if (fp->_cur_column) if (fp->_cur_column)
return _IO_adjust_column(fp->_cur_column - 1, return _IO_adjust_column (fp->_cur_column - 1,
fp->_IO_write_base, fp->_IO_write_base,
fp->_IO_write_ptr - fp->_IO_write_base); fp->_IO_write_ptr - fp->_IO_write_base);
return -1; return -1;
} }
#endif
int int
DEFUN_VOID(_IO_flush_all) _IO_flush_all ()
{ {
int result = 0; int result = 0;
_IO_FILE *fp; _IO_FILE *fp;
...@@ -604,16 +669,18 @@ DEFUN_VOID(_IO_flush_all) ...@@ -604,16 +669,18 @@ DEFUN_VOID(_IO_flush_all)
} }
void void
DEFUN_VOID(_IO_flush_all_linebuffered) _IO_flush_all_linebuffered ()
{ {
_IO_FILE *fp; _IO_FILE *fp;
for (fp = _IO_list_all; fp != NULL; fp = fp->_chain) 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); _IO_OVERFLOW (fp, EOF);
} }
void static void _IO_unbuffer_all __P ((void));
DEFUN_VOID(_IO_unbuffer_all)
static void
_IO_unbuffer_all ()
{ {
_IO_FILE *fp; _IO_FILE *fp;
for (fp = _IO_list_all; fp != NULL; fp = fp->_chain) for (fp = _IO_list_all; fp != NULL; fp = fp->_chain)
...@@ -622,43 +689,44 @@ DEFUN_VOID(_IO_unbuffer_all) ...@@ -622,43 +689,44 @@ DEFUN_VOID(_IO_unbuffer_all)
} }
void void
DEFUN_VOID(_IO_cleanup) _IO_cleanup ()
{ {
_IO_flush_all (); _IO_flush_all ();
/* We currently don't have a reliable mechanism for making sure that /* We currently don't have a reliable mechanism for making sure that
C++ static destructors are executed in the correct order. 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. 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. */ which forces any output from late destructors to be written out. */
_IO_unbuffer_all (); _IO_unbuffer_all ();
} }
void void
DEFUN(_IO_init_marker, (marker, fp), _IO_init_marker (marker, fp)
struct _IO_marker *marker AND _IO_FILE *fp) struct _IO_marker *marker;
_IO_FILE *fp;
{ {
marker->_sbuf = fp; marker->_sbuf = fp;
if (_IO_in_put_mode(fp)) if (_IO_in_put_mode (fp))
_IO_switch_to_get_mode(fp); _IO_switch_to_get_mode (fp);
if (_IO_in_backup(fp)) if (_IO_in_backup (fp))
marker->_pos = fp->_IO_read_ptr - fp->_IO_read_end; marker->_pos = fp->_IO_read_ptr - fp->_IO_read_end;
else else
marker->_pos = fp->_IO_read_ptr - fp->_IO_read_base; marker->_pos = fp->_IO_read_ptr - fp->_IO_read_base;
/* Should perhaps sort the chain? */ /* Should perhaps sort the chain? */
marker->_next = fp->_markers; marker->_next = fp->_markers;
fp->_markers = marker; fp->_markers = marker;
} }
void void
DEFUN(_IO_remove_marker, (marker), _IO_remove_marker (marker)
register struct _IO_marker *marker) struct _IO_marker *marker;
{ {
/* Unlink from sb's chain. */ /* Unlink from sb's chain. */
register struct _IO_marker **ptr = &marker->_sbuf->_markers; struct _IO_marker **ptr = &marker->_sbuf->_markers;
for (; ; ptr = &(*ptr)->_next) for (; ; ptr = &(*ptr)->_next)
{ {
if (*ptr == NULL) if (*ptr == NULL)
...@@ -678,21 +746,22 @@ DEFUN(_IO_remove_marker, (marker), ...@@ -678,21 +746,22 @@ DEFUN(_IO_remove_marker, (marker),
#define BAD_DELTA EOF #define BAD_DELTA EOF
int int
DEFUN(_IO_marker_difference, (mark1, mark2), _IO_marker_difference (mark1, mark2)
struct _IO_marker *mark1 AND struct _IO_marker *mark2) struct _IO_marker *mark1;
struct _IO_marker *mark2;
{ {
return mark1->_pos - mark2->_pos; 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 int
DEFUN(_IO_marker_delta, (mark), _IO_marker_delta (mark)
struct _IO_marker *mark) struct _IO_marker *mark;
{ {
int cur_pos; int cur_pos;
if (mark->_sbuf == NULL) if (mark->_sbuf == NULL)
return BAD_DELTA; 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; cur_pos = mark->_sbuf->_IO_read_ptr - mark->_sbuf->_IO_read_end;
else else
cur_pos = mark->_sbuf->_IO_read_ptr - mark->_sbuf->_IO_read_base; cur_pos = mark->_sbuf->_IO_read_ptr - mark->_sbuf->_IO_read_base;
...@@ -700,135 +769,150 @@ DEFUN(_IO_marker_delta, (mark), ...@@ -700,135 +769,150 @@ DEFUN(_IO_marker_delta, (mark),
} }
int int
DEFUN(_IO_seekmark, (fp, mark, delta), _IO_seekmark (fp, mark, delta)
_IO_FILE *fp AND struct _IO_marker *mark AND int delta) _IO_FILE *fp;
struct _IO_marker *mark;
int delta;
{ {
if (mark->_sbuf != fp) if (mark->_sbuf != fp)
return EOF; return EOF;
if (mark->_pos >= 0) if (mark->_pos >= 0)
{ {
if (_IO_in_backup(fp)) if (_IO_in_backup (fp))
_IO_switch_to_main_get_area(fp); _IO_switch_to_main_get_area (fp);
fp->_IO_read_ptr = fp->_IO_read_base + mark->_pos; fp->_IO_read_ptr = fp->_IO_read_base + mark->_pos;
} }
else else
{ {
if (!_IO_in_backup(fp)) if (!_IO_in_backup (fp))
_IO_switch_to_backup_area(fp); _IO_switch_to_backup_area (fp);
fp->_IO_read_ptr = fp->_IO_read_end + mark->_pos; fp->_IO_read_ptr = fp->_IO_read_end + mark->_pos;
} }
return 0; return 0;
} }
void void
DEFUN(_IO_unsave_markers, (fp), _IO_unsave_markers (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
register struct _IO_marker *mark = fp->_markers; struct _IO_marker *mark = fp->_markers;
if (mark) if (mark)
{ {
#ifdef TODO #ifdef TODO
streampos offset = seekoff(0, ios::cur, ios::in); streampos offset = seekoff (0, ios::cur, ios::in);
if (offset != EOF) if (offset != EOF)
{ {
offset += eGptr() - Gbase(); offset += eGptr () - Gbase ();
for ( ; mark != NULL; mark = mark->_next) for ( ; mark != NULL; mark = mark->_next)
mark->set_streampos(mark->_pos + offset); mark->set_streampos (mark->_pos + offset);
} }
else else
{ {
for ( ; mark != NULL; mark = mark->_next) for ( ; mark != NULL; mark = mark->_next)
mark->set_streampos(EOF); mark->set_streampos (EOF);
} }
#endif #endif
fp->_markers = 0; fp->_markers = 0;
} }
if (_IO_have_backup(fp)) if (_IO_have_backup (fp))
_IO_free_backup_area(fp); _IO_free_backup_area (fp);
} }
#if 0
/* Seems not to be needed. --drepper */
int int
DEFUN(_IO_nobackup_pbackfail, (fp, c), _IO_nobackup_pbackfail (fp, c)
register _IO_FILE *fp AND int c) _IO_FILE *fp;
int c;
{ {
if (fp->_IO_read_ptr > fp->_IO_read_base) if (fp->_IO_read_ptr > fp->_IO_read_base)
fp->_IO_read_ptr--; fp->_IO_read_ptr--;
if (c != EOF && *fp->_IO_read_ptr != c) if (c != EOF && *fp->_IO_read_ptr != c)
*fp->_IO_read_ptr = c; *fp->_IO_read_ptr = c;
return (unsigned char)c; return (unsigned char) c;
} }
#endif
int int
DEFUN(_IO_default_pbackfail, (fp, c), _IO_default_pbackfail (fp, c)
register _IO_FILE *fp AND int c) _IO_FILE *fp;
int c;
{ {
if (fp->_IO_read_ptr <= fp->_IO_read_base) if (fp->_IO_read_ptr <= fp->_IO_read_base)
{ {
/* Need to handle a filebuf in write mode (switch to read mode). FIXME!*/ /* Need to handle a filebuf in write mode (switch to read mode). FIXME!*/
if (_IO_have_backup(fp) && !_IO_in_backup(fp)) if (_IO_have_backup (fp) && !_IO_in_backup (fp))
_IO_switch_to_backup_area(fp); _IO_switch_to_backup_area (fp);
if (!_IO_have_backup(fp)) if (!_IO_have_backup (fp))
{ {
/* No backup buffer: allocate one. */ /* No backup buffer: allocate one. */
/* Use nshort buffer, if unused? (probably not) FIXME */ /* Use nshort buffer, if unused? (probably not) FIXME */
int backup_size = 128; int backup_size = 128;
char *bbuf = (char*)malloc(backup_size); char *bbuf = (char *) malloc (backup_size);
if (bbuf == NULL) if (bbuf == NULL)
return EOF; return EOF;
fp->_IO_save_base = bbuf; fp->_IO_save_base = bbuf;
fp->_IO_save_end = fp->_IO_save_base + backup_size; fp->_IO_save_end = fp->_IO_save_base + backup_size;
fp->_IO_backup_base = fp->_IO_save_end; fp->_IO_backup_base = fp->_IO_save_end;
_IO_switch_to_backup_area(fp); _IO_switch_to_backup_area (fp);
} }
else if (fp->_IO_read_ptr <= fp->_IO_read_base) else if (fp->_IO_read_ptr <= fp->_IO_read_base)
{ {
/* Increase size of existing backup buffer. */ /* Increase size of existing backup buffer. */
_IO_size_t new_size; _IO_size_t new_size;
_IO_size_t old_size = fp->_IO_read_end - fp->_IO_read_base; _IO_size_t old_size = fp->_IO_read_end - fp->_IO_read_base;
char *new_buf; char *new_buf;
new_size = 2 * old_size; new_size = 2 * old_size;
new_buf = (char*)malloc(new_size); new_buf = (char *) malloc (new_size);
if (new_buf == NULL) if (new_buf == NULL)
return EOF; return EOF;
memcpy(new_buf+(new_size-old_size), fp->_IO_read_base, old_size); memcpy (new_buf + (new_size - old_size), fp->_IO_read_base,
free (fp->_IO_read_base); old_size);
_IO_setg(fp, free (fp->_IO_read_base);
new_buf, new_buf+(new_size-old_size), new_buf+new_size); _IO_setg (fp, new_buf, new_buf + (new_size - old_size),
fp->_IO_backup_base = fp->_IO_read_ptr; new_buf + new_size);
} fp->_IO_backup_base = fp->_IO_read_ptr;
} }
fp->_IO_read_ptr--; }
--fp->_IO_read_ptr;
if (c != EOF && *fp->_IO_read_ptr != c) if (c != EOF && *fp->_IO_read_ptr != c)
*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 _IO_pos_t
DEFUN(_IO_default_seek, (fp, offset, dir), _IO_default_seek (fp, offset, dir)
_IO_FILE *fp AND _IO_off_t offset AND int dir) _IO_FILE *fp;
_IO_off_t offset;
int dir;
{ {
return _IO_pos_BAD; return _IO_pos_BAD;
} }
int int
DEFUN(_IO_default_stat, (fp, st), _IO_default_stat (fp, st)
_IO_FILE *fp AND void* st) _IO_FILE *fp;
void* st;
{ {
return EOF; return EOF;
} }
_IO_ssize_t _IO_ssize_t
DEFUN(_IO_default_read, (fp, data, n), _IO_default_read (fp, data, n)
register _IO_FILE* fp AND void* data AND _IO_ssize_t n) _IO_FILE* fp;
void *data;
_IO_ssize_t n;
{ {
return -1; return -1;
} }
_IO_ssize_t _IO_ssize_t
DEFUN(_IO_default_write, (fp, data, n), _IO_default_write (fp, data, n)
register _IO_FILE* fp AND const void* data AND _IO_ssize_t n) _IO_FILE *fp;
const void *data;
_IO_ssize_t n;
{ {
return 0; return 0;
} }
...@@ -844,9 +928,17 @@ DEFUN(_IO_default_write, (fp, data, n), ...@@ -844,9 +928,17 @@ DEFUN(_IO_default_write, (fp, data, n),
#else #else
struct __io_defs { struct __io_defs {
__io_defs() { } __io_defs() { }
~__io_defs() { _IO_cleanup(); } ~__io_defs() { _IO_cleanup (); }
}; };
__io_defs io_defs__; __io_defs io_defs__;
#endif #endif
#endif /* TODO */ #endif /* TODO */
#ifdef weak_alias
weak_alias (_IO_cleanup, _cleanup)
#endif
#ifdef text_set_element
text_set_element(__libc_atexit, _cleanup);
#endif
/* this will be used later*/
/* /* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#ifdef __STDC__ #ifdef __STDC__
...@@ -28,20 +29,30 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -28,20 +29,30 @@ the executable file might be covered by the GNU General Public License. */
#endif #endif
int int
DEFUN(_IO_fclose, (fp), _IO_fclose (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
int status; int status;
CHECK_FILE(fp, EOF); 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) if (fp->_IO_file_flags & _IO_IS_FILEBUF)
status = _IO_file_close_it(fp); status = _IO_file_close_it (fp);
else else
status = fp->_flags & _IO_ERR_SEEN ? -1 : 0; status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
_IO_FINISH (fp); _IO_FINISH (fp);
_IO_cleanup_region_end (1);
if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr) if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
{ {
fp->_IO_file_flags = 0; fp->_IO_file_flags = 0;
free(fp); free(fp);
} }
return status; return status;
} }
#ifdef weak_alias
weak_alias (_IO_fclose, fclose)
#endif
/* /* Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
Copyright (C) 1993, 1994 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#ifdef __STDC__ #ifdef __STDC__
#include <stdlib.h> #include <stdlib.h>
...@@ -33,12 +34,19 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -33,12 +34,19 @@ the executable file might be covered by the GNU General Public License. */
#endif #endif
_IO_FILE * _IO_FILE *
DEFUN(_IO_fdopen, (fd, mode), _IO_fdopen (fd, mode)
int fd AND const char *mode) int fd;
const char *mode;
{ {
int read_write; int read_write;
int posix_mode = 0; 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; int fd_flags;
switch (*mode++) switch (*mode++)
...@@ -54,9 +62,7 @@ DEFUN(_IO_fdopen, (fd, mode), ...@@ -54,9 +62,7 @@ DEFUN(_IO_fdopen, (fd, mode),
read_write = _IO_NO_READS|_IO_IS_APPENDING; read_write = _IO_NO_READS|_IO_IS_APPENDING;
break; break;
default: default:
#ifdef EINVAL MAYBE_SET_EINVAL;
errno = EINVAL;
#endif
return NULL; return NULL;
} }
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
...@@ -96,26 +102,33 @@ DEFUN(_IO_fdopen, (fd, mode), ...@@ -96,26 +102,33 @@ DEFUN(_IO_fdopen, (fd, mode),
} }
#endif #endif
fp = (struct _IO_FILE_plus*)malloc(sizeof(struct _IO_FILE_plus)); new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (fp == NULL) if (new_f == NULL)
return NULL; return NULL;
_IO_init(&fp->file, 0); #ifdef _IO_MTSAFE_IO
_IO_JUMPS(&fp->file) = &_IO_file_jumps; new_f->fp.file._lock = &new_f->lock;
_IO_file_init(&fp->file); #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 #if !_IO_UNIFIED_JUMPTABLES
fp->vtable = NULL; new_f->fp.vtable = NULL;
#endif #endif
if (_IO_file_attach(&fp->file, fd) == NULL) if (_IO_file_attach (&new_f->fp.file, fd) == NULL)
{ {
_IO_un_link(&fp->file); _IO_un_link (&new_f->fp.file);
free (fp); free (new_f);
return NULL; return NULL;
} }
fp->file._flags &= ~_IO_DELETE_DONT_CLOSE; new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
fp->file._IO_file_flags = new_f->fp.file._IO_file_flags =
_IO_mask_flags(&fp->file, read_write, _IO_mask_flags (&new_f->fp.file, read_write,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); _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
/* 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
/* 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
/* /* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <stdio.h>
int int
DEFUN(_IO_fflush, (fp), _IO_fflush (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
if (fp == NULL) if (fp == NULL)
return _IO_flush_all(); return _IO_flush_all ();
else else
{ {
CHECK_FILE(fp, EOF); int result;
return _IO_SYNC (fp) ? EOF : 0; 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
/* 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;
}
}
/* /* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <errno.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 int
DEFUN(_IO_fgetpos, (fp, posp), _IO_fgetpos (fp, posp)
_IO_FILE* fp AND _IO_fpos_t *posp) _IO_FILE* fp;
_IO_fpos_t *posp;
{ {
_IO_fpos_t pos; _IO_fpos_t pos;
CHECK_FILE(fp, EOF); CHECK_FILE (fp, EOF);
pos = _IO_seekoff(fp, 0, _IO_seek_cur, 0); _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) if (pos == _IO_pos_BAD)
{ {
#ifdef EIO #ifdef EIO
if (errno == 0) if (errno == 0)
errno = EIO; __set_errno (EIO);
#endif #endif
return EOF; return EOF;
} }
*posp = pos; *posp = pos;
return 0; return 0;
} }
#ifdef weak_alias
weak_alias (_IO_fgetpos, fgetpos)
#endif
/* /* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <stdio.h>
char* char *
DEFUN(_IO_fgets, (buf, n, fp), _IO_fgets (buf, n, fp)
char* buf AND int n AND _IO_FILE* fp) char *buf;
int n;
_IO_FILE *fp;
{ {
_IO_size_t count; _IO_size_t count;
CHECK_FILE(fp, NULL); char *result;
CHECK_FILE (fp, NULL);
if (n <= 0) if (n <= 0)
return NULL; 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)) if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN))
return NULL; result = NULL;
buf[count] = 0; else
return buf; {
buf[count] = '\0';
result = buf;
}
_IO_cleanup_region_end (1);
return result;
} }
#ifdef weak_alias
weak_alias (_IO_fgets, fgets)
#endif
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#ifdef __STDC__ #ifdef __STDC__
...@@ -28,22 +29,36 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -28,22 +29,36 @@ the executable file might be covered by the GNU General Public License. */
#endif #endif
_IO_FILE * _IO_FILE *
DEFUN(_IO_fopen, (filename, mode), _IO_fopen (filename, mode)
const char *filename AND const char *mode) const char *filename;
const char *mode;
{ {
struct _IO_FILE_plus *fp = struct locked_FILE
(struct _IO_FILE_plus*)malloc(sizeof(struct _IO_FILE_plus)); {
if (fp == NULL) 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; return NULL;
_IO_init(&fp->file, 0); #ifdef _IO_MTSAFE_IO
_IO_JUMPS(&fp->file) = &_IO_file_jumps; new_f->fp.file._lock = &new_f->lock;
_IO_file_init(&fp->file); #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 #if !_IO_UNIFIED_JUMPTABLES
fp->vtable = NULL; new_f->fp.vtable = NULL;
#endif #endif
if (_IO_file_fopen(&fp->file, filename, mode) != NULL) if (_IO_file_fopen (&new_f->fp.file, filename, mode) != NULL)
return (_IO_FILE*)fp; return (_IO_FILE *) &new_f->fp;
_IO_un_link(&fp->file); _IO_un_link (&new_f->fp.file);
free (fp); free (new_f);
return NULL; return NULL;
} }
#ifdef weak_alias
weak_alias (_IO_fopen, fopen)
#endif
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
...@@ -31,18 +32,20 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -31,18 +32,20 @@ the executable file might be covered by the GNU General Public License. */
#endif #endif
int int
_IO_fprintf
#ifdef __STDC__ #ifdef __STDC__
(_IO_FILE *fp, const char* format, ...) _IO_fprintf (_IO_FILE *fp, const char* format, ...)
#else #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 #endif
{ {
int ret; int ret;
va_list args; va_list args;
CHECK_FILE(fp, -1); CHECK_FILE (fp, -1);
_IO_va_start(args, format); _IO_va_start (args, format);
ret = _IO_vfprintf(fp, format, args); ret = _IO_vfprintf (fp, format, args);
va_end(args); va_end (args);
return ret; return ret;
} }
/* /* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <string.h> #include <string.h>
int int
DEFUN(_IO_fputs, (str, fp), _IO_fputs (str, fp)
const char *str AND _IO_FILE *fp) const char *str;
_IO_FILE *fp;
{ {
_IO_size_t len = strlen(str); _IO_size_t len = strlen (str);
CHECK_FILE(fp, EOF); int result;
if (_IO_sputn(fp, str, len) != len) CHECK_FILE (fp, EOF);
return EOF; _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
return 1; _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
/* /* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
_IO_size_t _IO_size_t
DEFUN(_IO_fread, (buf, size, count, fp), _IO_fread (buf, size, count, fp)
void *buf AND _IO_size_t size AND _IO_size_t count AND _IO_FILE* 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_requested = size*count;
_IO_size_t bytes_read; _IO_size_t bytes_read;
CHECK_FILE(fp, 0); CHECK_FILE (fp, 0);
if (bytes_requested == 0) if (bytes_requested == 0)
return 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; return bytes_requested == bytes_read ? count : bytes_read / size;
} }
#ifdef weak_alias
weak_alias (_IO_fread, fread)
#endif
/* /* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libioP.h> #include <libioP.h>
#include <errno.h> #include <errno.h>
int int
DEFUN(_IO_fsetpos, (fp, posp), _IO_fsetpos (fp, posp)
_IO_FILE* fp AND const _IO_fpos_t *posp) _IO_FILE *fp;
const _IO_fpos_t *posp;
{ {
CHECK_FILE(fp, EOF); int result;
if (_IO_seekpos(fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD) 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 #ifdef EIO
if (errno == 0) if (errno == 0)
errno = EIO; __set_errno (EIO);
#endif #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
/* /* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <errno.h> #include <errno.h>
/* ANSI explicily requires setting errno to a positive value on failure. */ /* ANSI explicily requires setting errno to a positive value on failure. */
long int long int
DEFUN(_IO_ftell, (fp), _IO_ftell (fp)
_IO_FILE* fp) _IO_FILE *fp;
{ {
_IO_pos_t pos; _IO_pos_t pos;
CHECK_FILE(fp, -1L); CHECK_FILE (fp, -1L);
pos = _IO_seekoff(fp, 0, _IO_seek_cur, 0); _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) if (pos == _IO_pos_BAD)
{ {
#ifdef EIO #ifdef EIO
if (errno == 0) if (errno == 0)
errno = EIO; __set_errno (EIO);
#endif #endif
return -1L; return -1L;
} }
return _IO_pos_as_off(pos); return _IO_pos_as_off (pos);
} }
#ifdef weak_alias
weak_alias (_IO_ftell, ftell)
#endif
/* /* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
_IO_size_t _IO_size_t
DEFUN(_IO_fwrite, (buf, size, count, fp), _IO_fwrite (buf, size, count, fp)
const void* buf AND _IO_size_t size AND _IO_size_t count const void *buf;
AND _IO_FILE *fp) _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; _IO_size_t written;
CHECK_FILE(fp, 0); CHECK_FILE (fp, 0);
if (request == 0) if (request == 0)
return 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, /* 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) if (written == request)
return count; return count;
else else
return written/size; return written / size;
} }
#ifdef weak_alias
weak_alias (_IO_fwrite, fwrite)
#endif
/* 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
/* /* Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1994 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#ifdef __STDC__ #ifdef __STDC__
#include <stdlib.h> #include <stdlib.h>
...@@ -36,36 +37,49 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -36,36 +37,49 @@ the executable file might be covered by the GNU General Public License. */
null terminator), or -1 on error or EOF. */ null terminator), or -1 on error or EOF. */
_IO_ssize_t _IO_ssize_t
DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp), _IO_getdelim (lineptr, n, delimiter, fp)
char **lineptr AND _IO_size_t *n AND int delimiter AND _IO_FILE *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; _IO_ssize_t len;
if (lineptr == NULL || n == NULL) if (lineptr == NULL || n == NULL)
{ {
#ifdef EINVAL MAYBE_SET_EINVAL;
errno = EINVAL;
#endif
return -1; return -1;
} }
CHECK_FILE (fp, -1); CHECK_FILE (fp, -1);
if (_IO_ferror (fp)) _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
return -1; _IO_flockfile (fp);
if (_IO_ferror_unlocked (fp))
{
result = -1;
goto unlock_return;
}
if (*lineptr == NULL || *n == 0) if (*lineptr == NULL || *n == 0)
{ {
*n = 120; *n = 120;
*lineptr = (char *) malloc (*n); *lineptr = (char *) malloc (*n);
if (*lineptr == NULL) if (*lineptr == NULL)
return -1; {
result = -1;
goto unlock_return;
}
} }
len = fp->_IO_read_end - fp->_IO_read_ptr; len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len <= 0) if (len <= 0)
{ {
if (__underflow (fp) == EOF) if (__underflow (fp) == EOF)
return -1; {
result = -1;
goto unlock_return;
}
len = fp->_IO_read_end - fp->_IO_read_ptr; len = fp->_IO_read_end - fp->_IO_read_ptr;
} }
...@@ -76,16 +90,19 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp), ...@@ -76,16 +90,19 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len); t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
if (t != NULL) if (t != NULL)
len = (t - fp->_IO_read_ptr) + 1; 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; needed = cur_len + len + 1;
if (needed > *n) if (needed > *n)
{ {
if (t == NULL && needed < 2 * *n) if (needed < 2 * *n)
needed = 2 * *n; /* Be generous. */ needed = 2 * *n; /* Be generous. */
*n = needed; *n = needed;
*lineptr = (char *) realloc (*lineptr, needed); *lineptr = (char *) realloc (*lineptr, needed);
if (*lineptr == NULL) if (*lineptr == NULL)
return -1; {
result = -1;
goto unlock_return;
}
} }
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len); memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len; fp->_IO_read_ptr += len;
...@@ -95,5 +112,14 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp), ...@@ -95,5 +112,14 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
len = fp->_IO_read_end - fp->_IO_read_ptr; len = fp->_IO_read_end - fp->_IO_read_ptr;
} }
(*lineptr)[cur_len] = '\0'; (*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
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <string.h> #include <string.h>
...@@ -34,38 +35,41 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -34,38 +35,41 @@ the executable file might be covered by the GNU General Public License. */
If extract_delim > 0, insert delim in output. */ If extract_delim > 0, insert delim in output. */
_IO_size_t _IO_size_t
DEFUN(_IO_getline, (fp, buf, n, delim, extract_delim), _IO_getline (fp, buf, n, delim, extract_delim)
_IO_FILE *fp AND char* buf AND _IO_size_t n _IO_FILE *fp;
AND int delim AND int extract_delim) char *buf;
_IO_size_t n;
int delim;
int extract_delim;
{ {
register char *ptr = buf; char *ptr = buf;
do do
{ {
_IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr; _IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr;
char *t; char *t;
if (len <= 0) if (len <= 0)
if (__underflow(fp) == EOF) if (__underflow (fp) == EOF)
break; break;
else else
len = fp->_IO_read_end - fp->_IO_read_ptr; len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len >= n) if ((_IO_size_t) len >= n)
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) if (t != NULL)
{ {
_IO_size_t old_len = ptr-buf; _IO_size_t old_len = ptr-buf;
len = t - fp->_IO_read_ptr; len = t - fp->_IO_read_ptr;
if (extract_delim >= 0) if (extract_delim >= 0)
{ {
t++; ++t;
if (extract_delim > 0) 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; fp->_IO_read_ptr = t;
return old_len + len; 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; fp->_IO_read_ptr += len;
ptr += len; ptr += len;
n -= len; n -= len;
......
/* /* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <limits.h> #include <limits.h>
char* char*
DEFUN(_IO_gets, (buf), _IO_gets (buf)
char* buf) char *buf;
{ {
_IO_size_t count; _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) if (ch == EOF)
return NULL; {
retval = NULL;
goto unlock_return;
}
if (ch == '\n') if (ch == '\n')
count = 0; count = 0;
else else
{ {
buf[0] = (char)ch; buf[0] = (char) ch;
count = _IO_getline(_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1; count = _IO_getline (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN) if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
return NULL; {
retval = NULL;
goto unlock_return;
}
} }
buf[count] = 0; 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
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
...@@ -31,34 +32,38 @@ static char const zeroes[PADSIZE] = ...@@ -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'}; {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
_IO_ssize_t _IO_ssize_t
DEFUN(_IO_padn, (fp, pad, count), _IO_padn (fp, pad, count)
_IO_FILE *fp AND int pad AND _IO_ssize_t count) _IO_FILE *fp;
int pad;
_IO_ssize_t count;
{ {
char padbuf[PADSIZE]; char padbuf[PADSIZE];
const char *padptr; const char *padptr;
register int i; int i;
_IO_size_t written = 0, w; _IO_size_t written = 0;
_IO_size_t w;
if (pad == ' ') if (pad == ' ')
padptr = blanks; padptr = blanks;
else if (pad == '0') else if (pad == '0')
padptr = zeroes; padptr = zeroes;
else else
{ {
for (i = PADSIZE; --i >= 0; ) padbuf[i] = pad; for (i = PADSIZE; --i >= 0; )
padbuf[i] = pad;
padptr = padbuf; padptr = padbuf;
} }
for (i = count; i >= PADSIZE; i -= PADSIZE) for (i = count; i >= PADSIZE; i -= PADSIZE)
{ {
w = _IO_sputn(fp, padptr, PADSIZE); w = _IO_sputn (fp, padptr, PADSIZE);
written += w; written += w;
if (w != PADSIZE) if (w != PADSIZE)
return written; return written;
} }
if (i > 0) if (i > 0)
{ {
w = _IO_sputn(fp, padptr, i); w = _IO_sputn (fp, padptr, i);
written += w; written += w;
} }
return written; return written;
......
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
Written by Per Bothner <bothner@cygnus.com>.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the This library is free software; you can redistribute it and/or
terms of the GNU General Public License as published by the modify it under the terms of the GNU General Public License as
Free Software Foundation; either version 2, or (at your option) published by the Free Software Foundation; either version 2, or (at
any later version. your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
the resulting executable to be covered by the GNU General Public License. compiled with a GNU compiler to produce an executable, this does
This exception does not however invalidate any other reasons why not cause the resulting executable to be covered by the GNU General
the executable file might be covered by the GNU General Public License. */ Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
/* written by Per Bothner (bothner@cygnus.com) */ General Public License. */
#define _POSIX_SOURCE #ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h" #include "libioP.h"
#include <sys/types.h>
#if _IO_HAVE_SYS_WAIT #if _IO_HAVE_SYS_WAIT
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#ifdef __STDC__ #ifdef __STDC__
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#ifdef _LIBC
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#ifndef _IO_fork #ifndef _IO_fork
#define _IO_fork vfork /* defined in libiberty, if needed */ #define _IO_fork vfork /* defined in libiberty, if needed */
_IO_pid_t _IO_fork(); extern _IO_pid_t _IO_fork __P ((void));
#endif #endif
#endif /* _IO_HAVE_SYS_WAIT */ #endif /* _IO_HAVE_SYS_WAIT */
#ifndef _IO_pipe #ifndef _IO_pipe
#define _IO_pipe pipe #define _IO_pipe pipe
extern int _IO_pipe(); extern int _IO_pipe __P ((int des[2]));
#endif #endif
#ifndef _IO_dup2 #ifndef _IO_dup2
#define _IO_dup2 dup2 #define _IO_dup2 dup2
extern int _IO_dup2(); extern int _IO_dup2 __P ((int fd, int fd2));
#endif #endif
#ifndef _IO_waitpid #ifndef _IO_waitpid
...@@ -75,17 +80,19 @@ typedef struct _IO_proc_file _IO_proc_file; ...@@ -75,17 +80,19 @@ typedef struct _IO_proc_file _IO_proc_file;
static struct _IO_proc_file *proc_file_chain = NULL; static struct _IO_proc_file *proc_file_chain = NULL;
_IO_FILE * _IO_FILE *
DEFUN(_IO_proc_open, (fp, command, mode), _IO_proc_open (fp, command, mode)
_IO_FILE* fp AND const char *command AND const char *mode) _IO_FILE *fp;
const char *command;
const char *mode;
{ {
#if _IO_HAVE_SYS_WAIT #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 pipe_fds[2];
int parent_end, child_end;
_IO_pid_t child_pid; _IO_pid_t child_pid;
if (_IO_file_is_open(fp)) if (_IO_file_is_open (fp))
return NULL; return NULL;
if (_IO_pipe(pipe_fds) < 0) if (_IO_pipe (pipe_fds) < 0)
return NULL; return NULL;
if (mode[0] == 'r') if (mode[0] == 'r')
{ {
...@@ -99,17 +106,17 @@ DEFUN(_IO_proc_open, (fp, command, mode), ...@@ -99,17 +106,17 @@ DEFUN(_IO_proc_open, (fp, command, mode),
child_end = pipe_fds[0]; child_end = pipe_fds[0];
read_or_write = _IO_NO_READS; 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) if (child_pid == 0)
{ {
int child_std_end = mode[0] == 'r' ? 1 : 0; int child_std_end = mode[0] == 'r' ? 1 : 0;
_IO_close(parent_end); _IO_close (parent_end);
if (child_end != child_std_end) if (child_end != child_std_end)
{ {
_IO_dup2(child_end, child_std_end); _IO_dup2 (child_end, child_std_end);
_IO_close(child_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 popen() calls that remain open in the parent process are closed
in the new child process." */ in the new child process." */
while (proc_file_chain) while (proc_file_chain)
...@@ -118,20 +125,20 @@ DEFUN(_IO_proc_open, (fp, command, mode), ...@@ -118,20 +125,20 @@ DEFUN(_IO_proc_open, (fp, command, mode),
proc_file_chain = proc_file_chain->next; proc_file_chain = proc_file_chain->next;
} }
_IO_execl("/bin/sh", "sh", "-c", command, (char *)0); _IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
_IO__exit(127); _IO__exit (127);
} }
_IO_close(child_end); _IO_close (child_end);
if (child_pid < 0) if (child_pid < 0)
{ {
_IO_close(parent_end); _IO_close (parent_end);
return NULL; return NULL;
} }
_IO_fileno(fp) = parent_end; _IO_fileno (fp) = parent_end;
/* Link into proc_file_chain. */ /* Link into proc_file_chain. */
((_IO_proc_file*)fp)->next = proc_file_chain; ((_IO_proc_file *) fp)->next = proc_file_chain;
proc_file_chain = (_IO_proc_file*)fp; proc_file_chain = (_IO_proc_file *) fp;
_IO_mask_flags (fp, read_or_write, _IO_NO_READS|_IO_NO_WRITES); _IO_mask_flags (fp, read_or_write, _IO_NO_READS|_IO_NO_WRITES);
return fp; return fp;
...@@ -141,28 +148,45 @@ DEFUN(_IO_proc_open, (fp, command, mode), ...@@ -141,28 +148,45 @@ DEFUN(_IO_proc_open, (fp, command, mode),
} }
_IO_FILE * _IO_FILE *
DEFUN(_IO_popen, (command, mode), _IO_popen (command, mode)
const char *command AND const char *mode) const char *command;
const char *mode;
{ {
_IO_proc_file *fpx = (_IO_proc_file*)malloc(sizeof(_IO_proc_file)); struct locked_FILE
_IO_FILE *fp = (_IO_FILE*)fpx; {
if (fp == NULL) 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; return NULL;
_IO_init(fp, 0); #ifdef _IO_MTSAFE_IO
_IO_JUMPS(fp) = &_IO_proc_jumps; new_f->fpx.file.file._lock = &new_f->lock;
_IO_file_init(fp); #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 #if !_IO_UNIFIED_JUMPTABLES
((struct _IO_FILE_plus*)fp)->vtable = NULL; ((struct _IO_FILE_plus *) fp)->vtable = NULL;
#endif #endif
if (_IO_proc_open (fp, command, mode) != NULL) if (_IO_proc_open (fp, command, mode) != NULL)
return fp; return fp;
free (fpx); free (new_f);
return NULL; return NULL;
} }
#ifdef strong_alias
strong_alias (_IO_popen, popen);
#endif
int int
DEFUN(_IO_proc_close, (fp), _IO_proc_close (fp)
_IO_FILE *fp) _IO_FILE *fp;
{ {
/* This is not name-space clean. FIXME! */ /* This is not name-space clean. FIXME! */
#if _IO_HAVE_SYS_WAIT #if _IO_HAVE_SYS_WAIT
...@@ -170,11 +194,11 @@ DEFUN(_IO_proc_close, (fp), ...@@ -170,11 +194,11 @@ DEFUN(_IO_proc_close, (fp),
_IO_proc_file **ptr = &proc_file_chain; _IO_proc_file **ptr = &proc_file_chain;
_IO_pid_t wait_pid; _IO_pid_t wait_pid;
int status = -1; int status = -1;
/* Unlink from proc_file_chain. */ /* Unlink from proc_file_chain. */
for ( ; *ptr != NULL; ptr = &(*ptr)->next) for ( ; *ptr != NULL; ptr = &(*ptr)->next)
{ {
if (*ptr == (_IO_proc_file*)fp) if (*ptr == (_IO_proc_file *) fp)
{ {
*ptr = (*ptr)->next; *ptr = (*ptr)->next;
status = 0; status = 0;
...@@ -182,7 +206,7 @@ DEFUN(_IO_proc_close, (fp), ...@@ -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; return -1;
/* POSIX.2 Rationale: "Some historical implementations either block /* POSIX.2 Rationale: "Some historical implementations either block
or ignore the signals SIGINT, SIGQUIT, and SIGHUP while waiting or ignore the signals SIGINT, SIGQUIT, and SIGHUP while waiting
...@@ -190,8 +214,9 @@ DEFUN(_IO_proc_close, (fp), ...@@ -190,8 +214,9 @@ DEFUN(_IO_proc_close, (fp),
described in POSIX.2, such implementations are not conforming." */ described in POSIX.2, such implementations are not conforming." */
do do
{ {
wait_pid = _IO_waitpid (((_IO_proc_file*)fp)->pid, &wstatus, 0); wait_pid = _IO_waitpid (((_IO_proc_file *) fp)->pid, &wstatus, 0);
} while (wait_pid == -1 && errno == EINTR); }
while (wait_pid == -1 && errno == EINTR);
if (wait_pid == -1) if (wait_pid == -1)
return -1; return -1;
return wstatus; return wstatus;
......
/* 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
/* /* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include <string.h> #include <string.h>
int int
DEFUN(_IO_puts, (str), _IO_puts (str)
const char *str) const char *str;
{ {
_IO_size_t len = strlen(str); int result;
if (_IO_sputn(_IO_stdout, str, len) != len) _IO_size_t len = strlen (str);
return EOF; _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
if (_IO_putc('\n', _IO_stdout) == EOF) _IO_stdout);
return EOF; _IO_flockfile (_IO_stdout);
return len+1; 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
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libioP.h> #include <libioP.h>
_IO_pos_t _IO_pos_t
DEFUN(_IO_seekoff, (fp, offset, dir, mode), _IO_seekoff (fp, offset, dir, mode)
_IO_FILE* fp AND _IO_off_t offset AND int dir AND int 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 /* If we have a backup buffer, get rid of it, since the __seekoff
callback may not know to do the right thing about it. callback may not know to do the right thing about it.
......
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libioP.h> #include <libioP.h>
_IO_pos_t _IO_pos_t
DEFUN(_IO_seekpos, (fp, pos, mode), _IO_seekpos (fp, pos, mode)
_IO_FILE* fp AND _IO_pos_t pos AND int mode) _IO_FILE *fp;
_IO_pos_t pos;
int mode;
{ {
/* If we have a backup buffer, get rid of it, since the __seekoff /* If we have a backup buffer, get rid of it, since the __seekoff
callback may not know to do the right thing about it. callback may not know to do the right thing about it.
......
/* /* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
void void
DEFUN(_IO_setbuffer, (fp, buf, size), _IO_setbuffer (fp, buf, size)
_IO_FILE *fp AND char *buf AND _IO_size_t 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; fp->_flags &= ~_IO_LINE_BUF;
if (!buf) if (!buf)
size = 0; size = 0;
(void) _IO_SETBUF (fp, buf, size); (void) _IO_SETBUF (fp, buf, size);
_IO_cleanup_region_end (1);
} }
#ifdef weak_alias
weak_alias (_IO_setbuffer, setbuffer)
#endif
/* /* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
...@@ -29,10 +30,16 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -29,10 +30,16 @@ the executable file might be covered by the GNU General Public License. */
#define _IONBF 2 /* No buffering. */ #define _IONBF 2 /* No buffering. */
int int
DEFUN(_IO_setvbuf, (fp, buf, mode, size), _IO_setvbuf (fp, buf, mode, size)
_IO_FILE* fp AND char* buf AND int mode AND _IO_size_t 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) switch (mode)
{ {
case _IOFBF: case _IOFBF:
...@@ -55,24 +62,39 @@ DEFUN(_IO_setvbuf, (fp, buf, mode, size), ...@@ -55,24 +62,39 @@ DEFUN(_IO_setvbuf, (fp, buf, mode, size),
A possibly cleaner alternative would be to add an A possibly cleaner alternative would be to add an
extra flag, but then flags are a finite resource. */ extra flag, but then flags are a finite resource. */
if (_IO_DOALLOCATE (fp) < 0) if (_IO_DOALLOCATE (fp) < 0)
return EOF; {
result = EOF;
goto unlock_return;
}
fp->_IO_file_flags &= ~_IO_LINE_BUF; fp->_IO_file_flags &= ~_IO_LINE_BUF;
} }
return 0; result = 0;
goto unlock_return;
} }
break; break;
case _IOLBF: case _IOLBF:
fp->_IO_file_flags &= ~_IO_UNBUFFERED; fp->_IO_file_flags &= ~_IO_UNBUFFERED;
fp->_IO_file_flags |= _IO_LINE_BUF; fp->_IO_file_flags |= _IO_LINE_BUF;
if (buf == NULL) if (buf == NULL)
return 0; {
result = 0;
goto unlock_return;
}
break; break;
case _IONBF: case _IONBF:
buf = NULL; buf = NULL;
size = 0; size = 0;
break; break;
default: 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
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
...@@ -31,17 +32,19 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -31,17 +32,19 @@ the executable file might be covered by the GNU General Public License. */
#endif #endif
int int
_IO_sprintf
#ifdef __STDC__ #ifdef __STDC__
(char *string, const char* format, ...) _IO_sprintf (char *string, const char* format, ...)
#else #else
(string, format, va_alist) char *string; char *format; va_dcl _IO_sprintf (string, format, va_alist)
char *string;
char *format;
va_dcl
#endif #endif
{ {
int ret; int ret;
va_list args; va_list args;
_IO_va_start(args, format); _IO_va_start (args, format);
ret = _IO_vsprintf(string, format, args); ret = _IO_vsprintf (string, format, args);
va_end(args); va_end (args);
return ret; return ret;
} }
/* 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 Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free This file is part of the GNU IO Library. This library is free
...@@ -96,7 +96,11 @@ class ostream : virtual public ios ...@@ -96,7 +96,11 @@ class ostream : virtual public ios
#endif #endif
ostream& operator<<(double n); ostream& operator<<(double n);
ostream& operator<<(float n) { return 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); } ostream& operator<<(long double n) { return operator<<((double)n); }
#endif
ostream& operator<<(__omanip func) { return (*func)(*this); } ostream& operator<<(__omanip func) { return (*func)(*this); }
ostream& operator<<(__manip func) {(*func)(*this); return *this;} ostream& operator<<(__manip func) {(*func)(*this); return *this;}
ostream& operator<<(streambuf*); ostream& operator<<(streambuf*);
......
/* /* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
int int
DEFUN(_IO_ungetc, (c, fp), _IO_ungetc (c, fp)
int c AND _IO_FILE *fp) int c;
_IO_FILE *fp;
{ {
CHECK_FILE(fp, EOF); int result;
CHECK_FILE (fp, EOF);
if (c == EOF) if (c == EOF)
return 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
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include "strfile.h" #include "strfile.h"
int int
DEFUN(_IO_vsprintf, (string, format, args), _IO_vsprintf (string, format, args)
char *string AND const char *format AND _IO_va_list args) char *string;
const char *format;
_IO_va_list args;
{ {
_IO_strfile sf; _IO_strfile sf;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
int ret; int ret;
_IO_init((_IO_FILE*)&sf, 0);
_IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps; #ifdef _IO_MTSAFE_IO
_IO_str_init_static ((_IO_FILE*)&sf, string, -1, string); sf._sbf._f._lock = &lock;
ret = _IO_vfprintf((_IO_FILE*)&sf, format, args); #endif
_IO_putc('\0', (_IO_FILE*)&sf); _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; return ret;
} }
#ifdef weak_alias
weak_alias (_IO_vsprintf, vsprintf)
#endif
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include "strfile.h" #include "strfile.h"
int int
DEFUN(_IO_vsscanf, (string, format, args), _IO_vsscanf (string, format, args)
const char *string AND const char *format AND _IO_va_list args) const char *string;
const char *format;
_IO_va_list args;
{ {
int ret;
_IO_strfile sf; _IO_strfile sf;
_IO_init((_IO_FILE*)&sf, 0); #ifdef _IO_MTSAFE_IO
_IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps; _IO_lock_t lock;
_IO_str_init_static ((_IO_FILE*)&sf, (char*)string, 0, NULL); sf._sbf._f._lock = &lock;
return _IO_vfscanf((_IO_FILE*)&sf, format, args, NULL); #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
/* /*
Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation
This file is part of the GNU IO Library. This library is free 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. */ ...@@ -153,6 +153,14 @@ the executable file might be covered by the GNU General Public License. */
struct _IO_jump_t; struct _IO_FILE; 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 {
struct _IO_marker *_next; struct _IO_marker *_next;
struct _IO_FILE *_sbuf; struct _IO_FILE *_sbuf;
...@@ -196,20 +204,22 @@ struct _IO_FILE { ...@@ -196,20 +204,22 @@ struct _IO_FILE {
char *_IO_save_end; /* Pointer to end of non-current get area. */ char *_IO_save_end; /* Pointer to end of non-current get area. */
struct _IO_marker *_markers; struct _IO_marker *_markers;
struct _IO_FILE *_chain; struct _IO_FILE *_chain;
int _fileno; int _fileno;
int _blksize; int _blksize;
_IO_off_t _offset; _IO_off_t _offset;
#define __HAVE_COLUMN /* temporary */ #define __HAVE_COLUMN /* temporary */
/* 1+column number of pbase(); 0 is unknown. */ /* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column; unsigned short _cur_column;
char _unused; char _unused;
char _shortbuf[1]; char _shortbuf[1];
/* char* _save_gptr; char* _save_egptr; */ /* char* _save_gptr; char* _save_egptr; */
_IO_lock_t *_lock;
}; };
#ifndef __cplusplus #ifndef __cplusplus
...@@ -222,6 +232,26 @@ extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_; ...@@ -222,6 +232,26 @@ extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
#define _IO_stdout ((_IO_FILE*)(&_IO_stdout_)) #define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
#define _IO_stderr ((_IO_FILE*)(&_IO_stderr_)) #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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -230,26 +260,47 @@ extern int __underflow __P((_IO_FILE*)); ...@@ -230,26 +260,47 @@ extern int __underflow __P((_IO_FILE*));
extern int __uflow __P((_IO_FILE*)); extern int __uflow __P((_IO_FILE*));
extern int __overflow __P((_IO_FILE*, int)); 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) \ ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow(_fp) \
: *(unsigned char*)(_fp)->_IO_read_ptr++) : *(unsigned char*)(_fp)->_IO_read_ptr++)
#define _IO_peekc(_fp) \ #define _IO_peekc_unlocked(_fp) \
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \ ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
&& __underflow(_fp) == EOF ? EOF \ && __underflow(_fp) == EOF ? EOF \
: *(unsigned char*)(_fp)->_IO_read_ptr) : *(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) \ (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
? __overflow(_fp, (unsigned char)(_ch)) \ ? __overflow(_fp, (unsigned char)(_ch)) \
: (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch))) : (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch)))
#define _IO_feof(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0) #define _IO_feof_unclocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define _IO_ferror(__fp) (((__fp)->_flags & _IO_ERR_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. */ /* This one is for Emacs. */
#define _IO_PENDING_OUTPUT_COUNT(_fp) \ #define _IO_PENDING_OUTPUT_COUNT(_fp) \
((_fp)->_IO_write_ptr - (_fp)->_IO_write_base) ((_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_vfscanf __P((_IO_FILE*, const char*, _IO_va_list, int*));
extern int _IO_vfprintf __P((_IO_FILE*, const char*, _IO_va_list)); 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)); extern _IO_ssize_t _IO_padn __P((_IO_FILE *, int, _IO_ssize_t));
......
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include <errno.h> #include <errno.h>
#ifndef errno #ifndef errno
extern int errno; extern int errno;
#endif #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" #include "iolibio.h"
...@@ -100,8 +106,8 @@ extern "C" { ...@@ -100,8 +106,8 @@ extern "C" {
/* The 'finish' function does any final cleaning up of an _IO_FILE object. /* 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 does not delete (free) it, but does everything else to finalize it/
It matches the streambuf::~streambuf virtual destructor. */ It matches the streambuf::~streambuf virtual destructor. */
typedef void (*_IO_finish_t) __P((_IO_FILE*)); /* finalize */ typedef void (*_IO_finish_t) __P((_IO_FILE*, int)); /* finalize */
#define _IO_FINISH(FP) JUMP0(__finish, FP) #define _IO_FINISH(FP) JUMP1(__finish, FP, 0)
/* The 'overflow' hook flushes the buffer. /* The 'overflow' hook flushes the buffer.
The second argument is a character, or EOF. The second argument is a character, or EOF.
...@@ -266,6 +272,9 @@ struct _IO_FILE_plus { ...@@ -266,6 +272,9 @@ struct _IO_FILE_plus {
/* Generic functions */ /* 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 int _IO_switch_to_get_mode __P((_IO_FILE*));
extern void _IO_init __P((_IO_FILE*, int)); extern void _IO_init __P((_IO_FILE*, int));
extern int _IO_sputbackc __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)); ...@@ -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_underflow __P((_IO_FILE*));
extern int _IO_default_uflow __P((_IO_FILE*)); extern int _IO_default_uflow __P((_IO_FILE*));
extern int _IO_default_doallocate __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 int _IO_default_pbackfail __P((_IO_FILE*, int));
extern _IO_FILE* _IO_default_setbuf __P((_IO_FILE *, char*, _IO_ssize_t)); 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)); 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)); ...@@ -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_sync __P((_IO_FILE*));
extern int _IO_file_close_it __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 _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. */ /* Other file functions. */
extern _IO_FILE* _IO_file_attach __P((_IO_FILE *, int)); extern _IO_FILE* _IO_file_attach __P((_IO_FILE *, int));
...@@ -361,12 +370,20 @@ extern int _IO_str_underflow __P((_IO_FILE*)); ...@@ -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_overflow __P((_IO_FILE *, int));
extern int _IO_str_pbackfail __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 _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 */ /* Other strfile functions */
extern void _IO_str_init_static __P((_IO_FILE *, char*, int, char*)); 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 void _IO_str_init_readonly __P((_IO_FILE *, const char*, int));
extern _IO_ssize_t _IO_str_count __P ((_IO_FILE*)); 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_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 _IO_ssize_t _IO_getdelim __P((char**, _IO_size_t*, int, _IO_FILE*));
extern double _IO_strtod __P((const char *, char **)); extern double _IO_strtod __P((const char *, char **));
...@@ -394,8 +411,52 @@ extern void (*_IO_cleanup_registration_needed) __P ((void)); ...@@ -394,8 +411,52 @@ extern void (*_IO_cleanup_registration_needed) __P ((void));
#endif #endif
#endif #endif
#define FREE_BUF(_B) free(_B) #if _G_HAVE_MMAP
#define ALLOC_BUF(_S) (char*)malloc(_S)
#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 #ifndef OS_FSTAT
#define OS_FSTAT fstat #define OS_FSTAT fstat
...@@ -433,10 +494,18 @@ extern int _IO_fstat __P((int, struct stat *)); ...@@ -433,10 +494,18 @@ extern int _IO_fstat __P((int, struct stat *));
} }
#endif #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! */ /* check following! */
#define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \ #define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \ { _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, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD}
#endif
/* VTABLE_LABEL defines NAME as of the CLASS class. /* VTABLE_LABEL defines NAME as of the CLASS class.
CNLENGTH is strlen(#CLASS). */ CNLENGTH is strlen(#CLASS). */
...@@ -480,7 +549,7 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf; ...@@ -480,7 +549,7 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
#endif #endif
#ifdef EINVAL #ifdef EINVAL
#define MAYBE_SET_EINVAL errno = EINVAL #define MAYBE_SET_EINVAL __set_errno (EINVAL)
#else #else
#define MAYBE_SET_EINVAL /* nothing */ #define MAYBE_SET_EINVAL /* nothing */
#endif #endif
...@@ -490,7 +559,7 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf; ...@@ -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; } \ if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
else { COERCE_FILE(FILE); \ else { COERCE_FILE(FILE); \
if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \ if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
{ errno = EINVAL; return RET; }} { MAYBE_SET_EINVAL; return RET; }}
#else #else
#define CHECK_FILE(FILE,RET) \ #define CHECK_FILE(FILE,RET) \
COERCE_FILE(FILE) COERCE_FILE(FILE)
......
...@@ -137,7 +137,7 @@ general_parsebuf::general_parsebuf(streambuf *buf, int delete_arg_buf) ...@@ -137,7 +137,7 @@ general_parsebuf::general_parsebuf(streambuf *buf, int delete_arg_buf)
delete_buf = delete_arg_buf; delete_buf = delete_arg_buf;
sbuf = buf; sbuf = buf;
int buf_size = 128; int buf_size = 128;
char* buffer = ALLOC_BUF(buf_size); char* buffer = (char*)malloc(buf_size);
setb(buffer, buffer+buf_size, 1); setb(buffer, buffer+buf_size, 1);
// setg(buffer, buffer, buffer); // setg(buffer, buffer, buffer);
} }
......
/* 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;
}
/* /* Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
Copyright (C) 1993, 1994 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ 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 /* 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. */ ...@@ -31,10 +32,16 @@ the executable file might be covered by the GNU General Public License. */
#include "libioP.h" #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) \ #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
struct _IO_FILE_plus NAME \ struct _IO_FILE_plus NAME \
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps} = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}
#endif
DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES); DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS); DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS);
......
/* this will be used later*/
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> 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 * stdio.h (TMP_MAX): Wrap it with #ifndef for now, since it can
......
...@@ -7,9 +7,9 @@ srcdir = . ...@@ -7,9 +7,9 @@ srcdir = .
STDIO_RENAMED_OBJECTS = ... filled in by configure ... STDIO_RENAMED_OBJECTS = ... filled in by configure ...
# These are the files that a libc would want. # These are the files that a libc would want.
STDIO_OBJECTS = $(STDIO_RENAMED_OBJECTS) \ STDIO_OBJECTS = $(STDIO_RENAMED_OBJECTS) \
clearerr.o fdopen.o feof.o ferror.o fgetc.o fileno.o \ clearerr.o fdopen.o fgetc.o fileno.o \
fputc.o freopen.o fseek.o getc.o getchar.o getline.o getw.o \ fputc.o freopen.o fseek.o getchar.o getline.o getw.o \
popen.o putc.o putchar.o putw.o rewind.o \ popen.o putchar.o putw.o rewind.o \
setbuf.o setfileno.o setlinebuf.o snprintf.o \ setbuf.o setfileno.o setlinebuf.o snprintf.o \
vfprintf.o vfscanf.o vprintf.o vscanf.o vsnprintf.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 ...@@ -18,6 +18,18 @@ CINCLUDES = -I. -I$(srcdir) -I.. -I$(srcdir)/.. -D__USE_GNU
nothing: 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) stdio.list: stamp-picdir $(STDIO_OBJECTS)
@echo "$(STDIO_OBJECTS)" >stdio.list @echo "$(STDIO_OBJECTS)" >stdio.list
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
void void
clearerr(fp) clearerr (fp)
FILE* fp; FILE *fp;
{ {
CHECK_FILE(fp, /*nothing*/); CHECK_FILE (fp, /*nothing*/);
_IO_clearerr(fp); _IO_flockfile (fp);
_IO_clearerr (fp);
_IO_funlockfile (fp);
} }
/* 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);
}
/* 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);
}
/* 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);
}
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
int int
fgetc(fp) fgetc (fp)
FILE *fp; FILE *fp;
{ {
CHECK_FILE(fp, EOF); int result;
return _IO_getc(fp); 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;
} }
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
int int
fileno(fp) fileno (fp)
_IO_FILE* fp; _IO_FILE* fp;
{ {
CHECK_FILE(fp, EOF); CHECK_FILE (fp, EOF);
if (!(fp->_flags & _IO_IS_FILEBUF)) if (!(fp->_flags & _IO_IS_FILEBUF))
return EOF; 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
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
int int
fputc(c, fp) fputc (c, fp)
int c; int c;
FILE *fp; _IO_FILE *fp;
{ {
CHECK_FILE(fp, EOF); int result;
return _IO_putc(c, fp); 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;
} }
/* 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);
}
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
FILE* FILE*
freopen(filename, mode, fp) freopen (filename, mode, fp)
const char* filename; const char* filename;
const char* mode; const char* mode;
FILE* fp; FILE* fp;
{ {
CHECK_FILE(fp, NULL); FILE *result;
CHECK_FILE (fp, NULL);
if (!(fp->_flags & _IO_IS_FILEBUF)) if (!(fp->_flags & _IO_IS_FILEBUF))
return NULL; 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;
} }
#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 "libioP.h"
#include "stdio.h"
int int
fseek(fp, offset, whence) fseek (fp, offset, whence)
_IO_FILE* fp; _IO_FILE* fp;
long int offset; long int offset;
int whence; int whence;
{ {
CHECK_FILE(fp, -1); int result;
return _IO_fseek(fp, offset, whence); 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;
} }
/* 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);
}
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
...@@ -6,5 +31,10 @@ ...@@ -6,5 +31,10 @@
int int
getchar () 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;
} }
/* 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);
}
/* 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);
}
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
#undef putchar #undef putchar
int int
putchar(c) putchar (c)
int 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;
} }
/* 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);
}
#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 "libioP.h"
#include "stdio.h"
void void
rewind(fp) rewind (fp)
_IO_FILE* fp; _IO_FILE *fp;
{ {
CHECK_FILE(fp, ); CHECK_FILE (fp, );
_IO_rewind(fp); _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
_IO_rewind (fp);
_IO_cleanup_region_end (1);
} }
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
void void
setbuf (fp, buf) setbuf (fp, buf)
FILE *fp; char *buf; _IO_FILE *fp;
char *buf;
{ {
_IO_setbuffer(fp, buf, _IO_BUFSIZ); _IO_setbuffer (fp, buf, _IO_BUFSIZ);
} }
/* 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 "libioP.h"
#include "stdio.h" #include "stdio.h"
...@@ -5,7 +30,7 @@ ...@@ -5,7 +30,7 @@
void void
setlinebuf (stream) setlinebuf (stream)
FILE *stream; _IO_FILE *stream;
{ {
_IO_setvbuf(stream, NULL, 1, 0); _IO_setvbuf (stream, NULL, 1, 0);
} }
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include "stdio.h" #include "stdio.h"
#undef vscanf
int int
vscanf(format, args) _IO_vscanf (format, args)
const char *format; const char *format;
_IO_va_list args; _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
/* /* Copyright (C) 1994, 1997 Free Software Foundation, Inc.
Copyright (C) 1994 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h" #include "libioP.h"
#include "strfile.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 int
vsnprintf (string, maxlen, format, args) _IO_vsnprintf (string, maxlen, format, args)
char *string; char *string;
_IO_size_t maxlen; _IO_size_t maxlen;
const char *format; const char *format;
_IO_va_list args; _IO_va_list args;
{ {
_IO_strfile sf; _IO_strnfile sf;
int ret; int ret;
_IO_init((_IO_FILE*)&sf, 0); #ifdef _IO_MTSAFE_IO
_IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps; _IO_lock_t lock;
_IO_str_init_static ((_IO_FILE*)&sf, string, maxlen - 1, string); sf.f._sbf._f._lock = &lock;
ret = _IO_vfprintf((_IO_FILE*)&sf, format, args); #endif
*((_IO_FILE*)&sf)->_IO_write_ptr = '\0';
/* 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; return ret;
} }
#ifdef weak_alias
weak_alias (_IO_vsnprintf, __vsnprintf)
weak_alias (_IO_vsnprintf, vsnprintf)
#endif
...@@ -213,7 +213,7 @@ streambuf::streambuf(int flags) ...@@ -213,7 +213,7 @@ streambuf::streambuf(int flags)
#endif #endif
} }
streambuf::~streambuf() { _IO_default_finish(this); } streambuf::~streambuf() { _IO_default_finish(this,0); }
streampos streampos
streambuf::seekoff(streamoff, _seek_dir, int /*=ios::in|ios::out*/) streambuf::seekoff(streamoff, _seek_dir, int /*=ios::in|ios::out*/)
......
...@@ -138,7 +138,7 @@ class ios : public _ios_fields { ...@@ -138,7 +138,7 @@ class ios : public _ios_fields {
bin = _IOS_BIN, // Deprecated - ANSI uses ios::binary. bin = _IOS_BIN, // Deprecated - ANSI uses ios::binary.
binary = _IOS_BIN }; binary = _IOS_BIN };
enum seek_dir { beg, cur, end}; 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(). // NOTE: If adding flags here, before to update ios::bitalloc().
enum { skipws=_IO_SKIPWS, enum { skipws=_IO_SKIPWS,
left=_IO_LEFT, right=_IO_RIGHT, internal=_IO_INTERNAL, left=_IO_LEFT, right=_IO_RIGHT, internal=_IO_INTERNAL,
......
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, but
This library is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to
along with this library; see the file COPYING. If not, write to the Free the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MA 02111-1307, USA.
As a special exception, if you link this library with files As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libio.h> #include <libio.h>
#ifdef TODO #ifdef TODO
Merge into libio.h ? Merge into libio.h ?
#endif #endif
typedef void *(*_IO_alloc_type) __P((_IO_size_t)); typedef void *(*_IO_alloc_type) __P ((_IO_size_t));
typedef void (*_IO_free_type) __P((void*)); typedef void (*_IO_free_type) __P ((void*));
struct _IO_str_fields struct _IO_str_fields
{ {
......
/* /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free This library is free software; you can redistribute it and/or
software; you can redistribute it and/or modify it under the modify it under the terms of the GNU General Public License as
terms of the GNU General Public License as published by the published by the Free Software Foundation; either version 2, or (at
Free Software Foundation; either version 2, or (at your option) your option) any later version.
any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License 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 along with this library; see the file COPYING. If not, write to
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause compiled with a GNU compiler to produce an executable, this does
the resulting executable to be covered by the GNU General Public License. not cause the resulting executable to be covered by the GNU General
This exception does not however invalidate any other reasons why Public License. This exception does not however invalidate any
the executable file might be covered by the GNU General Public License. */ other reasons why the executable file might be covered by the GNU
General Public License. */
#include "strfile.h" #include "strfile.h"
#include "libioP.h" #include "libioP.h"
...@@ -28,7 +29,7 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -28,7 +29,7 @@ the executable file might be covered by the GNU General Public License. */
#if 0 #if 0
/* The following definitions are for exposition only. /* 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. */ to the implementation. */
/* allocated: set when a dynamic array object has been allocated, and /* 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. */ ...@@ -59,16 +60,19 @@ the executable file might be covered by the GNU General Public License. */
#endif #endif
void void
DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), _IO_str_init_static (fp, ptr, size, pstart)
_IO_FILE *fp AND char *ptr AND int size AND char *pstart) _IO_FILE *fp;
char *ptr;
int size;
char *pstart;
{ {
if (size == 0) if (size == 0)
size = strlen(ptr); size = strlen (ptr);
else if (size < 0) else if (size < 0)
{ {
/* If size is negative 'the characters are assumed to /* If size is negative 'the characters are assumed to
continue indefinitely.' This is kind of messy ... */ continue indefinitely.' This is kind of messy ... */
_G_int32_t s; int s;
size = 512; size = 512;
/* Try increasing powers of 2, as long as we don't wrap around. */ /* Try increasing powers of 2, as long as we don't wrap around. */
for (; s = 2*size, s > 0 && ptr + s > ptr && s < 0x4000000L; ) for (; s = 2*size, s > 0 && ptr + s > ptr && s < 0x4000000L; )
...@@ -80,7 +84,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), ...@@ -80,7 +84,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
size += s; size += s;
} }
} }
_IO_setb(fp, ptr, ptr+size, 0); _IO_setb (fp, ptr, ptr + size, 0);
fp->_IO_write_base = ptr; fp->_IO_write_base = ptr;
fp->_IO_read_base = ptr; fp->_IO_read_base = ptr;
...@@ -88,7 +92,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), ...@@ -88,7 +92,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
if (pstart) if (pstart)
{ {
fp->_IO_write_ptr = pstart; fp->_IO_write_ptr = pstart;
fp->_IO_write_end = ptr+size; fp->_IO_write_end = ptr + size;
fp->_IO_read_end = pstart; fp->_IO_read_end = pstart;
} }
else else
...@@ -98,20 +102,23 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart), ...@@ -98,20 +102,23 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
fp->_IO_read_end = ptr+size; fp->_IO_read_end = ptr+size;
} }
/* A null _allocate_buffer function flags the strfile as being static. */ /* 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 void
DEFUN(_IO_str_init_readonly, (fp, ptr, size), _IO_str_init_readonly (fp, ptr, size)
_IO_FILE *fp AND const char *ptr AND int 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; fp->_IO_file_flags |= _IO_NO_WRITES;
} }
int int
DEFUN(_IO_str_overflow, (fp, c), _IO_str_overflow (fp, c)
register _IO_FILE* fp AND int c) _IO_FILE *fp;
int c;
{ {
int flush_only = c == EOF; int flush_only = c == EOF;
_IO_size_t pos; _IO_size_t pos;
...@@ -124,7 +131,7 @@ DEFUN(_IO_str_overflow, (fp, c), ...@@ -124,7 +131,7 @@ DEFUN(_IO_str_overflow, (fp, c),
fp->_IO_read_ptr = fp->_IO_read_end; fp->_IO_read_ptr = fp->_IO_read_end;
} }
pos = fp->_IO_write_ptr - fp->_IO_write_base; 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 */ if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */
return EOF; return EOF;
...@@ -132,9 +139,9 @@ DEFUN(_IO_str_overflow, (fp, c), ...@@ -132,9 +139,9 @@ DEFUN(_IO_str_overflow, (fp, c),
{ {
char *new_buf; char *new_buf;
char *old_buf = fp->_IO_buf_base; 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 new_buf
= (char*)(*((_IO_strfile*)fp)->_s._allocate_buffer)(new_size); = (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size);
if (new_buf == NULL) if (new_buf == NULL)
{ {
/* __ferror(fp) = 1; */ /* __ferror(fp) = 1; */
...@@ -142,16 +149,16 @@ DEFUN(_IO_str_overflow, (fp, c), ...@@ -142,16 +149,16 @@ DEFUN(_IO_str_overflow, (fp, c),
} }
if (fp->_IO_buf_base) if (fp->_IO_buf_base)
{ {
memcpy(new_buf, old_buf, _IO_blen(fp)); memcpy (new_buf, old_buf, _IO_blen (fp));
(*((_IO_strfile*)fp)->_s._free_buffer)(fp->_IO_buf_base); (*((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base);
/* Make sure _IO_setb won't try to delete _IO_buf_base. */ /* Make sure _IO_setb won't try to delete _IO_buf_base. */
fp->_IO_buf_base = NULL; fp->_IO_buf_base = NULL;
} }
#if 0 #if 0
if (lenp == &LEN(fp)) /* use '\0'-filling */ if (lenp == &LEN(fp)) /* use '\0'-filling */
memset(new_buf + pos, 0, blen() - pos); memset (new_buf + pos, 0, blen() - pos);
#endif #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_base = new_buf + (fp->_IO_read_base - old_buf);
fp->_IO_read_ptr = new_buf + (fp->_IO_read_ptr - 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); fp->_IO_read_end = new_buf + (fp->_IO_read_end - old_buf);
...@@ -170,8 +177,8 @@ DEFUN(_IO_str_overflow, (fp, c), ...@@ -170,8 +177,8 @@ DEFUN(_IO_str_overflow, (fp, c),
} }
int int
DEFUN(_IO_str_underflow, (fp), _IO_str_underflow (fp)
register _IO_FILE* fp) _IO_FILE *fp;
{ {
if (fp->_IO_write_ptr > fp->_IO_read_end) if (fp->_IO_write_ptr > fp->_IO_read_end)
fp->_IO_read_end = fp->_IO_write_ptr; fp->_IO_read_end = fp->_IO_write_ptr;
...@@ -190,19 +197,22 @@ DEFUN(_IO_str_underflow, (fp), ...@@ -190,19 +197,22 @@ DEFUN(_IO_str_underflow, (fp),
/* The size of the valid part of the buffer. */ /* The size of the valid part of the buffer. */
_IO_ssize_t _IO_ssize_t
DEFUN(_IO_str_count, (fp), _IO_str_count (fp)
register _IO_FILE *fp) _IO_FILE *fp;
{ {
return (fp->_IO_write_ptr > fp->_IO_read_end ? fp->_IO_write_ptr return ((fp->_IO_write_ptr > fp->_IO_read_end
: fp->_IO_read_end) ? fp->_IO_write_ptr : fp->_IO_read_end)
- fp->_IO_read_base; - fp->_IO_read_base);
} }
_IO_pos_t _IO_pos_t
DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), _IO_str_seekoff (fp, offset, dir, mode)
register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int 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; _IO_pos_t new_pos = EOF;
/* Move the get pointer, if requested. */ /* Move the get pointer, if requested. */
...@@ -219,7 +229,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), ...@@ -219,7 +229,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
default: /* case _IO_seek_set: */ default: /* case _IO_seek_set: */
break; break;
} }
if (offset < 0 || (_IO_size_t)offset > cur_size) if (offset < 0 || (_IO_ssize_t) offset > cur_size)
return EOF; return EOF;
fp->_IO_read_ptr = fp->_IO_read_base + offset; fp->_IO_read_ptr = fp->_IO_read_base + offset;
fp->_IO_read_end = fp->_IO_read_base + cur_size; fp->_IO_read_end = fp->_IO_read_base + cur_size;
...@@ -240,7 +250,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), ...@@ -240,7 +250,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
default: /* case _IO_seek_set: */ default: /* case _IO_seek_set: */
break; break;
} }
if (offset < 0 || (_IO_size_t)offset > cur_size) if (offset < 0 || (_IO_ssize_t) offset > cur_size)
return EOF; return EOF;
fp->_IO_write_ptr = fp->_IO_write_base + offset; fp->_IO_write_ptr = fp->_IO_write_base + offset;
new_pos = offset; new_pos = offset;
...@@ -249,26 +259,29 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode), ...@@ -249,26 +259,29 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
} }
int int
DEFUN(_IO_str_pbackfail, (fp, c), _IO_str_pbackfail (fp, c)
register _IO_FILE *fp AND int c) _IO_FILE *fp;
int c;
{ {
if ((fp->_flags & _IO_NO_WRITES) && c != EOF) if ((fp->_flags & _IO_NO_WRITES) && c != EOF)
return EOF; return EOF;
return _IO_default_pbackfail(fp, c); return _IO_default_pbackfail (fp, c);
} }
void void
DEFUN (_IO_str_finish, (fp), _IO_str_finish (fp, dummy)
register _IO_FILE* fp) _IO_FILE *fp;
int dummy;
{ {
if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF)) 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; 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_DUMMY,
JUMP_INIT(finish, _IO_str_finish), JUMP_INIT(finish, _IO_str_finish),
JUMP_INIT(overflow, _IO_str_overflow), JUMP_INIT(overflow, _IO_str_overflow),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment