Insert libio rewrite and its various changes from devo.

From-SVN: r15129
This commit is contained in:
Brendan Kehoe 1997-09-06 03:44:38 -04:00
parent 1496c1bb0b
commit dbfcb4beac
72 changed files with 3266 additions and 1470 deletions

View File

@ -1,7 +1,180 @@
Fri Sep 5 09:58:43 1997 Brendan Kehoe <brendan@lisa.cygnus.com>
* Makefile.in (iostream.list): Instead of adding stdio.list, add
STDIO_WRAP_OBJECTS.
(iostream.list): Lose dependency on stmp-stdio, not necessary for
our stuff. The stdio stuff is present here just for uniformity
with glibc.
Thu Sep 4 17:26:22 1997 Brendan Kehoe <brendan@lisa.cygnus.com>
* parsestream.cc (general_parsebuf): Cast return of malloc to char*.
1997-09-04 16:11 Ulrich Drepper <drepper@cygnus.com>
Change compared to version initially intended to in:
* strops.c (_IO_str_count): Still use _IO_write_ptr, not
_IO_write_end, for now.
* iofeof.c, ioferror.c, iofflush_u.c, iogetc.c, ioputc.c, peekc.c,
stdio-lock.h: New files.
* include: New dir.
* include/empty.h: New header.
* filedoalloc.c: Update and reformat copyright.
Don't use DEFUN.
Use __set_errno throughout the code to support multi-threaded
programs.
Correct layout to follow the Coding Standard.
Add casts to prevent warnings.
* fileops.c: Likewise.
* genops.c: Likewise.
* iofclose.c: Likewise.
* iofdopen.c: Likewise.
* iofflush.c: Likewise.
* iofgetpos.c: Likewise.
* iofgets.c: Likewise.
* iofopen.c: Likewise.
* iofprintf.c: Likewise.
* iofputs.c: Likewise.
* iofread.c: Likewise.
* iofsetpos.c: Likewise.
* ioftell.c: Likewise.
* iofwrite.c: Likewise.
* iogetdelim.c: Likewise.
* iogetline.c: Likewise.
* iogets.c: Likewise.
* iopadn.c: Likewise.
* iopopen.c: Likewise.
* ioputs.c: Likewise.
* ioseekoff.c: Likewise.
* iosetbuffer.c: Likewise.
* iosetvbuf.c: Likewise.
* iosprintf.c: Likewise.
* ioungetc.c: Likewise.
* iovsprintf.c: Likewise.
* iovsscanf.c: Likewise.
* libio.h: Likewise.
* libioP.h: Likewise.
* stdfiles.c: Likewise.
* strfile.h: Likewise.
* strops.c: Likewise.
* Makefile.in (IO_OBJECTS): Add peekc.o, iogetc.o, ioputc.o,
iofeof.o, and ioferror.o.
(iostream.list): Depend upon stmp-stdio. Add the entries
from stdio.list to iostream.list.
(stmp-stdio): New name for what was the stdio/stdio.list rule.
All it now does is cd down into stdio and build stdio.list.
* configure.in (ALL): Add libiostream.a.
* libio.h [_IO_MTSFE_IO]: Include header declaring locking code.
Otherwise define opaque _IO_lock_t.
Define _IO_cookie_file.
Rename _IO_getc to _IO_getc_unlocked, _IO_peekc to _IO_peekc_unlocked,
_IO_putc to _IO_putc_unlocked, _IO_feof to _IO_feof_unclocked, and
_IO_ferror to _IO_ferror_unlocked.
Add prototypes for _IO_getc, _IO_putc, _IO_feof, _IO_ferror,
and _IO_peekc_locked.
Add declarations for _IO_flockfile, _IO_funlockfile, and
_IO_ftrylockfile. If !_IO_MTSAFE_IO define _IO_flockfile,
_IO_funlockfile, _IO_ftrylockfile, _IO_cleanup_region_start, and
_IO_cleanup_region_end as empty macros.
* libioP.h: Change type of finish function to take an additional int
argument and change declaration of finish functions.
Add prototypes for _IO_seekoff and _IO_seekpos.
If _G_HAVE_MMAP is defined use stream buffers allocated with mmap.
Redefine FREE_BUF and ALLOC_BUF macros to help in both situations.
(FILEBUF_LITERAL): If we compile for a thread-safe library also
initialize lock member.
* filedoalloc.c: Take care for systems already defining _POSIX_SOURCE.
Keep name space clean on systems which require this.
(_IO_file_doallocate): Adopt ALLOC_BUF call for changed semantic.
* fileops.c: Keep name space clean on systems which require this.
(_IO_file_attach): Don't fail if seek failed because it's used on a
pipe.
(_IO_file_underflow): Update buffer pointers before calling `read'
since the `read' might not return anymore.
(_IO_file_overflow): If stream allows no writes set error flag.
(_IO_seekoff): Make sure that after flushing the file pointer in
the underlying file is exact.
(_IO_file_read): Don't restart `read' syscall if it return EINTR.
This violates POSIX.
(_IO_file_write): Likewise for `write'.
(_IO_cleanup): Install as exit handler in glibc.
* genops.c (_IO_setb): Correctly use FREE_BUF.
(_IO_default_doallocate): Correctly use ALLOC_BUF.
(_IO_init): Initialize lock in stream structure.
(_IO_default_finish): Destroy lock.
(_IO_get_column): Don't compile since it's not needed.
(_IO_nobackup_default): Likewise.
* iopopen.c: Take care for systems already defining _POSIX_SOURCE.
Correct _IO_fork and _IO_dup2 prototypes.
* iofclose.c: Acquire lock before starting the work.
* iofflush.c: Likewise.
* iofgetpos.c: Likewise.
* iofgets.c: Likewise.
* iofputs.c: Likewise.
* iofread.c: Likewise.
* iofsetpos.c: Likewise.
* ioftell.c: Likewise.
* iofwrite.c: Likewise.
* iogetdelim.c: Likewise.
* iogets.c: Likewise.
* ioputs.c: Likewise.
* iosetbuffer.c: Likewise.
* iosetvbuf.c: Likewise.
* ioungetc.c: Likewise.
* iofdopen.c: Create and initialize lock for new stream.
* iofopen.c: Likewise.
* iopopen.c (_IO_popen): Likewise.
* iovsprintf.c: Likewise.
* iovsscanf.c: Likewise.
* genops.c: Make weak aliases for various functions.
* iofclose.c: Likewise.
* iofdopen.c: Likewise.
* iofflush.c: Likewise.
* iofgetpos.c: Likewise.
* iofgets.c: Likewise.
* iofopen.c: Likewise.
* iofputs.c: Likewise.
* iofread.c: Likewise.
* iofsetpos.c: Likewise.
* ioftell.c: Likewise.
* iofwrite.c: Likewise.
* iogetdelim.c: Likewise.
* iogets.c: Likewise.
* ioputs.c: Likewise.
* iosetbuffer.c: Likewise.
* iosetvbuf.c: Likewise.
* ioungetc.c: Likewise.
* iovsprintf.c: Likewise.
* iovsscanf.c: Likewise.
* iofflush_u.c: New file. fflush_unlocked implementation.
* iostream.h [_G_HAVE_LONG_DOUBLE_IO]: Declare real long double
output operator.
* peekc.c: New file. Implement _IO_peekc_locked function.
* stdfiles.c: If we compile for a thread-safe library also define
lock variable.
Tue Aug 26 12:24:01 1997 H.J. Lu (hjl@gnu.ai.mit.edu)
* testsuite/Makefile.in (check): Don't depend on site.exp.
(just-check): Depend on site.exp.
* testsuite/Makefile.in (check): Don't depend on site.exp.
(just-check): Depend on site.exp.
Wed Aug 20 02:01:34 1997 Jason Merrill <jason@yorick.cygnus.com>

View File

@ -29,7 +29,8 @@ IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \
iofgetpos.o iofread.o iofscanf.o \
iofsetpos.o iogetdelim.o iogetline.o \
ioprintf.o ioseekoff.o ioseekpos.o \
outfloat.o strops.o iofclose.o iopopen.o ioungetc.o
outfloat.o strops.o iofclose.o iopopen.o ioungetc.o peekc.o iogetc.o \
ioputc.o iofeof.o ioferror.o
# These emulate stdio functionality, but with a different name (_IO_ungetc
# instead of ungetc), and using _IO_FILE instead of FILE.
@ -40,7 +41,7 @@ IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \
# iofclose.o is not here, because it is needed for stdio (by pclose).
STDIO_WRAP_OBJECTS = iofdopen.o iofflush.o iofgets.o iofopen.o iofprintf.o iofputs.o iofwrite.o \
iogets.o ioperror.o ioputs.o ioscanf.o iosetbuffer.o iosetvbuf.o \
iosprintf.o iosscanf.o ioftell.o iovsprintf.o iovsscanf.o
iosprintf.o iosscanf.o ioftell.o iovsscanf.o iovsprintf.o
IOSTREAM_OBJECTS = builtinbuf.o filebuf.o fstream.o \
indstream.o ioassign.o ioextend.o iomanip.o iostream.o \
@ -82,16 +83,12 @@ tpipe: tpipe.o libio.a
iostream.list: stamp-picdir $(_G_CONFIG_H) $(LIBIOSTREAM_DEP)
@echo "$(LIBIOSTREAM_USE)"> iostream.list
@echo "$(STDIO_WRAP_OBJECTS)" >> iostream.list
stdio/stdio.list: force
stmp-stdio:
@rootme=`pwd`/ ; export rootme; cd stdio ; \
$(MAKE) $(FLAGS_TO_PASS) stdio.list
stdio.list: stdio/stdio.list
rm -f tstdio.list
sed 's,\([a-z_]*\.o\),stdio/\1,g' stdio/stdio.list > tstdio.list
mv tstdio.list stdio.list
_G_config.h: ${srcdir}/gen-params
rootme=`pwd`/ ; export rootme; \
CC="$(CC)"; export CC; \

View File

@ -57,7 +57,7 @@ ${moveifchange} temp.mt target-mkfrag
LIBDIR=yes
TO_TOPDIR=../
ALL='$(_G_CONFIG_H) libio.a iostream.list'
ALL='$(_G_CONFIG_H) libio.a libiostream.a iostream.list'
XCINCLUDES='-I. -I$(srcdir)'
XCXXINCLUDES='-I. -I$(srcdir)'
MOSTLYCLEAN='*.o pic stamp-picdir core iostream.list'

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
/*
* Copyright (c) 1990 The Regents of the University of California.
@ -41,7 +42,9 @@ the executable file might be covered by the GNU General Public License. */
/* Modified for GNU iostream by Per Bothner 1991, 1992. */
#define _POSIX_SOURCE
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h"
#include <sys/types.h>
#include <sys/stat.h>
@ -50,6 +53,11 @@ the executable file might be covered by the GNU General Public License. */
#include <unistd.h>
#endif
#ifdef _LIBC
# undef isatty
# define isatty(Fd) __isatty (Fd)
#endif
/*
* Allocate a file buffer, or switch to unbuffered I/O.
* Per the ANSI C standard, ALL tty devices default to line buffered.
@ -59,21 +67,23 @@ the executable file might be covered by the GNU General Public License. */
*/
int
DEFUN(_IO_file_doallocate, (fp),
register _IO_FILE *fp)
_IO_file_doallocate (fp)
_IO_FILE *fp;
{
register _IO_size_t size;
_IO_size_t size;
int couldbetty;
register char *p;
char *p;
struct stat st;
#ifndef _LIBC
/* If _IO_cleanup_registration_needed is non-zero, we should call the
function it points to. This is to make sure _IO_cleanup gets called
on exit. We call it from _IO_file_doallocate, since that is likely
to get called by any program that does buffered I/O. */
if (_IO_cleanup_registration_needed)
(*_IO_cleanup_registration_needed)();
(*_IO_cleanup_registration_needed) ();
#endif
if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0)
{
couldbetty = 0;
@ -85,18 +95,16 @@ DEFUN(_IO_file_doallocate, (fp),
}
else
{
couldbetty = S_ISCHR(st.st_mode);
couldbetty = S_ISCHR (st.st_mode);
#if _IO_HAVE_ST_BLKSIZE
size = st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize;
#else
size = _IO_BUFSIZ;
#endif
}
p = ALLOC_BUF(size);
if (p == NULL)
return EOF;
_IO_setb(fp, p, p+size, 1);
if (couldbetty && isatty(fp->_fileno))
ALLOC_BUF (p, size, EOF);
_IO_setb (fp, p, p + size, 1);
if (couldbetty && isatty (fp->_fileno))
fp->_flags |= _IO_LINE_BUF;
return 1;
}

View File

@ -1,30 +1,33 @@
/*
Copyright (C) 1993, 1995 Free Software Foundation
/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
Written by Per Bothner <bothner@cygnus.com>.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
/* written by Per Bothner (bothner@cygnus.com) */
#define _POSIX_SOURCE
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h"
#include <fcntl.h>
#include <sys/types.h>
@ -35,11 +38,16 @@ the executable file might be covered by the GNU General Public License. */
extern int errno;
#endif
#ifdef _LIBC
# define open(Name, Flags, Prot) __open ((Name), (Flags), (Prot))
#endif
/* An fstream can be in at most one of put mode, get mode, or putback mode.
Putback mode is a variant of get mode.
In a filebuf, there is only one current position, instead of two
separate get and put pointers. In get mode, the current posistion
separate get and put pointers. In get mode, the current position
is that of gptr(); in put mode that of pptr().
The position in the buffer that corresponds to the position
@ -73,14 +81,14 @@ extern int errno;
(The pointers save_gptr() and save_egptr() are the values
of gptr() and egptr() at the time putback mode was entered.)
The OS position corresponds to that of save_egptr().
LINE BUFFERED OUTPUT:
During line buffered output, _IO_write_base==base() && epptr()==base().
However, ptr() may be anywhere between base() and ebuf().
This forces a call to filebuf::overflow(int C) on every put.
If there is more space in the buffer, and C is not a '\n',
then C is inserted, and pptr() incremented.
UNBUFFERED STREAMS:
If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer.
*/
@ -90,8 +98,8 @@ extern int errno;
void
DEFUN(_IO_file_init, (fp),
register _IO_FILE *fp)
_IO_file_init (fp)
_IO_FILE *fp;
{
/* POSIX.1 allows another file handle to be used to change the position
of our file descriptor. Hence we actually don't know the actual
@ -104,11 +112,11 @@ DEFUN(_IO_file_init, (fp),
}
int
DEFUN(_IO_file_close_it, (fp),
register _IO_FILE* fp)
_IO_file_close_it (fp)
_IO_FILE *fp;
{
int write_status, close_status;
if (!_IO_file_is_open(fp))
if (!_IO_file_is_open (fp))
return EOF;
write_status = _IO_do_flush (fp);
@ -118,11 +126,11 @@ DEFUN(_IO_file_close_it, (fp),
close_status = _IO_SYSCLOSE (fp);
/* Free buffer. */
_IO_setb(fp, NULL, NULL, 0);
_IO_setg(fp, NULL, NULL, NULL);
_IO_setp(fp, NULL, NULL);
_IO_setb (fp, NULL, NULL, 0);
_IO_setg (fp, NULL, NULL, NULL);
_IO_setp (fp, NULL, NULL);
_IO_un_link(fp);
_IO_un_link (fp);
fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
fp->_fileno = EOF;
fp->_offset = _IO_pos_BAD;
@ -131,86 +139,99 @@ DEFUN(_IO_file_close_it, (fp),
}
void
DEFUN(_IO_file_finish, (fp),
register _IO_FILE* fp)
_IO_file_finish (fp, dummy)
_IO_FILE *fp;
int dummy;
{
if (_IO_file_is_open(fp))
if (_IO_file_is_open (fp))
{
_IO_do_flush (fp);
if (!(fp->_flags & _IO_DELETE_DONT_CLOSE))
_IO_SYSCLOSE (fp);
}
_IO_default_finish(fp);
_IO_default_finish (fp, 0);
}
_IO_FILE *
DEFUN(_IO_file_fopen, (fp, filename, mode),
register _IO_FILE *fp AND const char *filename AND const char *mode)
_IO_file_fopen (fp, filename, mode)
_IO_FILE *fp;
const char *filename;
const char *mode;
{
int oflags = 0, omode;
int read_write, fdesc;
int oprot = 0666;
if (_IO_file_is_open (fp))
return 0;
switch (*mode++) {
case 'r':
omode = O_RDONLY;
read_write = _IO_NO_WRITES;
break;
case 'w':
omode = O_WRONLY;
oflags = O_CREAT|O_TRUNC;
read_write = _IO_NO_READS;
break;
case 'a':
omode = O_WRONLY;
oflags = O_CREAT|O_APPEND;
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
errno = EINVAL;
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) {
omode = O_RDWR;
read_write &= _IO_IS_APPENDING;
}
fdesc = open(filename, omode|oflags, oprot);
switch (*mode++)
{
case 'r':
omode = O_RDONLY;
read_write = _IO_NO_WRITES;
break;
case 'w':
omode = O_WRONLY;
oflags = O_CREAT|O_TRUNC;
read_write = _IO_NO_READS;
break;
case 'a':
omode = O_WRONLY;
oflags = O_CREAT|O_APPEND;
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
__set_errno (EINVAL);
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
{
omode = O_RDWR;
read_write &= _IO_IS_APPENDING;
}
fdesc = open (filename, omode|oflags, oprot);
if (fdesc < 0)
return NULL;
fp->_fileno = fdesc;
_IO_mask_flags(fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
_IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
if (read_write & _IO_IS_APPENDING)
if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD)
== _IO_pos_BAD && errno != ESPIPE)
return NULL;
_IO_link_in(fp);
_IO_link_in (fp);
return fp;
}
_IO_FILE*
DEFUN(_IO_file_attach, (fp, fd),
_IO_FILE *fp AND int fd)
_IO_FILE *
_IO_file_attach (fp, fd)
_IO_FILE *fp;
int fd;
{
if (_IO_file_is_open(fp))
if (_IO_file_is_open (fp))
return NULL;
fp->_fileno = fd;
fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES);
fp->_flags |= _IO_DELETE_DONT_CLOSE;
/* Get the current position of the file. */
/* We have to do that since that may be junk. */
fp->_offset = _IO_pos_BAD;
if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD && errno != ESPIPE)
return NULL;
return fp;
}
_IO_FILE*
DEFUN(_IO_file_setbuf, (fp, p, len),
register _IO_FILE *fp AND char* p AND _IO_ssize_t len)
_IO_FILE *
_IO_file_setbuf (fp, p, len)
_IO_FILE *fp;
char *p;
_IO_ssize_t len;
{
if (_IO_default_setbuf(fp, p, len) == NULL)
return NULL;
if (_IO_default_setbuf (fp, p, len) == NULL)
return NULL;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
= fp->_IO_buf_base;
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
return fp;
}
@ -219,44 +240,42 @@ DEFUN(_IO_file_setbuf, (fp, p, len),
Then mark FP as having empty buffers. */
int
DEFUN(_IO_do_write, (fp, data, to_do),
register _IO_FILE *fp AND const char* data AND _IO_size_t to_do)
_IO_do_write (fp, data, to_do)
_IO_FILE *fp;
const char *data;
_IO_size_t to_do;
{
_IO_size_t count;
if (to_do == 0)
return 0;
else
if (fp->_flags & _IO_IS_APPENDING)
/* On a system without a proper O_APPEND implementation,
you would need to sys_seek(0, SEEK_END) here, but is
is not needed nor desirable for Unix- or Posix-like systems.
Instead, just indicate that offset (before and after) is
unpredictable. */
fp->_offset = _IO_pos_BAD;
else if (fp->_IO_read_end != fp->_IO_write_base)
{
if (fp->_flags & _IO_IS_APPENDING)
/* On a system without a proper O_APPEND implementation,
you would need to sys_seek(0, SEEK_END) here, but is
is not needed nor desirable for Unix- or Posix-like systems.
Instead, just indicate that offset (before and after) is
unpredictable. */
fp->_offset = _IO_pos_BAD;
else if (fp->_IO_read_end != fp->_IO_write_base)
{
_IO_pos_t new_pos
= _IO_SYSSEEK(fp, fp->_IO_write_base - fp->_IO_read_end, 1);
if (new_pos == _IO_pos_BAD)
return EOF;
fp->_offset = new_pos;
}
count = _IO_SYSWRITE (fp, data, to_do);
if (fp->_cur_column)
fp->_cur_column
= _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1;
_IO_pos_t new_pos
= _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1);
if (new_pos == _IO_pos_BAD)
return EOF;
fp->_offset = new_pos;
}
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
count = _IO_SYSWRITE (fp, data, to_do);
if (fp->_cur_column)
fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1;
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
fp->_IO_write_end = (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) ? fp->_IO_buf_base
: fp->_IO_buf_end;
fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
? fp->_IO_buf_base : fp->_IO_buf_end);
return count != to_do ? EOF : 0;
}
int
DEFUN(_IO_file_underflow, (fp),
register _IO_FILE *fp)
_IO_file_underflow (fp)
_IO_FILE *fp;
{
_IO_ssize_t count;
#if 0
@ -266,19 +285,31 @@ DEFUN(_IO_file_underflow, (fp),
#endif
if (fp->_flags & _IO_NO_READS)
return EOF;
{
__set_errno (EBADF);
return EOF;
}
if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char*)fp->_IO_read_ptr;
return *(unsigned char *) fp->_IO_read_ptr;
if (fp->_IO_buf_base == NULL)
_IO_doallocbuf(fp);
_IO_doallocbuf (fp);
/* Flush all line buffered files before reading. */
/* FIXME This can/should be moved to genops ?? */
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
_IO_flush_all_linebuffered();
_IO_flush_all_linebuffered ();
_IO_switch_to_get_mode(fp);
_IO_switch_to_get_mode (fp);
/* This is very tricky. We have to adjust those
pointers before we call _IO_SYSREAD () since
we may longjump () out while waiting for
input. Those pointers may be screwed up. H.J. */
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
fp->_IO_read_end = fp->_IO_buf_base;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
= fp->_IO_buf_base;
count = _IO_SYSREAD (fp, fp->_IO_buf_base,
fp->_IO_buf_end - fp->_IO_buf_base);
@ -289,30 +320,32 @@ DEFUN(_IO_file_underflow, (fp),
else
fp->_flags |= _IO_ERR_SEEN, count = 0;
}
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
fp->_IO_read_end = fp->_IO_buf_base + count;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
= fp->_IO_buf_base;
fp->_IO_read_end += count;
if (count == 0)
return EOF;
if (fp->_offset != _IO_pos_BAD)
_IO_pos_adjust(fp->_offset, count);
return *(unsigned char*)fp->_IO_read_ptr;
_IO_pos_adjust (fp->_offset, count);
return *(unsigned char *) fp->_IO_read_ptr;
}
int
DEFUN(_IO_file_overflow, (f, ch),
register _IO_FILE* f AND int ch)
_IO_file_overflow (f, ch)
_IO_FILE *f;
int ch;
{
if (f->_flags & _IO_NO_WRITES) /* SET ERROR */
return EOF;
{
f->_flags |= _IO_ERR_SEEN;
__set_errno (EBADF);
return EOF;
}
/* If currently reading or no buffer allocated. */
if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
{
/* Allocate a buffer if needed. */
if (f->_IO_write_base == 0)
{
_IO_doallocbuf(f);
_IO_doallocbuf (f);
_IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base);
}
/* Otherwise must be currently reading.
@ -334,35 +367,35 @@ DEFUN(_IO_file_overflow, (f, ch),
f->_flags |= _IO_CURRENTLY_PUTTING;
}
if (ch == EOF)
return _IO_do_flush(f);
return _IO_do_flush (f);
if (f->_IO_write_ptr == f->_IO_buf_end ) /* Buffer is really full */
if (_IO_do_flush(f) == EOF)
if (_IO_do_flush (f) == EOF)
return EOF;
*f->_IO_write_ptr++ = ch;
if ((f->_flags & _IO_UNBUFFERED)
|| ((f->_flags & _IO_LINE_BUF) && ch == '\n'))
if (_IO_do_flush(f) == EOF)
if (_IO_do_flush (f) == EOF)
return EOF;
return (unsigned char)ch;
return (unsigned char) ch;
}
int
DEFUN(_IO_file_sync, (fp),
register _IO_FILE* fp)
_IO_file_sync (fp)
_IO_FILE *fp;
{
_IO_size_t delta;
/* char* ptr = cur_ptr(); */
if (fp->_IO_write_ptr > fp->_IO_write_base)
if (_IO_do_flush(fp)) return EOF;
delta = fp->_IO_read_ptr - fp->_IO_read_end;
delta = fp->_IO_read_ptr - fp->_IO_read_end;
if (delta != 0)
{
#ifdef TODO
if (_IO_in_backup(fp))
delta -= eGptr() - Gbase();
if (_IO_in_backup (fp))
delta -= eGptr () - Gbase ();
#endif
_IO_off_t new_pos = _IO_SYSSEEK (fp, delta, 1);
if (new_pos != (_IO_off_t)EOF)
if (new_pos != (_IO_off_t) EOF)
fp->_IO_read_end = fp->_IO_read_ptr;
#ifdef ESPIPE
else if (errno == ESPIPE)
@ -378,12 +411,19 @@ DEFUN(_IO_file_sync, (fp),
}
_IO_pos_t
DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode)
_IO_file_seekoff (fp, offset, dir, mode)
_IO_FILE *fp;
_IO_off_t offset;
int dir;
int mode;
{
_IO_pos_t result;
_IO_off_t delta, new_offset;
long count;
/* POSIX.1 8.2.3.7 says that after a call the fflush() the file
offset of the underlying file must be exact. */
int must_be_exact = (fp->_IO_read_base == fp->_IO_read_end
&& fp->_IO_write_base == fp->_IO_write_ptr);
if (mode == 0)
dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
@ -396,14 +436,15 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
end up flushing when we close(), it doesn't make much difference.)
FIXME: simulate mem-papped files. */
if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode(fp))
if (_IO_switch_to_get_mode(fp)) return EOF;
if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode (fp))
if (_IO_switch_to_get_mode (fp))
return EOF;
if (fp->_IO_buf_base == NULL)
{
_IO_doallocbuf(fp);
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_doallocbuf (fp);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
}
switch (dir)
@ -414,7 +455,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
if (fp->_offset == _IO_pos_BAD)
goto dumb;
/* Make offset absolute, assuming current pointer is file_ptr(). */
offset += _IO_pos_as_off(fp->_offset);
offset += _IO_pos_as_off (fp->_offset);
dir = _IO_seek_set;
break;
@ -423,7 +464,7 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
case _IO_seek_end:
{
struct stat st;
if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG(st.st_mode))
if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
{
offset += st.st_size;
dir = _IO_seek_set;
@ -439,46 +480,46 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
&& !_IO_in_backup (fp))
{
/* Offset relative to start of main get area. */
_IO_pos_t rel_offset = offset - fp->_offset
+ (fp->_IO_read_end - fp->_IO_read_base);
_IO_pos_t rel_offset = (offset - fp->_offset
+ (fp->_IO_read_end - fp->_IO_read_base));
if (rel_offset >= 0)
{
#if 0
if (_IO_in_backup(fp))
_IO_switch_to_main_get_area(fp);
if (_IO_in_backup (fp))
_IO_switch_to_main_get_area (fp);
#endif
if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
{
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
fp->_IO_read_end);
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
fp->_IO_read_end);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
return offset;
}
#ifdef TODO
/* If we have streammarkers, seek forward by reading ahead. */
if (_IO_have_markers(fp))
if (_IO_have_markers (fp))
{
int to_skip = rel_offset
- (fp->_IO_read_ptr - fp->_IO_read_base);
if (ignore(to_skip) != to_skip)
if (ignore (to_skip) != to_skip)
goto dumb;
return offset;
}
#endif
}
#ifdef TODO
if (rel_offset < 0 && rel_offset >= Bbase() - Bptr())
if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())
{
if (!_IO_in_backup(fp))
_IO_switch_to_backup_area(fp);
gbump(fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
if (!_IO_in_backup (fp))
_IO_switch_to_backup_area (fp);
gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
return offset;
}
#endif
}
#ifdef TODO
_IO_unsave_markers(fp);
_IO_unsave_markers (fp);
#endif
if (fp->_flags & _IO_NO_READS)
@ -500,7 +541,8 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
else
{
count = _IO_SYSREAD (fp, fp->_IO_buf_base,
fp->_IO_buf_end - fp->_IO_buf_base);
(must_be_exact
? delta : fp->_IO_buf_end - fp->_IO_buf_base));
if (count < delta)
{
/* We weren't allowed to read, but try to seek the remainder. */
@ -509,31 +551,38 @@ DEFUN(_IO_file_seekoff, (fp, offset, dir, mode),
goto dumb;
}
}
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base+delta, fp->_IO_buf_base+count);
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,
fp->_IO_buf_base + count);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_offset = result + count;
_IO_mask_flags(fp, 0, _IO_EOF_SEEN);
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
return offset;
dumb:
_IO_unsave_markers(fp);
_IO_unsave_markers (fp);
result = _IO_SYSSEEK (fp, offset, dir);
if (result != EOF)
_IO_mask_flags(fp, 0, _IO_EOF_SEEN);
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
fp->_offset = result;
_IO_setg(fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setp(fp, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
return result;
}
_IO_ssize_t
DEFUN(_IO_file_read, (fp, buf, size),
register _IO_FILE* fp AND void* buf AND _IO_ssize_t size)
_IO_file_read (fp, buf, size)
_IO_FILE *fp;
void *buf;
_IO_ssize_t size;
{
for (;;)
{
_IO_ssize_t count = _IO_read(fp->_fileno, buf, size);
#ifdef EINTR
_IO_ssize_t count = _IO_read (fp->_fileno, buf, size);
#if 0 && defined EINTR
/* We must not do this optimization since POSIX.1 explicitly
requests that the stream operations must return with the
error EINTR if this happens. There must be the possibility
that stream operations time out. --drepper */
if (count == -1 && errno == EINTR)
continue;
#endif
@ -542,37 +591,46 @@ DEFUN(_IO_file_read, (fp, buf, size),
}
_IO_pos_t
DEFUN(_IO_file_seek, (fp, offset, dir),
_IO_FILE *fp AND _IO_off_t offset AND int dir)
_IO_file_seek (fp, offset, dir)
_IO_FILE *fp;
_IO_off_t offset;
int dir;
{
return _IO_lseek(fp->_fileno, offset, dir);
return _IO_lseek (fp->_fileno, offset, dir);
}
int
DEFUN(_IO_file_stat, (fp, st),
_IO_FILE *fp AND void* st)
_IO_file_stat (fp, st)
_IO_FILE *fp;
void *st;
{
return _IO_fstat(fp->_fileno, (struct stat*)st);
return _IO_fstat (fp->_fileno, (struct stat *) st);
}
int
DEFUN(_IO_file_close, (fp),
_IO_FILE* fp)
_IO_file_close (fp)
_IO_FILE *fp;
{
return _IO_close(fp->_fileno);
return _IO_close (fp->_fileno);
}
_IO_ssize_t
DEFUN(_IO_file_write, (f, data, n),
register _IO_FILE* f AND const void* data AND _IO_ssize_t n)
_IO_file_write (f, data, n)
_IO_FILE *f;
const void *data;
_IO_ssize_t n;
{
_IO_ssize_t to_do = n;
while (to_do > 0)
{
_IO_ssize_t count = _IO_write(f->_fileno, data, to_do);
_IO_ssize_t count = _IO_write (f->_fileno, data, to_do);
if (count == EOF)
{
#ifdef EINTR
#if 0 && defined EINTR
/* We must not do this optimization since POSIX.1 explicitly
requests that the stream operations must return with the
error EINTR if this happens. There must be the
possibility that stream operations time out. --drepper */
if (errno == EINTR)
continue;
else
@ -583,7 +641,7 @@ DEFUN(_IO_file_write, (f, data, n),
}
}
to_do -= count;
data = (void*)((char*)data + count);
data = (void *) ((char *) data + count);
}
n -= to_do;
if (f->_offset >= 0)
@ -592,10 +650,12 @@ DEFUN(_IO_file_write, (f, data, n),
}
_IO_size_t
DEFUN(_IO_file_xsputn, (f, data, n),
_IO_FILE *f AND const void *data AND _IO_size_t n)
_IO_file_xsputn (f, data, n)
_IO_FILE *f;
const void *data;
_IO_size_t n;
{
register const char *s = (char*) data;
register const char *s = (char *) data;
_IO_size_t to_do = n;
int must_flush = 0;
_IO_size_t count;
@ -612,14 +672,16 @@ DEFUN(_IO_file_xsputn, (f, data, n),
{
count = f->_IO_buf_end - f->_IO_write_ptr;
if (count >= n)
{ register const char *p;
{
register const char *p;
for (p = s + n; p > s; )
{
if (*--p == '\n') {
count = p - s + 1;
must_flush = 1;
break;
}
if (*--p == '\n')
{
count = p - s + 1;
must_flush = 1;
break;
}
}
}
}
@ -628,23 +690,26 @@ DEFUN(_IO_file_xsputn, (f, data, n),
{
if (count > to_do)
count = to_do;
if (count > 20) {
memcpy(f->_IO_write_ptr, s, count);
s += count;
}
if (count > 20)
{
memcpy (f->_IO_write_ptr, s, count);
s += count;
}
else
{
register char *p = f->_IO_write_ptr;
register int i = (int)count;
while (--i >= 0) *p++ = *s++;
register int i = (int) count;
while (--i >= 0)
*p++ = *s++;
}
f->_IO_write_ptr += count;
to_do -= count;
}
if (to_do + must_flush > 0)
{ _IO_size_t block_size, dont_write;
{
_IO_size_t block_size, dont_write;
/* Next flush the (full) buffer. */
if (__overflow(f, EOF) == EOF)
if (__overflow (f, EOF) == EOF)
return n - to_do;
/* Try to maintain alignment: write a whole number of blocks.
@ -653,15 +718,15 @@ DEFUN(_IO_file_xsputn, (f, data, n),
dont_write = block_size >= 128 ? to_do % block_size : 0;
count = to_do - dont_write;
if (_IO_do_write(f, s, count) == EOF)
if (_IO_do_write (f, s, count) == EOF)
return n - to_do;
to_do = dont_write;
/* Now write out the remainder. Normally, this will fit in the
buffer, but it's somewhat messier for line-buffered files,
so we let _IO_default_xsputn handle the general case. */
if (dont_write)
to_do -= _IO_default_xsputn(f, s+count, dont_write);
to_do -= _IO_default_xsputn (f, s+count, dont_write);
}
return n - to_do;
}
@ -669,21 +734,24 @@ DEFUN(_IO_file_xsputn, (f, data, n),
#if 0
/* Work in progress */
_IO_size_t
DEFUN(_IO_file_xsgetn, (fp, data, n),
_IO_FILE *fp AND void *data AND _IO_size_t n)
_IO_file_xsgetn (fp, data, n)
_IO_FILE *fp;
void *data;
_IO_size_t n;
{
register _IO_size_t more = n;
register char *s = data;
for (;;)
{
_IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr; /* Data available. */
/* Data available. */
_IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr;
if (count > 0)
{
if (count > more)
count = more;
if (count > 20)
{
memcpy(s, fp->_IO_read_ptr, count);
memcpy (s, fp->_IO_read_ptr, count);
s += count;
fp->_IO_read_ptr += count;
}
@ -692,8 +760,9 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
else
{
register char *p = fp->_IO_read_ptr;
register int i = (int)count;
while (--i >= 0) *s++ = *p++;
register int i = (int) count;
while (--i >= 0)
*s++ = *p++;
fp->_IO_read_ptr = p;
}
more -= count;
@ -708,11 +777,11 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
/* If we're reading a lot of data, don't bother allocating
a buffer. But if we're only reading a bit, perhaps we should ??*/
if (count <= 512 && fp->_IO_buf_base == NULL)
_IO_doallocbuf(fp);
_IO_doallocbuf (fp);
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
_IO_flush_all_linebuffered();
_IO_flush_all_linebuffered ();
_IO_switch_to_get_mode(fp); ???;
_IO_switch_to_get_mode (fp); ???;
count = _IO_SYSREAD (fp, s, more);
if (count <= 0)
{
@ -721,19 +790,20 @@ DEFUN(_IO_file_xsgetn, (fp, data, n),
else
fp->_flags |= _IO_ERR_SEEN, count = 0;
}
s += count;
more -= count;
}
#endif
if (more == 0 || __underflow(fp) == EOF)
if (more == 0 || __underflow (fp) == EOF)
break;
}
return n - more;
}
#endif
struct _IO_jump_t _IO_file_jumps = {
struct _IO_jump_t _IO_file_jumps =
{
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_file_finish),
JUMP_INIT(overflow, _IO_file_overflow),

File diff suppressed because it is too large Load Diff

1
libio/include/empty.h Normal file
View File

@ -0,0 +1 @@
/* this will be used later*/

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#ifdef __STDC__
@ -28,20 +29,30 @@ the executable file might be covered by the GNU General Public License. */
#endif
int
DEFUN(_IO_fclose, (fp),
register _IO_FILE *fp)
_IO_fclose (fp)
_IO_FILE *fp;
{
int status;
CHECK_FILE(fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
status = _IO_file_close_it(fp);
status = _IO_file_close_it (fp);
else
status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
_IO_FINISH (fp);
_IO_cleanup_region_end (1);
if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
{
fp->_IO_file_flags = 0;
free(fp);
}
return status;
}
#ifdef weak_alias
weak_alias (_IO_fclose, fclose)
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993, 1994 Free Software Foundation
/* Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#ifdef __STDC__
#include <stdlib.h>
@ -33,12 +34,19 @@ the executable file might be covered by the GNU General Public License. */
#endif
_IO_FILE *
DEFUN(_IO_fdopen, (fd, mode),
int fd AND const char *mode)
_IO_fdopen (fd, mode)
int fd;
const char *mode;
{
int read_write;
int posix_mode = 0;
struct _IO_FILE_plus *fp;
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f;
int fd_flags;
switch (*mode++)
@ -54,9 +62,7 @@ DEFUN(_IO_fdopen, (fd, mode),
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
#ifdef EINVAL
errno = EINVAL;
#endif
MAYBE_SET_EINVAL;
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
@ -96,26 +102,33 @@ DEFUN(_IO_fdopen, (fd, mode),
}
#endif
fp = (struct _IO_FILE_plus*)malloc(sizeof(struct _IO_FILE_plus));
if (fp == NULL)
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
_IO_init(&fp->file, 0);
_IO_JUMPS(&fp->file) = &_IO_file_jumps;
_IO_file_init(&fp->file);
#if !_IO_UNIFIED_JUMPTABLES
fp->vtable = NULL;
#ifdef _IO_MTSAFE_IO
new_f->fp.file._lock = &new_f->lock;
#endif
if (_IO_file_attach(&fp->file, fd) == NULL)
_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
new_f->fp.vtable = NULL;
#endif
if (_IO_file_attach (&new_f->fp.file, fd) == NULL)
{
_IO_un_link(&fp->file);
free (fp);
_IO_un_link (&new_f->fp.file);
free (new_f);
return NULL;
}
fp->file._flags &= ~_IO_DELETE_DONT_CLOSE;
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
fp->file._IO_file_flags =
_IO_mask_flags(&fp->file, read_write,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
new_f->fp.file._IO_file_flags =
_IO_mask_flags (&new_f->fp.file, read_write,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
return (_IO_FILE*)fp;
return (_IO_FILE *) &new_f->fp;
}
#ifdef weak_alias
weak_alias (_IO_fdopen, fdopen)
#endif

43
libio/iofeof.c Normal file
View File

@ -0,0 +1,43 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
_IO_feof (fp)
_IO_FILE* fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_flockfile (fp);
result = _IO_feof_unlocked (fp);
_IO_funlockfile (fp);
return result;
}
#ifdef weak_alias
weak_alias (_IO_feof, feof)
#endif

43
libio/ioferror.c Normal file
View File

@ -0,0 +1,43 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
_IO_ferror (fp)
_IO_FILE* fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_flockfile (fp);
result = _IO_ferror_unlocked (fp);
_IO_funlockfile (fp);
return result;
}
#ifdef weak_alias
weak_alias (_IO_ferror, ferror)
#endif

View File

@ -1,38 +1,49 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <stdio.h>
int
DEFUN(_IO_fflush, (fp),
register _IO_FILE *fp)
_IO_fflush (fp)
_IO_FILE *fp;
{
if (fp == NULL)
return _IO_flush_all();
return _IO_flush_all ();
else
{
CHECK_FILE(fp, EOF);
return _IO_SYNC (fp) ? EOF : 0;
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_SYNC (fp) ? EOF : 0;
_IO_cleanup_region_end (1);
return result;
}
}
#ifdef weak_alias
weak_alias (_IO_fflush, fflush)
#endif

40
libio/iofflush_u.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <stdio.h>
int
fflush_unlocked (fp)
_IO_FILE *fp;
{
if (fp == NULL)
return _IO_flush_all ();
else
{
CHECK_FILE (fp, EOF);
return _IO_SYNC (fp) ? EOF : 0;
}
}

View File

@ -1,46 +1,55 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <errno.h>
/* ANSI explicily requires setting errno to a positive value on failure. */
/* ANSI explicitly requires setting errno to a positive value on failure. */
int
DEFUN(_IO_fgetpos, (fp, posp),
_IO_FILE* fp AND _IO_fpos_t *posp)
_IO_fgetpos (fp, posp)
_IO_FILE* fp;
_IO_fpos_t *posp;
{
_IO_fpos_t pos;
CHECK_FILE(fp, EOF);
pos = _IO_seekoff(fp, 0, _IO_seek_cur, 0);
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0);
_IO_cleanup_region_end (1);
if (pos == _IO_pos_BAD)
{
#ifdef EIO
if (errno == 0)
errno = EIO;
__set_errno (EIO);
#endif
return EOF;
}
*posp = pos;
return 0;
}
#ifdef weak_alias
weak_alias (_IO_fgetpos, fgetpos)
#endif

View File

@ -1,40 +1,56 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <stdio.h>
char*
DEFUN(_IO_fgets, (buf, n, fp),
char* buf AND int n AND _IO_FILE* fp)
char *
_IO_fgets (buf, n, fp)
char *buf;
int n;
_IO_FILE *fp;
{
_IO_size_t count;
CHECK_FILE(fp, NULL);
char *result;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
count = _IO_getline(fp, buf, n - 1, '\n', 1);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
count = _IO_getline (fp, buf, n - 1, '\n', 1);
if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN))
return NULL;
buf[count] = 0;
return buf;
result = NULL;
else
{
buf[count] = '\0';
result = buf;
}
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_fgets, fgets)
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#ifdef __STDC__
@ -28,22 +29,36 @@ the executable file might be covered by the GNU General Public License. */
#endif
_IO_FILE *
DEFUN(_IO_fopen, (filename, mode),
const char *filename AND const char *mode)
_IO_fopen (filename, mode)
const char *filename;
const char *mode;
{
struct _IO_FILE_plus *fp =
(struct _IO_FILE_plus*)malloc(sizeof(struct _IO_FILE_plus));
if (fp == NULL)
return NULL;
_IO_init(&fp->file, 0);
_IO_JUMPS(&fp->file) = &_IO_file_jumps;
_IO_file_init(&fp->file);
#if !_IO_UNIFIED_JUMPTABLES
fp->vtable = NULL;
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
if (_IO_file_fopen(&fp->file, filename, mode) != NULL)
return (_IO_FILE*)fp;
_IO_un_link(&fp->file);
free (fp);
} *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fp.file._lock = &new_f->lock;
#endif
_IO_init (&new_f->fp.file, 0);
_IO_JUMPS (&new_f->fp.file) = &_IO_file_jumps;
_IO_file_init (&new_f->fp.file);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
#endif
if (_IO_file_fopen (&new_f->fp.file, filename, mode) != NULL)
return (_IO_FILE *) &new_f->fp;
_IO_un_link (&new_f->fp.file);
free (new_f);
return NULL;
}
#ifdef weak_alias
weak_alias (_IO_fopen, fopen)
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
@ -31,18 +32,20 @@ the executable file might be covered by the GNU General Public License. */
#endif
int
_IO_fprintf
#ifdef __STDC__
(_IO_FILE *fp, const char* format, ...)
_IO_fprintf (_IO_FILE *fp, const char* format, ...)
#else
(fp, format, va_alist) _IO_FILE *fp; char *format; va_dcl
_IO_fprintf (fp, format, va_alist)
_IO_FILE *fp;
char *format;
va_dcl
#endif
{
int ret;
va_list args;
CHECK_FILE(fp, -1);
_IO_va_start(args, format);
ret = _IO_vfprintf(fp, format, args);
va_end(args);
CHECK_FILE (fp, -1);
_IO_va_start (args, format);
ret = _IO_vfprintf (fp, format, args);
va_end (args);
return ret;
}

View File

@ -1,37 +1,49 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <string.h>
int
DEFUN(_IO_fputs, (str, fp),
const char *str AND _IO_FILE *fp)
_IO_fputs (str, fp)
const char *str;
_IO_FILE *fp;
{
_IO_size_t len = strlen(str);
CHECK_FILE(fp, EOF);
if (_IO_sputn(fp, str, len) != len)
return EOF;
return 1;
_IO_size_t len = strlen (str);
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_sputn (fp, str, len) != len)
result = EOF;
else
result = 1;
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_fputs, fputs)
#endif

View File

@ -1,38 +1,49 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
_IO_size_t
DEFUN(_IO_fread, (buf, size, count, fp),
void *buf AND _IO_size_t size AND _IO_size_t count AND _IO_FILE* fp)
_IO_fread (buf, size, count, fp)
void *buf;
_IO_size_t size;
_IO_size_t count;
_IO_FILE *fp;
{
_IO_size_t bytes_requested = size*count;
_IO_size_t bytes_read;
CHECK_FILE(fp, 0);
CHECK_FILE (fp, 0);
if (bytes_requested == 0)
return 0;
bytes_read = _IO_sgetn(fp, (char *)buf, bytes_requested);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
bytes_read = _IO_sgetn (fp, (char *) buf, bytes_requested);
_IO_cleanup_region_end (1);
return bytes_requested == bytes_read ? count : bytes_read / size;
}
#ifdef weak_alias
weak_alias (_IO_fread, fread)
#endif

View File

@ -1,43 +1,56 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libioP.h>
#include <errno.h>
int
DEFUN(_IO_fsetpos, (fp, posp),
_IO_FILE* fp AND const _IO_fpos_t *posp)
_IO_fsetpos (fp, posp)
_IO_FILE *fp;
const _IO_fpos_t *posp;
{
CHECK_FILE(fp, EOF);
if (_IO_seekpos(fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD)
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_seekpos (fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD)
{
/*ANSI explicily requires setting errno to a positive value on failure.*/
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
errno = EIO;
__set_errno (EIO);
#endif
return EOF;
result = EOF;
}
return 0;
else
result = 0;
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_fsetpos, fsetpos)
#endif

View File

@ -1,45 +1,53 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <errno.h>
/* ANSI explicily requires setting errno to a positive value on failure. */
long int
DEFUN(_IO_ftell, (fp),
_IO_FILE* fp)
_IO_ftell (fp)
_IO_FILE *fp;
{
_IO_pos_t pos;
CHECK_FILE(fp, -1L);
pos = _IO_seekoff(fp, 0, _IO_seek_cur, 0);
CHECK_FILE (fp, -1L);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0);
_IO_cleanup_region_end (1);
if (pos == _IO_pos_BAD)
{
#ifdef EIO
if (errno == 0)
errno = EIO;
__set_errno (EIO);
#endif
return -1L;
}
return _IO_pos_as_off(pos);
return _IO_pos_as_off (pos);
}
#ifdef weak_alias
weak_alias (_IO_ftell, ftell)
#endif

View File

@ -1,44 +1,54 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
_IO_size_t
DEFUN(_IO_fwrite, (buf, size, count, fp),
const void* buf AND _IO_size_t size AND _IO_size_t count
AND _IO_FILE *fp)
_IO_fwrite (buf, size, count, fp)
const void *buf;
_IO_size_t size;
_IO_size_t count;
_IO_FILE *fp;
{
_IO_size_t request = size*count;
_IO_size_t request = size * count;
_IO_size_t written;
CHECK_FILE(fp, 0);
CHECK_FILE (fp, 0);
if (request == 0)
return 0;
written = _IO_sputn(fp, (const char *)buf, request);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
written = _IO_sputn (fp, (const char *) buf, request);
_IO_cleanup_region_end (1);
/* Many traditional implementations return 0 if size==0 && count > 0,
but ANSI seems to require us to return count in this case. */
but ANSI requires us to return count in this case. */
if (written == request)
return count;
else
return written/size;
return written / size;
}
#ifdef weak_alias
weak_alias (_IO_fwrite, fwrite)
#endif

48
libio/iogetc.c Normal file
View File

@ -0,0 +1,48 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef _IO_getc
int
_IO_getc (fp)
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_getc_unlocked (fp);
_IO_cleanup_region_end (1);
return result;
}
#undef getc
#ifdef weak_alias
weak_alias (_IO_getc, getc)
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1994 Free Software Foundation
/* Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#ifdef __STDC__
#include <stdlib.h>
@ -36,36 +37,49 @@ the executable file might be covered by the GNU General Public License. */
null terminator), or -1 on error or EOF. */
_IO_ssize_t
DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
char **lineptr AND _IO_size_t *n AND int delimiter AND _IO_FILE *fp)
_IO_getdelim (lineptr, n, delimiter, fp)
char **lineptr;
_IO_size_t *n;
int delimiter;
_IO_FILE *fp;
{
register _IO_ssize_t cur_len = 0;
int result;
_IO_ssize_t cur_len = 0;
_IO_ssize_t len;
if (lineptr == NULL || n == NULL)
{
#ifdef EINVAL
errno = EINVAL;
#endif
MAYBE_SET_EINVAL;
return -1;
}
CHECK_FILE (fp, -1);
if (_IO_ferror (fp))
return -1;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_ferror_unlocked (fp))
{
result = -1;
goto unlock_return;
}
if (*lineptr == NULL || *n == 0)
{
*n = 120;
*lineptr = (char *) malloc (*n);
if (*lineptr == NULL)
return -1;
{
result = -1;
goto unlock_return;
}
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len <= 0)
{
if (__underflow (fp) == EOF)
return -1;
{
result = -1;
goto unlock_return;
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
@ -76,16 +90,19 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
if (t != NULL)
len = (t - fp->_IO_read_ptr) + 1;
/* make enough space for len+1 (for final NUL) bytes. */
/* Make enough space for len+1 (for final NUL) bytes. */
needed = cur_len + len + 1;
if (needed > *n)
{
if (t == NULL && needed < 2 * *n)
if (needed < 2 * *n)
needed = 2 * *n; /* Be generous. */
*n = needed;
*lineptr = (char *) realloc (*lineptr, needed);
if (*lineptr == NULL)
return -1;
{
result = -1;
goto unlock_return;
}
}
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
@ -95,5 +112,14 @@ DEFUN(_IO_getdelim, (lineptr, n, delimiter, fp),
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
(*lineptr)[cur_len] = '\0';
return cur_len;
result = cur_len;
unlock_return:
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_getdelim, __getdelim)
weak_alias (_IO_getdelim, getdelim)
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <string.h>
@ -34,38 +35,41 @@ the executable file might be covered by the GNU General Public License. */
If extract_delim > 0, insert delim in output. */
_IO_size_t
DEFUN(_IO_getline, (fp, buf, n, delim, extract_delim),
_IO_FILE *fp AND char* buf AND _IO_size_t n
AND int delim AND int extract_delim)
_IO_getline (fp, buf, n, delim, extract_delim)
_IO_FILE *fp;
char *buf;
_IO_size_t n;
int delim;
int extract_delim;
{
register char *ptr = buf;
char *ptr = buf;
do
{
_IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr;
char *t;
if (len <= 0)
if (__underflow(fp) == EOF)
if (__underflow (fp) == EOF)
break;
else
len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len >= n)
if ((_IO_size_t) len >= n)
len = n;
t = (char*)memchr((void*)fp->_IO_read_ptr, delim, len);
t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
if (t != NULL)
{
_IO_size_t old_len = ptr-buf;
len = t - fp->_IO_read_ptr;
if (extract_delim >= 0)
{
t++;
++t;
if (extract_delim > 0)
len++;
++len;
}
memcpy((void*)ptr, (void*)fp->_IO_read_ptr, len);
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr = t;
return old_len + len;
}
memcpy((void*)ptr, (void*)fp->_IO_read_ptr, len);
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
ptr += len;
n -= len;

View File

@ -1,47 +1,71 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <limits.h>
char*
DEFUN(_IO_gets, (buf),
char* buf)
_IO_gets (buf)
char *buf;
{
_IO_size_t count;
int ch = _IO_getc (_IO_stdin);
int ch;
char *retval;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
_IO_stdin);
_IO_flockfile (_IO_stdin);
ch = _IO_getc_unlocked (_IO_stdin);
if (ch == EOF)
return NULL;
{
retval = NULL;
goto unlock_return;
}
if (ch == '\n')
count = 0;
else
{
buf[0] = (char)ch;
count = _IO_getline(_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
buf[0] = (char) ch;
count = _IO_getline (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
return NULL;
{
retval = NULL;
goto unlock_return;
}
}
buf[count] = 0;
return buf;
retval = buf;
unlock_return:
_IO_cleanup_region_end (1);
return retval;
}
#ifdef weak_alias
weak_alias (_IO_gets, gets)
#endif
#ifdef _LIBC
link_warning (gets, "the `gets' function is dangerous and should not be used.")
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
@ -31,34 +32,38 @@ static char const zeroes[PADSIZE] =
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
_IO_ssize_t
DEFUN(_IO_padn, (fp, pad, count),
_IO_FILE *fp AND int pad AND _IO_ssize_t count)
_IO_padn (fp, pad, count)
_IO_FILE *fp;
int pad;
_IO_ssize_t count;
{
char padbuf[PADSIZE];
const char *padptr;
register int i;
_IO_size_t written = 0, w;
int i;
_IO_size_t written = 0;
_IO_size_t w;
if (pad == ' ')
padptr = blanks;
else if (pad == '0')
padptr = zeroes;
else
{
for (i = PADSIZE; --i >= 0; ) padbuf[i] = pad;
for (i = PADSIZE; --i >= 0; )
padbuf[i] = pad;
padptr = padbuf;
}
for (i = count; i >= PADSIZE; i -= PADSIZE)
{
w = _IO_sputn(fp, padptr, PADSIZE);
w = _IO_sputn (fp, padptr, PADSIZE);
written += w;
if (w != PADSIZE)
return written;
}
if (i > 0)
{
w = _IO_sputn(fp, padptr, i);
w = _IO_sputn (fp, padptr, i);
written += w;
}
return written;

View File

@ -1,55 +1,60 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
Written by Per Bothner <bothner@cygnus.com>.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
/* written by Per Bothner (bothner@cygnus.com) */
#define _POSIX_SOURCE
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h"
#include <sys/types.h>
#if _IO_HAVE_SYS_WAIT
#include <signal.h>
#include <unistd.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef _LIBC
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>
#ifndef _IO_fork
#define _IO_fork vfork /* defined in libiberty, if needed */
_IO_pid_t _IO_fork();
extern _IO_pid_t _IO_fork __P ((void));
#endif
#endif /* _IO_HAVE_SYS_WAIT */
#ifndef _IO_pipe
#define _IO_pipe pipe
extern int _IO_pipe();
extern int _IO_pipe __P ((int des[2]));
#endif
#ifndef _IO_dup2
#define _IO_dup2 dup2
extern int _IO_dup2();
extern int _IO_dup2 __P ((int fd, int fd2));
#endif
#ifndef _IO_waitpid
@ -75,17 +80,19 @@ typedef struct _IO_proc_file _IO_proc_file;
static struct _IO_proc_file *proc_file_chain = NULL;
_IO_FILE *
DEFUN(_IO_proc_open, (fp, command, mode),
_IO_FILE* fp AND const char *command AND const char *mode)
_IO_proc_open (fp, command, mode)
_IO_FILE *fp;
const char *command;
const char *mode;
{
#if _IO_HAVE_SYS_WAIT
int read_or_write;
volatile int read_or_write;
volatile int parent_end, child_end;
int pipe_fds[2];
int parent_end, child_end;
_IO_pid_t child_pid;
if (_IO_file_is_open(fp))
if (_IO_file_is_open (fp))
return NULL;
if (_IO_pipe(pipe_fds) < 0)
if (_IO_pipe (pipe_fds) < 0)
return NULL;
if (mode[0] == 'r')
{
@ -99,17 +106,17 @@ DEFUN(_IO_proc_open, (fp, command, mode),
child_end = pipe_fds[0];
read_or_write = _IO_NO_READS;
}
((_IO_proc_file*)fp)->pid = child_pid = _IO_fork();
((_IO_proc_file *) fp)->pid = child_pid = _IO_fork ();
if (child_pid == 0)
{
int child_std_end = mode[0] == 'r' ? 1 : 0;
_IO_close(parent_end);
_IO_close (parent_end);
if (child_end != child_std_end)
{
_IO_dup2(child_end, child_std_end);
_IO_close(child_end);
_IO_dup2 (child_end, child_std_end);
_IO_close (child_end);
}
/* Posix.2: "popen() shall ensure that any streams from previous
/* POSIX.2: "popen() shall ensure that any streams from previous
popen() calls that remain open in the parent process are closed
in the new child process." */
while (proc_file_chain)
@ -118,20 +125,20 @@ DEFUN(_IO_proc_open, (fp, command, mode),
proc_file_chain = proc_file_chain->next;
}
_IO_execl("/bin/sh", "sh", "-c", command, (char *)0);
_IO__exit(127);
_IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
_IO__exit (127);
}
_IO_close(child_end);
_IO_close (child_end);
if (child_pid < 0)
{
_IO_close(parent_end);
_IO_close (parent_end);
return NULL;
}
_IO_fileno(fp) = parent_end;
_IO_fileno (fp) = parent_end;
/* Link into proc_file_chain. */
((_IO_proc_file*)fp)->next = proc_file_chain;
proc_file_chain = (_IO_proc_file*)fp;
((_IO_proc_file *) fp)->next = proc_file_chain;
proc_file_chain = (_IO_proc_file *) fp;
_IO_mask_flags (fp, read_or_write, _IO_NO_READS|_IO_NO_WRITES);
return fp;
@ -141,28 +148,45 @@ DEFUN(_IO_proc_open, (fp, command, mode),
}
_IO_FILE *
DEFUN(_IO_popen, (command, mode),
const char *command AND const char *mode)
_IO_popen (command, mode)
const char *command;
const char *mode;
{
_IO_proc_file *fpx = (_IO_proc_file*)malloc(sizeof(_IO_proc_file));
_IO_FILE *fp = (_IO_FILE*)fpx;
if (fp == NULL)
struct locked_FILE
{
struct _IO_proc_file fpx;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f;
_IO_FILE *fp;
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
_IO_init(fp, 0);
_IO_JUMPS(fp) = &_IO_proc_jumps;
_IO_file_init(fp);
#ifdef _IO_MTSAFE_IO
new_f->fpx.file.file._lock = &new_f->lock;
#endif
fp = (_IO_FILE*)&new_f->fpx;
_IO_init (fp, 0);
_IO_JUMPS (fp) = &_IO_proc_jumps;
_IO_file_init (fp);
#if !_IO_UNIFIED_JUMPTABLES
((struct _IO_FILE_plus*)fp)->vtable = NULL;
((struct _IO_FILE_plus *) fp)->vtable = NULL;
#endif
if (_IO_proc_open (fp, command, mode) != NULL)
return fp;
free (fpx);
free (new_f);
return NULL;
}
#ifdef strong_alias
strong_alias (_IO_popen, popen);
#endif
int
DEFUN(_IO_proc_close, (fp),
_IO_FILE *fp)
_IO_proc_close (fp)
_IO_FILE *fp;
{
/* This is not name-space clean. FIXME! */
#if _IO_HAVE_SYS_WAIT
@ -170,11 +194,11 @@ DEFUN(_IO_proc_close, (fp),
_IO_proc_file **ptr = &proc_file_chain;
_IO_pid_t wait_pid;
int status = -1;
/* Unlink from proc_file_chain. */
for ( ; *ptr != NULL; ptr = &(*ptr)->next)
{
if (*ptr == (_IO_proc_file*)fp)
if (*ptr == (_IO_proc_file *) fp)
{
*ptr = (*ptr)->next;
status = 0;
@ -182,7 +206,7 @@ DEFUN(_IO_proc_close, (fp),
}
}
if (status < 0 || _IO_close(_IO_fileno(fp)) < 0)
if (status < 0 || _IO_close (_IO_fileno(fp)) < 0)
return -1;
/* POSIX.2 Rationale: "Some historical implementations either block
or ignore the signals SIGINT, SIGQUIT, and SIGHUP while waiting
@ -190,8 +214,9 @@ DEFUN(_IO_proc_close, (fp),
described in POSIX.2, such implementations are not conforming." */
do
{
wait_pid = _IO_waitpid (((_IO_proc_file*)fp)->pid, &wstatus, 0);
} while (wait_pid == -1 && errno == EINTR);
wait_pid = _IO_waitpid (((_IO_proc_file *) fp)->pid, &wstatus, 0);
}
while (wait_pid == -1 && errno == EINTR);
if (wait_pid == -1)
return -1;
return wstatus;

42
libio/ioputc.c Normal file
View File

@ -0,0 +1,42 @@
/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "libioP.h"
#include "stdio.h"
#undef _IO_putc
int
_IO_putc (c, fp)
int c;
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_putc_unlocked (c, fp);
_IO_cleanup_region_end (1);
return result;
}
#undef putc
#ifdef weak_alias
weak_alias (_IO_putc, putc)
#endif

View File

@ -1,38 +1,49 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <string.h>
int
DEFUN(_IO_puts, (str),
const char *str)
_IO_puts (str)
const char *str;
{
_IO_size_t len = strlen(str);
if (_IO_sputn(_IO_stdout, str, len) != len)
return EOF;
if (_IO_putc('\n', _IO_stdout) == EOF)
return EOF;
return len+1;
int result;
_IO_size_t len = strlen (str);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
_IO_stdout);
_IO_flockfile (_IO_stdout);
if (_IO_sputn (_IO_stdout, str, len) == len
&& _IO_putc_unlocked ('\n', _IO_stdout) != EOF)
result = len + 1;
else
result = EOF;
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_puts, puts)
#endif

View File

@ -1,32 +1,36 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libioP.h>
_IO_pos_t
DEFUN(_IO_seekoff, (fp, offset, dir, mode),
_IO_FILE* fp AND _IO_off_t offset AND int dir AND int mode)
_IO_seekoff (fp, offset, dir, mode)
_IO_FILE *fp;
_IO_off_t offset;
int dir;
int mode;
{
/* If we have a backup buffer, get rid of it, since the __seekoff
callback may not know to do the right thing about it.

View File

@ -1,32 +1,35 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libioP.h>
_IO_pos_t
DEFUN(_IO_seekpos, (fp, pos, mode),
_IO_FILE* fp AND _IO_pos_t pos AND int mode)
_IO_seekpos (fp, pos, mode)
_IO_FILE *fp;
_IO_pos_t pos;
int mode;
{
/* If we have a backup buffer, get rid of it, since the __seekoff
callback may not know to do the right thing about it.

View File

@ -1,36 +1,46 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
void
DEFUN(_IO_setbuffer, (fp, buf, size),
_IO_FILE *fp AND char *buf AND _IO_size_t size)
_IO_setbuffer (fp, buf, size)
_IO_FILE *fp;
char *buf;
_IO_size_t size;
{
CHECK_FILE(fp, );
CHECK_FILE (fp, );
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
fp->_flags &= ~_IO_LINE_BUF;
if (!buf)
size = 0;
(void) _IO_SETBUF (fp, buf, size);
_IO_cleanup_region_end (1);
}
#ifdef weak_alias
weak_alias (_IO_setbuffer, setbuffer)
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
@ -29,10 +30,16 @@ the executable file might be covered by the GNU General Public License. */
#define _IONBF 2 /* No buffering. */
int
DEFUN(_IO_setvbuf, (fp, buf, mode, size),
_IO_FILE* fp AND char* buf AND int mode AND _IO_size_t size)
_IO_setvbuf (fp, buf, mode, size)
_IO_FILE *fp;
char *buf;
int mode;
_IO_size_t size;
{
CHECK_FILE(fp, EOF);
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
switch (mode)
{
case _IOFBF:
@ -55,24 +62,39 @@ DEFUN(_IO_setvbuf, (fp, buf, mode, size),
A possibly cleaner alternative would be to add an
extra flag, but then flags are a finite resource. */
if (_IO_DOALLOCATE (fp) < 0)
return EOF;
{
result = EOF;
goto unlock_return;
}
fp->_IO_file_flags &= ~_IO_LINE_BUF;
}
return 0;
result = 0;
goto unlock_return;
}
break;
case _IOLBF:
fp->_IO_file_flags &= ~_IO_UNBUFFERED;
fp->_IO_file_flags |= _IO_LINE_BUF;
if (buf == NULL)
return 0;
{
result = 0;
goto unlock_return;
}
break;
case _IONBF:
buf = NULL;
size = 0;
break;
default:
return EOF;
result = EOF;
goto unlock_return;
}
return _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
result = _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
unlock_return:
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_setvbuf, setvbuf)
#endif

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
@ -31,17 +32,19 @@ the executable file might be covered by the GNU General Public License. */
#endif
int
_IO_sprintf
#ifdef __STDC__
(char *string, const char* format, ...)
_IO_sprintf (char *string, const char* format, ...)
#else
(string, format, va_alist) char *string; char *format; va_dcl
_IO_sprintf (string, format, va_alist)
char *string;
char *format;
va_dcl
#endif
{
int ret;
va_list args;
_IO_va_start(args, format);
ret = _IO_vsprintf(string, format, args);
va_end(args);
_IO_va_start (args, format);
ret = _IO_vsprintf (string, format, args);
va_end (args);
return ret;
}

View File

@ -1,4 +1,4 @@
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
@ -96,7 +96,11 @@ class ostream : virtual public ios
#endif
ostream& operator<<(double n);
ostream& operator<<(float n) { return operator<<((double)n); }
#if _G_HAVE_LONG_DOUBLE_IO
ostream& operator<<(long double n);
#else
ostream& operator<<(long double n) { return operator<<((double)n); }
#endif
ostream& operator<<(__omanip func) { return (*func)(*this); }
ostream& operator<<(__manip func) {(*func)(*this); return *this;}
ostream& operator<<(streambuf*);

View File

@ -1,35 +1,46 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
int
DEFUN(_IO_ungetc, (c, fp),
int c AND _IO_FILE *fp)
_IO_ungetc (c, fp)
int c;
_IO_FILE *fp;
{
CHECK_FILE(fp, EOF);
int result;
CHECK_FILE (fp, EOF);
if (c == EOF)
return EOF;
return _IO_sputbackc(fp, (unsigned char)c);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_sputbackc (fp, (unsigned char) c);
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_ungetc, ungetc)
#endif

View File

@ -1,40 +1,57 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "strfile.h"
int
DEFUN(_IO_vsprintf, (string, format, args),
char *string AND const char *format AND _IO_va_list args)
_IO_vsprintf (string, format, args)
char *string;
const char *format;
_IO_va_list args;
{
_IO_strfile sf;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
int ret;
_IO_init((_IO_FILE*)&sf, 0);
_IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps;
_IO_str_init_static ((_IO_FILE*)&sf, string, -1, string);
ret = _IO_vfprintf((_IO_FILE*)&sf, format, args);
_IO_putc('\0', (_IO_FILE*)&sf);
#ifdef _IO_MTSAFE_IO
sf._sbf._f._lock = &lock;
#endif
_IO_init (&sf._sbf._f, 0);
_IO_JUMPS (&sf._sbf._f) = &_IO_str_jumps;
_IO_str_init_static (&sf._sbf._f, string, -1, string);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, &sf);
_IO_flockfile (&sf._sbf._f);
ret = _IO_vfprintf (&sf._sbf._f, format, args);
_IO_putc_unlocked ('\0', &sf._sbf._f);
_IO_cleanup_region_end (1);
return ret;
}
#ifdef weak_alias
weak_alias (_IO_vsprintf, vsprintf)
#endif

View File

@ -1,37 +1,54 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "strfile.h"
int
DEFUN(_IO_vsscanf, (string, format, args),
const char *string AND const char *format AND _IO_va_list args)
_IO_vsscanf (string, format, args)
const char *string;
const char *format;
_IO_va_list args;
{
int ret;
_IO_strfile sf;
_IO_init((_IO_FILE*)&sf, 0);
_IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps;
_IO_str_init_static ((_IO_FILE*)&sf, (char*)string, 0, NULL);
return _IO_vfscanf((_IO_FILE*)&sf, format, args, NULL);
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
sf._sbf._f._lock = &lock;
#endif
_IO_init (&sf._sbf._f, 0);
_IO_JUMPS (&sf._sbf._f) = &_IO_str_jumps;
_IO_str_init_static (&sf._sbf._f, (char*)string, 0, NULL);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, &sf);
_IO_flockfile (&sf._sbf._f);
ret = _IO_vfscanf (&sf._sbf._f, format, args, NULL);
_IO_cleanup_region_end (1);
return ret;
}
#ifdef weak_alias
weak_alias (_IO_vsscanf, __vsscanf)
weak_alias (_IO_vsscanf, vsscanf)
#endif

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation
This file is part of the GNU IO Library. This library is free
@ -153,6 +153,14 @@ the executable file might be covered by the GNU General Public License. */
struct _IO_jump_t; struct _IO_FILE;
/* Handle lock. */
#ifdef _IO_MTSAFE_IO
# include <stdio-lock.h>
#else
typedef void _IO_lock_t;
#endif
struct _IO_marker {
struct _IO_marker *_next;
struct _IO_FILE *_sbuf;
@ -196,20 +204,22 @@ struct _IO_FILE {
char *_IO_save_end; /* Pointer to end of non-current get area. */
struct _IO_marker *_markers;
struct _IO_FILE *_chain;
int _fileno;
int _blksize;
_IO_off_t _offset;
#define __HAVE_COLUMN /* temporary */
/* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column;
char _unused;
char _shortbuf[1];
/* char* _save_gptr; char* _save_egptr; */
_IO_lock_t *_lock;
};
#ifndef __cplusplus
@ -222,6 +232,26 @@ extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
#define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
#define _IO_stderr ((_IO_FILE*)(&_IO_stderr_))
/* Define the user-visible type, with user-friendly member names. */
typedef struct
{
_IO_ssize_t (*read) __P ((struct _IO_FILE *, void *, _IO_ssize_t));
_IO_ssize_t (*write) __P ((struct _IO_FILE *, const void *, _IO_ssize_t));
_IO_fpos_t (*seek) __P ((struct _IO_FILE *, _IO_off_t, int));
int (*close) __P ((struct _IO_FILE *));
} _IO_cookie_io_functions_t;
/* Special file type for fopencookie function. */
struct _IO_cookie_file
{
struct _IO_FILE file;
const void *vtable;
void *cookie;
_IO_cookie_io_functions_t io_functions;
};
#ifdef __cplusplus
extern "C" {
#endif
@ -230,26 +260,47 @@ extern int __underflow __P((_IO_FILE*));
extern int __uflow __P((_IO_FILE*));
extern int __overflow __P((_IO_FILE*, int));
#define _IO_getc(_fp) \
#define _IO_getc_unlocked(_fp) \
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow(_fp) \
: *(unsigned char*)(_fp)->_IO_read_ptr++)
#define _IO_peekc(_fp) \
#define _IO_peekc_unlocked(_fp) \
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
&& __underflow(_fp) == EOF ? EOF \
: *(unsigned char*)(_fp)->_IO_read_ptr)
#define _IO_putc(_ch, _fp) \
#define _IO_putc_unlocked(_ch, _fp) \
(((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
? __overflow(_fp, (unsigned char)(_ch)) \
: (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch)))
#define _IO_feof(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define _IO_ferror(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
#define _IO_feof_unclocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
extern int _IO_getc __P ((_IO_FILE *__fp));
extern int _IO_putc __P ((int __c, _IO_FILE *__fp));
extern int _IO_feof __P ((_IO_FILE *__fp));
extern int _IO_ferror __P ((_IO_FILE *__fp));
extern int _IO_peekc_locked __P ((_IO_FILE *__fp));
/* This one is for Emacs. */
#define _IO_PENDING_OUTPUT_COUNT(_fp) \
((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
extern void _IO_flockfile __P ((_IO_FILE *));
extern void _IO_funlockfile __P ((_IO_FILE *));
extern int _IO_ftrylockfile __P ((_IO_FILE *));
#ifndef _IO_MTSAFE_IO
# define _IO_flockfile(_fp) /**/
# define _IO_funlockfile(_fp) /**/
# define _IO_ftrylockfile(_fp) /**/
# define _IO_cleanup_region_start(_fct, _fp) /**/
# define _IO_cleanup_region_end(_Doit) /**/
#endif /* !_IO_MTSAFE_IO */
#define _IO_peekc(_fp) _IO_peekc_locked (_fp)
extern int _IO_vfscanf __P((_IO_FILE*, const char*, _IO_va_list, int*));
extern int _IO_vfprintf __P((_IO_FILE*, const char*, _IO_va_list));
extern _IO_ssize_t _IO_padn __P((_IO_FILE *, int, _IO_ssize_t));

View File

@ -1,31 +1,37 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include <errno.h>
#ifndef errno
extern int errno;
#endif
#ifndef __set_errno
/* This is a GNU libc special. Simply set errno to the given value here. */
#define __set_errno(Val) (errno = (Val))
#endif
#include <stdio-lock.h>
#include "iolibio.h"
@ -100,8 +106,8 @@ extern "C" {
/* The 'finish' function does any final cleaning up of an _IO_FILE object.
It does not delete (free) it, but does everything else to finalize it/
It matches the streambuf::~streambuf virtual destructor. */
typedef void (*_IO_finish_t) __P((_IO_FILE*)); /* finalize */
#define _IO_FINISH(FP) JUMP0(__finish, FP)
typedef void (*_IO_finish_t) __P((_IO_FILE*, int)); /* finalize */
#define _IO_FINISH(FP) JUMP1(__finish, FP, 0)
/* The 'overflow' hook flushes the buffer.
The second argument is a character, or EOF.
@ -266,6 +272,9 @@ struct _IO_FILE_plus {
/* Generic functions */
extern _IO_fpos_t _IO_seekoff __P((_IO_FILE*, _IO_off_t, int, int));
extern _IO_fpos_t _IO_seekpos __P((_IO_FILE*, _IO_fpos_t, int));
extern int _IO_switch_to_get_mode __P((_IO_FILE*));
extern void _IO_init __P((_IO_FILE*, int));
extern int _IO_sputbackc __P((_IO_FILE*, int));
@ -291,7 +300,7 @@ extern int _IO_seekmark __P((_IO_FILE *, struct _IO_marker *, int));
extern int _IO_default_underflow __P((_IO_FILE*));
extern int _IO_default_uflow __P((_IO_FILE*));
extern int _IO_default_doallocate __P((_IO_FILE*));
extern void _IO_default_finish __P((_IO_FILE *));
extern void _IO_default_finish __P((_IO_FILE *, int));
extern int _IO_default_pbackfail __P((_IO_FILE*, int));
extern _IO_FILE* _IO_default_setbuf __P((_IO_FILE *, char*, _IO_ssize_t));
extern _IO_size_t _IO_default_xsputn __P((_IO_FILE *, const void*, _IO_size_t));
@ -347,7 +356,7 @@ extern _IO_ssize_t _IO_file_read __P((_IO_FILE*, void*, _IO_ssize_t));
extern int _IO_file_sync __P((_IO_FILE*));
extern int _IO_file_close_it __P((_IO_FILE*));
extern _IO_fpos_t _IO_file_seek __P((_IO_FILE *, _IO_off_t, int));
extern void _IO_file_finish __P((_IO_FILE*));
extern void _IO_file_finish __P((_IO_FILE*, int));
/* Other file functions. */
extern _IO_FILE* _IO_file_attach __P((_IO_FILE *, int));
@ -361,12 +370,20 @@ extern int _IO_str_underflow __P((_IO_FILE*));
extern int _IO_str_overflow __P((_IO_FILE *, int));
extern int _IO_str_pbackfail __P((_IO_FILE*, int));
extern _IO_fpos_t _IO_str_seekoff __P((_IO_FILE*,_IO_off_t,int,int));
extern void _IO_str_finish __P ((_IO_FILE*, int));
/* Other strfile functions */
extern void _IO_str_init_static __P((_IO_FILE *, char*, int, char*));
extern void _IO_str_init_readonly __P((_IO_FILE *, const char*, int));
extern _IO_ssize_t _IO_str_count __P ((_IO_FILE*));
extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
_IO_va_list args));
extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
__const char *format, _IO_va_list args));
extern _IO_size_t _IO_getline __P((_IO_FILE*,char*,_IO_size_t,int,int));
extern _IO_ssize_t _IO_getdelim __P((char**, _IO_size_t*, int, _IO_FILE*));
extern double _IO_strtod __P((const char *, char **));
@ -394,8 +411,52 @@ extern void (*_IO_cleanup_registration_needed) __P ((void));
#endif
#endif
#define FREE_BUF(_B) free(_B)
#define ALLOC_BUF(_S) (char*)malloc(_S)
#if _G_HAVE_MMAP
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/param.h>
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON
#endif
#if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
#undef _G_HAVE_MMAP
#define _G_HAVE_MMAP 0
#endif
#endif /* _G_HAVE_MMAP */
#if _G_HAVE_MMAP
#define ROUND_TO_PAGE(_S) \
(((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
#define FREE_BUF(_B, _S) \
munmap ((_B), ROUND_TO_PAGE (_S))
#define ALLOC_BUF(_B, _S, _R) \
do { \
(_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
PROT_READ | PROT_WRITE, \
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
if ((_B) == (char *) -1) \
return _R; \
} while (0)
#else /* _G_HAVE_MMAP */
#define FREE_BUF(_B, _S) \
free(_B)
#define ALLOC_BUF(_B, _S, _R) \
do { \
(_B) = (char*)malloc(_S); \
if ((_B) == NULL) \
return _R; \
} while (0)
#endif /* _G_HAVE_MMAP */
#ifndef OS_FSTAT
#define OS_FSTAT fstat
@ -433,10 +494,18 @@ extern int _IO_fstat __P((int, struct stat *));
}
#endif
#ifdef _IO_MTSAFE_IO
/* check following! */
#define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
0, 0, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
#else
/* check following! */
#define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD}
#endif
/* VTABLE_LABEL defines NAME as of the CLASS class.
CNLENGTH is strlen(#CLASS). */
@ -480,7 +549,7 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
#endif
#ifdef EINVAL
#define MAYBE_SET_EINVAL errno = EINVAL
#define MAYBE_SET_EINVAL __set_errno (EINVAL)
#else
#define MAYBE_SET_EINVAL /* nothing */
#endif
@ -490,7 +559,7 @@ extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
else { COERCE_FILE(FILE); \
if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
{ errno = EINVAL; return RET; }}
{ MAYBE_SET_EINVAL; return RET; }}
#else
#define CHECK_FILE(FILE,RET) \
COERCE_FILE(FILE)

View File

@ -137,7 +137,7 @@ general_parsebuf::general_parsebuf(streambuf *buf, int delete_arg_buf)
delete_buf = delete_arg_buf;
sbuf = buf;
int buf_size = 128;
char* buffer = ALLOC_BUF(buf_size);
char* buffer = (char*)malloc(buf_size);
setb(buffer, buffer+buf_size, 1);
// setg(buffer, buffer, buffer);
}

42
libio/peekc.c Normal file
View File

@ -0,0 +1,42 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef _IO_peekc
int
_IO_peekc_locked (fp)
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_peekc_unlocked (fp);
_IO_cleanup_region_end (1);
return result;
}

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993, 1994 Free Software Foundation
/* Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
/* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
@ -31,10 +32,16 @@ the executable file might be covered by the GNU General Public License. */
#include "libioP.h"
#ifdef _IO_MTSAFE_IO
#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
struct _IO_FILE_plus NAME \
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}
#else
#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
struct _IO_FILE_plus NAME \
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}
#endif
DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS);

1
libio/stdio-lock.h Normal file
View File

@ -0,0 +1 @@
/* this will be used later*/

View File

@ -1,3 +1,44 @@
1997-09-04 16:11 Ulrich Drepper <drepper@cygnus.com>
* Makefile.in (STDIO_OBJECTS): Lose feof.o and ferror.o. Add getc.o
and putc.o.
(stmp-libio, stmp-libiostream, stmp-io, stmp-streamlib): New rules.
(iostream.list): Depend upon stmp-stdio. Add the entries
from stdio.list to iostream.list.
(stmp-stdio): New name for what was the stdio/stdio.list rule.
All it now does is cd down into stdio and build stdio.list.
* clearerr.c: Add copyright and lock stream before use.
* feof.c: Likewise.
* ferror.c: Likewise.
* fgetc.c: Likewise.
* fputc.c: Likewise.
* freopen.c: Likewise.
* fseek.c: Likewise.
* getc.c: Likewise.
* getchar.c: Likewise.
* putc.c: Likewise.
* putchar.c: Likewise.
* rewind.c: Likewise.
* setbuf.c: Update copyright.
* setlinebuf.c: Likewise.
* vscanf.c: Likewise.
* fileno.c: Define alias fileno_unlocked. Update copyright.
* clearerr_u.c: New file. Implement clearerr_unlocked function.
* feof_u.c: New file. Implement feof_unlocked function.
* ferror_u.c: New file. Implement ferror_unlocked function.
* fputc_u.c: New file. Implement fputc_unlocked function.
* getc_u.c: New file. Implement getc_unclocked function.
* getchar_u.c: New file. Implement getchar_unclocked function.
* putc_u.c: New file. Implement putc_unclocked function.
* putchar_u.c: New file. Implement putchar_unclocked function.
* vsnprintf.c: Rewrite according to ISO C 9X draft.
Thu May 1 11:03:45 1997 Brendan Kehoe <brendan@lisa.cygnus.com>
* stdio.h (TMP_MAX): Wrap it with #ifndef for now, since it can

View File

@ -7,9 +7,9 @@ srcdir = .
STDIO_RENAMED_OBJECTS = ... filled in by configure ...
# These are the files that a libc would want.
STDIO_OBJECTS = $(STDIO_RENAMED_OBJECTS) \
clearerr.o fdopen.o feof.o ferror.o fgetc.o fileno.o \
fputc.o freopen.o fseek.o getc.o getchar.o getline.o getw.o \
popen.o putc.o putchar.o putw.o rewind.o \
clearerr.o fdopen.o fgetc.o fileno.o \
fputc.o freopen.o fseek.o getchar.o getline.o getw.o \
popen.o putchar.o putw.o rewind.o \
setbuf.o setfileno.o setlinebuf.o snprintf.o \
vfprintf.o vfscanf.o vprintf.o vscanf.o vsnprintf.o
@ -18,6 +18,18 @@ CINCLUDES = -I. -I$(srcdir) -I.. -I$(srcdir)/.. -D__USE_GNU
nothing:
stmp-libio: stdio.list stamp-io
stamp-io:
$(AR) $(AR_FLAGS) ../libio.a $(STDIO_OBJECTS)
touch stmp-io
stmp-libiostream: stdio.list stamp-streamlib
stamp-streamlib:
$(AR) $(AR_FLAGS) ../libiostream.a $(STDIO_OBJECTS)
touch stmp-streamlib
stdio.list: stamp-picdir $(STDIO_OBJECTS)
@echo "$(STDIO_OBJECTS)" >stdio.list

View File

@ -1,10 +1,30 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "libioP.h"
#include "stdio.h"
void
clearerr(fp)
FILE* fp;
clearerr (fp)
FILE *fp;
{
CHECK_FILE(fp, /*nothing*/);
_IO_clearerr(fp);
CHECK_FILE (fp, /*nothing*/);
_IO_flockfile (fp);
_IO_clearerr (fp);
_IO_funlockfile (fp);
}

28
libio/stdio/clearerr_u.c Normal file
View File

@ -0,0 +1,28 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "libioP.h"
#include "stdio.h"
void
clearerr_unlocked (fp)
FILE *fp;
{
CHECK_FILE (fp, /*nothing*/);
_IO_clearerr (fp);
}

37
libio/stdio/feof_u.c Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef feof_unlocked
int
feof_unlocked (fp)
_IO_FILE* fp;
{
CHECK_FILE (fp, EOF);
return _IO_feof_unlocked (fp);
}

37
libio/stdio/ferror_u.c Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef ferror_unlocked
int
ferror_unlocked (fp)
_IO_FILE* fp;
{
CHECK_FILE (fp, EOF);
return _IO_ferror_unlocked (fp);
}

View File

@ -1,10 +1,40 @@
/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
fgetc(fp)
fgetc (fp)
FILE *fp;
{
CHECK_FILE(fp, EOF);
return _IO_getc(fp);
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_getc_unlocked (fp);
_IO_cleanup_region_end (1);
return result;
}

View File

@ -1,12 +1,49 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
fileno(fp)
fileno (fp)
_IO_FILE* fp;
{
CHECK_FILE(fp, EOF);
CHECK_FILE (fp, EOF);
if (!(fp->_flags & _IO_IS_FILEBUF))
return EOF;
return _IO_fileno(fp);
return _IO_fileno (fp);
}
#ifdef _IO_MTSAFE_IO
#ifdef weak_alias
/* The fileno implementation for libio does not require locking because
it only accesses once a single variable and this is already atomic
(at least at thread level). */
weak_alias (fileno, fileno_unlocked)
#endif
#endif

View File

@ -1,11 +1,41 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
fputc(c, fp)
fputc (c, fp)
int c;
FILE *fp;
_IO_FILE *fp;
{
CHECK_FILE(fp, EOF);
return _IO_putc(c, fp);
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_putc_unlocked (c, fp);
_IO_cleanup_region_end (1);
return result;
}

38
libio/stdio/fputc_u.c Normal file
View File

@ -0,0 +1,38 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef fputc_unlocked
int
fputc_unlocked (c, fp)
int c;
_IO_FILE *fp;
{
CHECK_FILE (fp, EOF);
return _IO_putc_unlocked (c, fp);
}

View File

@ -1,14 +1,44 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
FILE*
freopen(filename, mode, fp)
freopen (filename, mode, fp)
const char* filename;
const char* mode;
FILE* fp;
{
CHECK_FILE(fp, NULL);
FILE *result;
CHECK_FILE (fp, NULL);
if (!(fp->_flags & _IO_IS_FILEBUF))
return NULL;
return _IO_freopen(filename, mode, fp);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_freopen (filename, mode, fp);
_IO_cleanup_region_end (1);
return result;
}

View File

@ -1,12 +1,42 @@
#include "stdio.h"
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
fseek(fp, offset, whence)
fseek (fp, offset, whence)
_IO_FILE* fp;
long int offset;
int whence;
{
CHECK_FILE(fp, -1);
return _IO_fseek(fp, offset, whence);
int result;
CHECK_FILE (fp, -1);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_fseek (fp, offset, whence);
_IO_cleanup_region_end (1);
return result;
}

37
libio/stdio/getc_u.c Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef getc_unlocked
int
getc_unlocked (fp)
FILE *fp;
{
CHECK_FILE (fp, EOF);
return _IO_getc_unlocked (fp);
}

View File

@ -1,3 +1,28 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
@ -6,5 +31,10 @@
int
getchar ()
{
return _IO_getc (stdin);
int result;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, stdin);
_IO_flockfile (stdin);
result = _IO_getc_unlocked (stdin);
_IO_cleanup_region_end (1);
return result;
}

35
libio/stdio/getchar_u.c Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef getchar_unlocked
int
getchar_unlocked ()
{
return _IO_getc_unlocked (stdin);
}

31
libio/stdio/putc_u.c Normal file
View File

@ -0,0 +1,31 @@
/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "libioP.h"
#include "stdio.h"
#undef putc_unlocked
int
putc_unlocked (c, fp)
int c;
_IO_FILE *fp;
{
CHECK_FILE (fp, EOF);
return _IO_putc_unlocked (c, fp);
}

View File

@ -1,10 +1,35 @@
/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "libioP.h"
#include "stdio.h"
#undef putchar
int
putchar(c)
putchar (c)
int c;
{
return _IO_putc(c, stdout);
int result;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
_IO_stdout);
_IO_flockfile (_IO_stdout);
result = _IO_putc_unlocked (c, _IO_stdout);
_IO_cleanup_region_end (1);
return result;
}

30
libio/stdio/putchar_u.c Normal file
View File

@ -0,0 +1,30 @@
/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "libioP.h"
#include "stdio.h"
#undef putchar_unlocked
int
putchar_unlocked (c)
int c;
{
CHECK_FILE (stdout, EOF);
return _IO_putc_unlocked (c, stdout);
}

View File

@ -1,10 +1,38 @@
#include "stdio.h"
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
void
rewind(fp)
_IO_FILE* fp;
rewind (fp)
_IO_FILE *fp;
{
CHECK_FILE(fp, );
_IO_rewind(fp);
CHECK_FILE (fp, );
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
_IO_rewind (fp);
_IO_cleanup_region_end (1);
}

View File

@ -1,9 +1,35 @@
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
void
setbuf (fp, buf)
FILE *fp; char *buf;
_IO_FILE *fp;
char *buf;
{
_IO_setbuffer(fp, buf, _IO_BUFSIZ);
_IO_setbuffer (fp, buf, _IO_BUFSIZ);
}

View File

@ -1,3 +1,28 @@
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
@ -5,7 +30,7 @@
void
setlinebuf (stream)
FILE *stream;
_IO_FILE *stream;
{
_IO_setvbuf(stream, NULL, 1, 0);
_IO_setvbuf (stream, NULL, 1, 0);
}

View File

@ -1,34 +1,41 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef vscanf
int
vscanf(format, args)
_IO_vscanf (format, args)
const char *format;
_IO_va_list args;
{
return _IO_vfscanf(_IO_stdin, format, args, NULL);
return _IO_vfscanf (_IO_stdin, format, args, NULL);
}
#ifdef weak_alias
weak_alias (_IO_vscanf, vscanf)
#endif

View File

@ -1,43 +1,136 @@
/*
Copyright (C) 1994 Free Software Foundation
/* Copyright (C) 1994, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "strfile.h"
typedef struct
{
_IO_strfile f;
/* This is used for the characters which do not fit in the buffer
provided by the user. */
char overflow_buf[64];
} _IO_strnfile;
static int _IO_strn_overflow __P ((_IO_FILE *fp, int c));
static int
_IO_strn_overflow (fp, c)
_IO_FILE *fp;
int c;
{
/* When we come to here this means the user supplied buffer is
filled. But since we must return the number of characters which
would have been written in total we must provide a buffer for
further use. We can do this by writing on and on in the overflow
buffer in the _IO_strnfile structure. */
_IO_strnfile *snf = (_IO_strnfile *) fp;
if (fp->_IO_buf_base != snf->overflow_buf)
{
/* Terminate the string. We know that there is room for at
least one more character since we initialized the stream with
a size to make this possible. */
*fp->_IO_write_ptr = '\0';
_IO_setb (fp, snf->overflow_buf,
snf->overflow_buf + sizeof (snf->overflow_buf), 0);
fp->_IO_write_base = snf->overflow_buf;
fp->_IO_read_base = snf->overflow_buf;
fp->_IO_read_ptr = snf->overflow_buf;
fp->_IO_read_end = snf->overflow_buf + sizeof (snf->overflow_buf);
}
fp->_IO_write_ptr = snf->overflow_buf;
fp->_IO_write_end = snf->overflow_buf;
/* Since we are not really interested in storing the characters
which do not fit in the buffer we simply ignore it. */
return c;
}
static struct _IO_jump_t _IO_strn_jumps =
{
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_str_finish),
JUMP_INIT(overflow, _IO_strn_overflow),
JUMP_INIT(underflow, _IO_str_underflow),
JUMP_INIT(uflow, _IO_default_uflow),
JUMP_INIT(pbackfail, _IO_str_pbackfail),
JUMP_INIT(xsputn, _IO_default_xsputn),
JUMP_INIT(xsgetn, _IO_default_xsgetn),
JUMP_INIT(seekoff, _IO_str_seekoff),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, _IO_default_setbuf),
JUMP_INIT(sync, _IO_default_sync),
JUMP_INIT(doallocate, _IO_default_doallocate),
JUMP_INIT(read, _IO_default_read),
JUMP_INIT(write, _IO_default_write),
JUMP_INIT(seek, _IO_default_seek),
JUMP_INIT(close, _IO_default_close),
JUMP_INIT(stat, _IO_default_stat)
};
int
vsnprintf (string, maxlen, format, args)
_IO_vsnprintf (string, maxlen, format, args)
char *string;
_IO_size_t maxlen;
const char *format;
_IO_va_list args;
{
_IO_strfile sf;
_IO_strnfile sf;
int ret;
_IO_init((_IO_FILE*)&sf, 0);
_IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps;
_IO_str_init_static ((_IO_FILE*)&sf, string, maxlen - 1, string);
ret = _IO_vfprintf((_IO_FILE*)&sf, format, args);
*((_IO_FILE*)&sf)->_IO_write_ptr = '\0';
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
sf.f._sbf._f._lock = &lock;
#endif
/* We need to handle the special case where MAXLEN is 0. Use the
overflow buffer right from the start. */
if (maxlen == 0)
{
string = sf.overflow_buf;
maxlen = sizeof (sf.overflow_buf);
}
_IO_init ((_IO_FILE *) &sf, 0);
_IO_JUMPS ((_IO_FILE *) &sf) = &_IO_strn_jumps;
_IO_str_init_static ((_IO_FILE *) &sf, string, maxlen - 1, string);
ret = _IO_vfprintf ((_IO_FILE *) &sf, format, args);
if (sf.f._sbf._f._IO_buf_base != sf.overflow_buf)
*sf.f._sbf._f._IO_write_ptr = '\0';
return ret;
}
#ifdef weak_alias
weak_alias (_IO_vsnprintf, __vsnprintf)
weak_alias (_IO_vsnprintf, vsnprintf)
#endif

View File

@ -213,7 +213,7 @@ streambuf::streambuf(int flags)
#endif
}
streambuf::~streambuf() { _IO_default_finish(this); }
streambuf::~streambuf() { _IO_default_finish(this,0); }
streampos
streambuf::seekoff(streamoff, _seek_dir, int /*=ios::in|ios::out*/)

View File

@ -138,7 +138,7 @@ class ios : public _ios_fields {
bin = _IOS_BIN, // Deprecated - ANSI uses ios::binary.
binary = _IOS_BIN };
enum seek_dir { beg, cur, end};
// ANSI: typedef enum seek_dir seekdir; etc
typedef enum seek_dir seekdir;
// NOTE: If adding flags here, before to update ios::bitalloc().
enum { skipws=_IO_SKIPWS,
left=_IO_LEFT, right=_IO_RIGHT, internal=_IO_INTERNAL,

View File

@ -1,34 +1,35 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include <libio.h>
#ifdef TODO
Merge into libio.h ?
#endif
typedef void *(*_IO_alloc_type) __P((_IO_size_t));
typedef void (*_IO_free_type) __P((void*));
typedef void *(*_IO_alloc_type) __P ((_IO_size_t));
typedef void (*_IO_free_type) __P ((void*));
struct _IO_str_fields
{

View File

@ -1,26 +1,27 @@
/*
Copyright (C) 1993 Free Software Foundation
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "strfile.h"
#include "libioP.h"
@ -28,7 +29,7 @@ the executable file might be covered by the GNU General Public License. */
#if 0
/* The following definitions are for exposition only.
They map the terminlogy used in the ANSI/ISO C++ draft standard
They map the terminology used in the ANSI/ISO C++ draft standard
to the implementation. */
/* allocated: set when a dynamic array object has been allocated, and
@ -59,16 +60,19 @@ the executable file might be covered by the GNU General Public License. */
#endif
void
DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
_IO_FILE *fp AND char *ptr AND int size AND char *pstart)
_IO_str_init_static (fp, ptr, size, pstart)
_IO_FILE *fp;
char *ptr;
int size;
char *pstart;
{
if (size == 0)
size = strlen(ptr);
size = strlen (ptr);
else if (size < 0)
{
/* If size is negative 'the characters are assumed to
continue indefinitely.' This is kind of messy ... */
_G_int32_t s;
int s;
size = 512;
/* Try increasing powers of 2, as long as we don't wrap around. */
for (; s = 2*size, s > 0 && ptr + s > ptr && s < 0x4000000L; )
@ -80,7 +84,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
size += s;
}
}
_IO_setb(fp, ptr, ptr+size, 0);
_IO_setb (fp, ptr, ptr + size, 0);
fp->_IO_write_base = ptr;
fp->_IO_read_base = ptr;
@ -88,7 +92,7 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
if (pstart)
{
fp->_IO_write_ptr = pstart;
fp->_IO_write_end = ptr+size;
fp->_IO_write_end = ptr + size;
fp->_IO_read_end = pstart;
}
else
@ -98,20 +102,23 @@ DEFUN(_IO_str_init_static, (fp, ptr, size, pstart),
fp->_IO_read_end = ptr+size;
}
/* A null _allocate_buffer function flags the strfile as being static. */
(((_IO_strfile*)(fp))->_s._allocate_buffer) = (_IO_alloc_type)0;
(((_IO_strfile *) fp)->_s._allocate_buffer) = (_IO_alloc_type)0;
}
void
DEFUN(_IO_str_init_readonly, (fp, ptr, size),
_IO_FILE *fp AND const char *ptr AND int size)
_IO_str_init_readonly (fp, ptr, size)
_IO_FILE *fp;
const char *ptr;
int size;
{
_IO_str_init_static (fp, (char*)ptr, size, NULL);
_IO_str_init_static (fp, (char *) ptr, size, NULL);
fp->_IO_file_flags |= _IO_NO_WRITES;
}
int
DEFUN(_IO_str_overflow, (fp, c),
register _IO_FILE* fp AND int c)
_IO_str_overflow (fp, c)
_IO_FILE *fp;
int c;
{
int flush_only = c == EOF;
_IO_size_t pos;
@ -124,7 +131,7 @@ DEFUN(_IO_str_overflow, (fp, c),
fp->_IO_read_ptr = fp->_IO_read_end;
}
pos = fp->_IO_write_ptr - fp->_IO_write_base;
if (pos >= _IO_blen(fp) + flush_only)
if (pos >= (_IO_size_t) (_IO_blen (fp) + flush_only))
{
if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */
return EOF;
@ -132,9 +139,9 @@ DEFUN(_IO_str_overflow, (fp, c),
{
char *new_buf;
char *old_buf = fp->_IO_buf_base;
_IO_size_t new_size = 2 * _IO_blen(fp) + 100;
_IO_size_t new_size = 2 * _IO_blen (fp) + 100;
new_buf
= (char*)(*((_IO_strfile*)fp)->_s._allocate_buffer)(new_size);
= (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size);
if (new_buf == NULL)
{
/* __ferror(fp) = 1; */
@ -142,16 +149,16 @@ DEFUN(_IO_str_overflow, (fp, c),
}
if (fp->_IO_buf_base)
{
memcpy(new_buf, old_buf, _IO_blen(fp));
(*((_IO_strfile*)fp)->_s._free_buffer)(fp->_IO_buf_base);
memcpy (new_buf, old_buf, _IO_blen (fp));
(*((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base);
/* Make sure _IO_setb won't try to delete _IO_buf_base. */
fp->_IO_buf_base = NULL;
}
#if 0
if (lenp == &LEN(fp)) /* use '\0'-filling */
memset(new_buf + pos, 0, blen() - pos);
memset (new_buf + pos, 0, blen() - pos);
#endif
_IO_setb(fp, new_buf, new_buf + new_size, 1);
_IO_setb (fp, new_buf, new_buf + new_size, 1);
fp->_IO_read_base = new_buf + (fp->_IO_read_base - old_buf);
fp->_IO_read_ptr = new_buf + (fp->_IO_read_ptr - old_buf);
fp->_IO_read_end = new_buf + (fp->_IO_read_end - old_buf);
@ -170,8 +177,8 @@ DEFUN(_IO_str_overflow, (fp, c),
}
int
DEFUN(_IO_str_underflow, (fp),
register _IO_FILE* fp)
_IO_str_underflow (fp)
_IO_FILE *fp;
{
if (fp->_IO_write_ptr > fp->_IO_read_end)
fp->_IO_read_end = fp->_IO_write_ptr;
@ -190,19 +197,22 @@ DEFUN(_IO_str_underflow, (fp),
/* The size of the valid part of the buffer. */
_IO_ssize_t
DEFUN(_IO_str_count, (fp),
register _IO_FILE *fp)
_IO_str_count (fp)
_IO_FILE *fp;
{
return (fp->_IO_write_ptr > fp->_IO_read_end ? fp->_IO_write_ptr
: fp->_IO_read_end)
- fp->_IO_read_base;
}
return ((fp->_IO_write_ptr > fp->_IO_read_end
? fp->_IO_write_ptr : fp->_IO_read_end)
- fp->_IO_read_base);
}
_IO_pos_t
DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
register _IO_FILE *fp AND _IO_off_t offset AND int dir AND int mode)
_IO_str_seekoff (fp, offset, dir, mode)
_IO_FILE *fp;
_IO_off_t offset;
int dir;
int mode;
{
_IO_ssize_t cur_size = _IO_str_count(fp);
_IO_ssize_t cur_size = _IO_str_count (fp);
_IO_pos_t new_pos = EOF;
/* Move the get pointer, if requested. */
@ -219,7 +229,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
default: /* case _IO_seek_set: */
break;
}
if (offset < 0 || (_IO_size_t)offset > cur_size)
if (offset < 0 || (_IO_ssize_t) offset > cur_size)
return EOF;
fp->_IO_read_ptr = fp->_IO_read_base + offset;
fp->_IO_read_end = fp->_IO_read_base + cur_size;
@ -240,7 +250,7 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
default: /* case _IO_seek_set: */
break;
}
if (offset < 0 || (_IO_size_t)offset > cur_size)
if (offset < 0 || (_IO_ssize_t) offset > cur_size)
return EOF;
fp->_IO_write_ptr = fp->_IO_write_base + offset;
new_pos = offset;
@ -249,26 +259,29 @@ DEFUN(_IO_str_seekoff, (fp, offset, dir, mode),
}
int
DEFUN(_IO_str_pbackfail, (fp, c),
register _IO_FILE *fp AND int c)
_IO_str_pbackfail (fp, c)
_IO_FILE *fp;
int c;
{
if ((fp->_flags & _IO_NO_WRITES) && c != EOF)
return EOF;
return _IO_default_pbackfail(fp, c);
return _IO_default_pbackfail (fp, c);
}
void
DEFUN (_IO_str_finish, (fp),
register _IO_FILE* fp)
_IO_str_finish (fp, dummy)
_IO_FILE *fp;
int dummy;
{
if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
(((_IO_strfile*)fp)->_s._free_buffer)(fp->_IO_buf_base);
(((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base);
fp->_IO_buf_base = NULL;
_IO_default_finish(fp);
_IO_default_finish (fp, 0);
}
struct _IO_jump_t _IO_str_jumps = {
struct _IO_jump_t _IO_str_jumps =
{
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_str_finish),
JUMP_INIT(overflow, _IO_str_overflow),