Commit 3df1453d by Mark Mitchell

Remove libio

From-SVN: r39453
parent 39d6f2e8
This source diff could not be displayed because it is too large. You can view the blob instead.
# Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation
#
# This file is part of the GNU IO Library. This library is free
# software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library; see the file COPYING. If not, write to the Free
# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
srcdir = .
VERSION = 2.8.0
# The config file (overriden by Linux).
_G_CONFIG_H=_G_config.h
tooldir = $(exec_prefix)/$(target)
INSTALLDIR = $(libdir)
gxx_include_dir=${includedir}/g++
IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \
iovfprintf.o \
iovfscanf.o ioignore.o iopadn.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 peekc.o iogetc.o \
ioputc.o iofeof.o ioferror.o
STDIO_OBJECTS = stdfiles.o
# These emulate stdio functionality, but with a different name (_IO_ungetc
# instead of ungetc), and using _IO_FILE instead of FILE.
# They are not needed for C++ iostream, nor stdio, though some stdio
# files are build using the same source files (see stdio/configure.in).
# They are needed for iostdio.h. They are needed under Linux to avoid
# version incompatibility problems with the C library.
# 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 iovsscanf.o iovsprintf.o
IOSTREAM_OBJECTS = builtinbuf.o filebuf.o fstream.o \
indstream.o ioassign.o ioextend.o iomanip.o iostream.o \
isgetline.o isgetsb.o isscan.o \
osform.o procbuf.o sbform.o sbgetline.o sbscan.o \
stdiostream.o stdstrbufs.o stdstreams.o stream.o streambuf.o strstream.o \
PlotFile.o SFile.o parsestream.o pfstream.o editbuf.o
# These files define _IO_read etc, which are just wrappers for read(2) etc.
# They need to be changed to use name-space-clean (e.g. __read) versions
# for each specific libc.
OSPRIM_OBJECTS = ioprims.o iostrerror.o cleanup.o
LIBIOSTREAM_OBJECTS = $(IO_OBJECTS) $(IOSTREAM_OBJECTS) $(OSPRIM_OBJECTS)
LIBIO_OBJECTS = $(IO_OBJECTS) $(STDIO_WRAP_OBJECTS) $(OSPRIM_OBJECTS) \
$(STDIO_OBJECTS)
LIBIOSTREAM_DEP = $(LIBIOSTREAM_OBJECTS)
LIBIOSTREAM_USE = $(LIBIOSTREAM_OBJECTS)
USER_INCLUDES = *.h
PICFLAG =
#### package, host, target, and site dependent Makefile fragments come in here.
##
$(LIBIO_OBJECTS): $(_G_CONFIG_H)
libio.a: $(_G_CONFIG_H) $(LIBIO_OBJECTS)
-rm -rf libio.a
$(AR) $(AR_FLAGS) libio.a $(LIBIO_OBJECTS)
$(RANLIB) libio.a
libiostream.a: $(_G_CONFIG_H) $(LIBIOSTREAM_DEP)
-rm -rf libiostream.a
$(AR) $(AR_FLAGS) libiostream.a $(LIBIOSTREAM_USE)
$(RANLIB) libiostream.a
test: test.o libio.a
$(CC) $(CFLAGS) -o test test.o libio.a
tpipe: tpipe.o libio.a
$(CC) $(CFLAGS) -o tpipe tpipe.o libio.a
iostream.list: $(_G_CONFIG_H) $(LIBIOSTREAM_DEP)
@echo "$(LIBIOSTREAM_USE)"> iostream.list
# The "pic" subdir must be created before we can put any object
# files into it.
$(LIBIOSTREAM_DEP) $(LIBIO_OBJECTS): stamp-picdir
stmp-stdio:
@rootme=`pwd`/ ; export rootme; cd stdio ; \
$(MAKE) $(FLAGS_TO_PASS) stdio.list
_G_config.h: ${srcdir}/gen-params
rootme=`pwd`/ ; export rootme; \
CC="$(CC) $(CINCLUDES)"; export CC; \
CXX="$(CXX) $(CXXINCLUDES) $(NOSTDINC) $(CXXFLAGS)"; export CXX; \
CONFIG_NM="$(NM)"; export CONFIG_NM; \
$(SHELL) ${srcdir}/gen-params LIB_VERSION=$(VERSION) $(G_CONFIG_ARGS) >tmp-params.h
mv tmp-params.h _G_config.h
install:
rootme=`pwd`/ ; export rootme ; \
if [ -z "$(MULTISUBDIR)" ]; then \
if [ "$(_G_CONFIG_H)" != "" ]; then \
if [ x$(enable_version_specific_runtime_libs) = xyes ]; then \
rm -f $(gxx_include_dir)/_G_config.h ; \
$(INSTALL_DATA) _G_config.h $(gxx_include_dir)/_G_config.h || exit 1; \
else \
rm -f $(tooldir)/include/_G_config.h ; \
$(INSTALL_DATA) _G_config.h $(tooldir)/include/_G_config.h || exit 1; \
fi; \
else true; \
fi ; \
cd $(srcdir); \
for FILE in $(USER_INCLUDES); do if [ $$FILE != _G_config.h ]; then \
rm -f $(gxx_include_dir)/$$FILE ; \
$(INSTALL_DATA) $$FILE $(gxx_include_dir)/$$FILE ; \
chmod a-x $(gxx_include_dir)/$$FILE ; \
else true; fi; done ; \
else true; \
fi
@rootme=`pwd`/ ; export rootme ; \
$(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=install
c++clean:
rm -rf $(IOSTREAM_OBJECTS)
@$(MAKE) $(FLAGS_TO_PASS) "DODIRS=tests" DO=clean subdir_do
*** Major changes in libio for egcs:
* Better support for Linux.
* Dejagnu testsuite.
*** Major changes in libio version 2.7.0:
* The data representations of _IO_FILE and streambufs have been modified.
The layout of the jump-table table _IO_jumps_t has been re-arranged
to match that of a virtual function table of a streambuf. Therefore,
we no longer need a separate _IO_FILE::_jumps pointer; instead it can
be shared with the virtual function table pointer. In addition to
saving space, this also removes the overhead when double indirection
was needed, and there are many simplificatons (e.g. we no longer need
the builtinbuf class.
* The streambuf::uflow virtual has been added, to match the standard.
* The ifstream, ofstream, and fstream classes now include the filebuf
as a member, rather than being pointed to it. Various related changes.
* Version number changed to generally follow libg++ (and gcc).
*** Major changes in libio version 0.66 (released with libg++ 2.6.1):
* Some documentation and an example in iostream.texi on how to derive
your own class from streambuf.
* New functions added to stdio: getline, detdelim, snprintf, vsnprintf.
This is for compatibility with the GNU C library.
*** Major changes in libio version 0.65 (released with libg++ 2.6):
* _IO_getline and streambuf::sgetline no longer write a '\0' at the end.
* A number of improvements to get closer to the ANSI/ISO C++ working
paper, such as:
- Added (preliminary support for) new ANSI streambuf::uflow virtual.
- Added istdiostream and ostdiostream classes.
- Added ostream::operator<<(bool) and istream::operator>>(bool&).
* More robust (and faster) initialization and cleanup of standard streambufs.
* Many small bug fixes, portability improvements, and random enhancements.
*** Major changes in libio version 0.63 (released with libg++ 2.5.3):
* There is a g++ bug that causes inconsistent name mangling for the
assembler name of the virtual function table for the istream class.
A work-around has been put into streambuf.h, which will make g++
always do the right thing. Note that this may require you to
recompile programs that were incorrectly compiled by g++.
* Functions that do printf-style formatting to the unbuffered
streams have been optimized to write to a temporary buffer.
/*
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
// This may look like C code, but it is really -*- C++ -*-
/*
Copyright (C) 1988, 1992, 1993 Free Software Foundation
written by Doug Lea (dl@rocky.oswego.edu)
converted to use iostream library 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 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 GCC 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 __GNUG__
#pragma implementation
#endif
#include <PlotFile.h>
/*
PlotFile implementation module
*/
PlotFile& PlotFile:: cmd(char c)
{
ofstream::put(c);
return *this;
}
PlotFile& PlotFile:: operator<<(const int x)
{
#if defined(convex)
ofstream::put((char)(x>>8));
ofstream::put((char)(x&0377));
#else
ofstream::put((char)(x&0377));
ofstream::put((char)(x>>8));
#endif
return *this;
}
PlotFile& PlotFile:: operator<<(const char *s)
{
*(ofstream*)this << s;
return *this;
}
PlotFile& PlotFile:: arc(const int xi, const int yi,
const int x0, const int y0,
const int x1, const int y1)
{
return cmd('a') << xi << yi << x0 << y0 << x1 << y1;
}
PlotFile& PlotFile:: box(const int x0, const int y0,
const int x1, const int y1)
{
line(x0, y0, x0, y1);
line(x0, y1, x1, y1);
line(x1, y1, x1, y0);
return line(x1, y0, x0, y0);
}
PlotFile& PlotFile:: circle(const int x, const int y, const int r)
{
return cmd('c') << x << y << r;
}
PlotFile& PlotFile:: cont(const int xi, const int yi)
{
return cmd('n') << xi << yi;
}
PlotFile& PlotFile:: dot(const int xi, const int yi, const int dx,
int n, const int* pat)
{
cmd('d') << xi << yi << dx << n;
while (n-- > 0) *this << *pat++;
return *this;
}
PlotFile& PlotFile:: erase()
{
return cmd('e');
}
PlotFile& PlotFile:: label(const char* s)
{
return cmd('t') << s << "\n";
}
PlotFile& PlotFile:: line(const int x0, const int y0,
const int x1, const int y1)
{
return cmd('l') << x0 << y0 << x1 << y1;
}
PlotFile& PlotFile:: linemod(const char* s)
{
return cmd('f') << s << "\n";
}
PlotFile& PlotFile:: move(const int xi, const int yi)
{
return cmd('m') << xi << yi;
}
PlotFile& PlotFile:: point(const int xi, const int yi)
{
return cmd('p') << xi << yi;
}
PlotFile& PlotFile:: space(const int x0, const int y0,
const int x1, const int y1)
{
return cmd('s') << x0 << y0 << x1 << y1;
}
/* 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
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. */
/*
a very simple implementation of a class to output unix "plot"
format plotter files. See corresponding unix man pages for
more details.
written by Doug Lea (dl@rocky.oswego.edu)
converted to use iostream library by Per Bothner (bothner@cygnus.com)
*/
#ifndef _PlotFile_h
#ifdef __GNUG__
#pragma interface
#endif
#define _PlotFile_h
#include <fstream.h>
/*
Some plot libraries have the `box' command to draw boxes. Some don't.
`box' is included here via moves & lines to allow both possiblilties.
*/
extern "C++" {
class PlotFile : public ofstream
{
protected:
PlotFile& cmd(char c);
PlotFile& operator << (const int x);
PlotFile& operator << (const char *s);
public:
PlotFile() : ofstream() { }
PlotFile(int fd) : ofstream(fd) { }
PlotFile(const char *name, int mode=ios::out, int prot=0664)
: ofstream(name, mode, prot) { }
// PlotFile& remove() { ofstream::remove(); return *this; }
// int filedesc() { return ofstream::filedesc(); }
// const char* name() { return File::name(); }
// void setname(const char* newname) { File::setname(newname); }
// int iocount() { return File::iocount(); }
PlotFile& arc(const int xi, const int yi,
const int x0, const int y0,
const int x1, const int y1);
PlotFile& box(const int x0, const int y0,
const int x1, const int y1);
PlotFile& circle(const int x, const int y, const int r);
PlotFile& cont(const int xi, const int yi);
PlotFile& dot(const int xi, const int yi, const int dx,
int n, const int* pat);
PlotFile& erase();
PlotFile& label(const char* s);
PlotFile& line(const int x0, const int y0,
const int x1, const int y1);
PlotFile& linemod(const char* s);
PlotFile& move(const int xi, const int yi);
PlotFile& point(const int xi, const int yi);
PlotFile& space(const int x0, const int y0,
const int x1, const int y1);
};
} // extern "C++"
#endif
This is libio, the GNU C/C++ input/output library.
By default, the library is configured to build the C++ iostream
facility (in $libdir/libiostream.a).
The library can be configured to build the C stdio facility
that is part of a C run-time library.
This library is distributed with libg++; see ../libg++/README
for installation instructions, and where to send bug reports
and questions.
* Copyright restrictions
The files in this directory are generally covered by the GNU Public
License (which is in the file ../COPYING), but modified with the
following:
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.
A few source files and subroutines are covered by other (but
less restrictive) copyright conditions. E.g. some code (such
as iovfprintf.c) is based on software that was developed by the
University of California, Berkeley, for the Berkeley Software
Distribution (BSD-4.4), and bears their copyright; and one
file (floatconv.c) is derived from ("free") code copyrighted AT&T.
/*
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/*
Copyright (C) 1988 Free Software Foundation
written by Doug Lea (dl@rocky.oswego.edu)
This file is part of the GNU C++ Library. This 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. 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef __GNUG__
#pragma implementation
#endif
#include <SFile.h>
SFile::SFile(const char *filename, int size, int mode, int prot)
: fstream(filename, mode, prot)
{
sz = size;
}
SFile::SFile(int fd, int size)
: fstream(fd)
{
sz = size;
}
void SFile::open(const char *name, int size, int mode, int prot)
{
fstream::open(name, mode, prot);
sz = size;
}
SFile& SFile::get(void* x)
{
read(x, sz);
return *this;
}
SFile& SFile::put(void* x)
{
write(x, sz);
return *this;
}
SFile& SFile::operator[](long i)
{
if (rdbuf()->pubseekoff(i * sz, ios::beg) == EOF)
set(ios::badbit);
return *this;
}
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 1988, 1992, 1993 Free Software Foundation
written by Doug Lea (dl@rocky.oswego.edu)
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. */
#ifndef _SFile_h
#ifdef __GNUG__
#pragma interface
#endif
#define _SFile_h 1
#include <fstream.h>
extern "C++" {
class SFile: public fstream
{
protected:
int sz; // unit size for structured binary IO
public:
SFile() : fstream() { }
SFile(int fd, int size);
SFile(const char *name, int size, int mode, int prot=0664);
void open(const char *name, int size, int mode, int prot=0664);
int size() { return sz; }
int setsize(int s) { int old = sz; sz = s; return old; }
SFile& get(void* x);
SFile& put(void* x);
SFile& operator[](long i);
};
} // extern "C++"
#endif
/*
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifdef __GNUC__
#pragma implementation
#endif
#define _STREAM_COMPAT
#include "builtinbuf.h"
#include "iostreamP.h"
#if !_IO_UNIFIED_JUMPTABLES
int builtinbuf::overflow(int ch) { return _IO_OVERFLOW (this, ch); }
int builtinbuf::underflow() { return _IO_UNDERFLOW (this); }
streamsize builtinbuf::xsgetn(char* buf, streamsize n)
{ return _IO_XSGETN (this, buf, n); }
streamsize builtinbuf::xsputn(const char* buf, streamsize n)
{ return _IO_XSPUTN (this, buf, n); }
int builtinbuf::doallocate() { return _IO_DOALLOCATE (this); }
builtinbuf::~builtinbuf() { _IO_FINISH (this); }
int builtinbuf::sync() { return _IO_SYNC (this); }
streambuf* builtinbuf::setbuf(char *buf, int n)
{ return (streambuf*)_IO_SETBUF (this, buf, n); }
streampos builtinbuf::seekoff(streamoff off, _seek_dir dir, int mode)
{
return _IO_SEEKOFF (this, off, dir, mode);
}
streampos builtinbuf::seekpos(streampos pos, int mode)
{
return _IO_SEEKPOS (this, pos, mode);
}
int builtinbuf::pbackfail(int c)
{ return _IO_PBACKFAIL (this, c); }
streamsize builtinbuf::sys_read(char* buf, streamsize size)
{ return _IO_SYSREAD (this, buf, size); }
streampos builtinbuf::sys_seek(streamoff off, _seek_dir dir)
{ return _IO_SYSSEEK (this, off, dir); }
streamsize builtinbuf::sys_write(const char* buf, streamsize size)
{ return _IO_SYSWRITE (this, buf, size); }
int builtinbuf::sys_stat(void* buf) // Actually, a (struct stat*)
{ return _IO_SYSSTAT (this, buf); }
int builtinbuf::sys_close()
{ return _IO_SYSCLOSE (this); }
#endif
/*
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef _BUILTINBUF_H
#define _BUILTINBUF_H
#ifdef __GNUC__
#pragma interface
#endif
#include <streambuf.h>
#if !_IO_UNIFIED_JUMPTABLES
// A builtinbuf is a streambuf where all the virtual operations
// call the _IO_jump_t table.
extern "C++" {
class builtinbuf : public streambuf {
friend ios;
virtual int overflow(int);
virtual int underflow();
virtual streamsize xsgetn(char *, streamsize);
virtual streamsize xsputn(const char *, streamsize);
virtual streambuf* setbuf(char*, int);
virtual int doallocate();
virtual ~builtinbuf();
virtual int sync();
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
virtual int pbackfail(int c);
virtual streamsize sys_read(char* buf, streamsize size);
virtual streampos sys_seek(streamoff, _seek_dir);
virtual streamsize sys_write(const char*, streamsize);
virtual int sys_stat(void*); // Actually, a (struct stat*)
virtual int sys_close();
#if 0
virtual int get_column();
virtual int set_column(int);
#endif
private:
builtinbuf() { }
};
} // extern "C++"
#endif
#endif /* _BUILTINBUF_H */
#include "libioP.h"
#if _G_HAVE_ATEXIT
#include <stdlib.h>
typedef void (*voidfunc) __P((void));
static void
_IO_register_cleanup ()
{
atexit ((voidfunc)_IO_cleanup);
_IO_cleanup_registration_needed = 0;
}
void (*_IO_cleanup_registration_needed)() = _IO_register_cleanup;
#else
void (*_IO_cleanup_registration_needed)() = NULL;
#endif /* _G_HAVE_ATEXIT */
# Use the libio which comes with the local libc.
# Comment this out to avoid including the stdio functions in libiostream.a:
# LIBIOSTREAM_OBJECTS = $(IO_OBJECTS) $(IOSTREAM_OBJECTS) $(STDIO_WRAP_OBJECTS) $(OSPRIM_OBJECTS)
# LIBIOSTREAM_DEP = $(LIBIOSTREAM_OBJECTS) stdio.list
# LIBIOSTREAM_USE = $(LIBIOSTREAM_OBJECTS) `cat stdio.list`
# Comment the above and uncomment the below to use the code in the Linux libc:
# We have _G_config.h in /usr/include.
_G_CONFIG_H=
# We must not see the libio.h file from this library.
LIBIO_INCLUDE=
# We have those in libc.a.
IO_OBJECTS= iogetline.o
STDIO_WRAP_OBJECTS=
OSPRIM_OBJECTS=
STDIO_OBJECTS=
# We have the rest in /usr/include.
USER_INCLUDES=PlotFile.h SFile.h builtinbuf.h editbuf.h fstream.h \
indstream.h iomanip.h iostream.h istream.h ostream.h \
parsestream.h pfstream.h procbuf.h stdiostream.h stream.h \
streambuf.h strfile.h strstream.h
/* libc-internal interface for mutex locks. LinuxThreads version.
Copyright (C) 1996 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. */
#ifndef _LIBC_LOCK_H
#define _LIBC_LOCK_H 1
#include <pthread.h>
#define __libc_lock_t pthread_mutex_t
/* Define a lock variable NAME with storage class CLASS. The lock must be
initialized with __libc_lock_init before it can be used (or define it
with __libc_lock_define_initialized, below). Use `extern' for CLASS to
declare a lock defined in another module. In public structure
definitions you must use a pointer to the lock structure (i.e., NAME
begins with a `*'), because its storage size will not be known outside
of libc. */
#define __libc_lock_define(CLASS,NAME) \
CLASS __libc_lock_t NAME;
/* Define an initialized lock variable NAME with storage class CLASS. */
#define __libc_lock_define_initialized(CLASS,NAME) \
CLASS __libc_lock_t NAME = PTHREAD_MUTEX_INITIALIZER;
/* Initialize the named lock variable, leaving it in a consistent, unlocked
state. */
#define __libc_lock_init(NAME) \
(__pthread_mutex_init != NULL ? __pthread_mutex_init (&(NAME), NULL) : 0);
/* Same as last but this time we initialize a recursive mutex. */
#define __libc_lock_init_recursive(NAME) \
do { \
if (__pthread_mutex_init != NULL) \
{ \
pthread_mutexattr_t __attr; \
__pthread_mutexattr_init (&__attr); \
__pthread_mutexattr_setkind_np (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
__pthread_mutex_init (&(NAME), &__attr); \
__pthread_mutexattr_destroy (&__attr); \
} \
} while (0);
/* Finalize the named lock variable, which must be locked. It cannot be
used again until __libc_lock_init is called again on it. This must be
called on a lock variable before the containing storage is reused. */
#define __libc_lock_fini(NAME) \
(__pthread_mutex_destroy != NULL ? __pthread_mutex_destroy (&(NAME)) : 0);
/* Lock the named lock variable. */
#define __libc_lock_lock(NAME) \
(__pthread_mutex_lock != NULL ? __pthread_mutex_lock (&(NAME)) : 0);
/* Try to lock the named lock variable. */
#define __libc_lock_trylock(NAME) \
(__pthread_mutex_trylock != NULL ? __pthread_mutex_trylock (&(NAME)) : 0);
/* Unlock the named lock variable. */
#define __libc_lock_unlock(NAME) \
(__pthread_mutex_unlock != NULL ? __pthread_mutex_unlock (&(NAME)) : 0);
/* Start critical region with cleanup. */
#define __libc_cleanup_region_start(FCT, ARG) \
{ struct _pthread_cleanup_buffer _buffer; \
if (_pthread_cleanup_push_defer != NULL) { \
_pthread_cleanup_push_defer (&_buffer, (FCT), (ARG)); \
}
/* End critical region with cleanup. */
#define __libc_cleanup_region_end(DOIT) \
if (_pthread_cleanup_push_defer != NULL) { \
_pthread_cleanup_pop_restore (&_buffer, (DOIT)); \
} \
}
/* Make the pthread functions weak so that we can elide them from
single-threaded processes. */
#pragma weak __pthread_mutex_init
#pragma weak __pthread_mutex_destroy
#pragma weak __pthread_mutex_lock
#pragma weak __pthread_mutex_trylock
#pragma weak __pthread_mutex_unlock
#pragma weak __pthread_mutexattr_init
#pragma weak __pthread_mutexattr_destroy
#pragma weak __pthread_mutexattr_setkind_np
#pragma weak __pthread_key_create
#pragma weak __pthread_setspecific
#pragma weak __pthread_getspecific
#pragma weak __pthread_initialize
#pragma weak _pthread_cleanup_push_defer
#pragma weak _pthread_cleanup_pop_restore
/* We need portable names for some functions. E.g., when they are
used as argument to __libc_cleanup_region_start. */
#define __libc_mutex_unlock __pthread_mutex_unlock
#endif /* libc-lock.h */
/* Thread package specific definitions of stream lock type.
Copyright (C) 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 <pthread.h>
typedef pthread_mutex_t _IO_lock_t;
/* We need recursive (counting) mutexes. */
#define _IO_lock_initializer PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
#define _IO_cleanup_region_start(_fct, _fp) \
__libc_cleanup_region_start (_fct, _fp)
#define _IO_cleanup_region_end(_doit) \
__libc_cleanup_region_end (_doit)
#define _IO_lock_init(_name) \
__libc_lock_init_recursive (_name)
#define _IO_lock_fini(_name) \
__libc_lock_fini_recursive (_name)
# We _do_ need a new _G_config.h
_G_CONFIG_H=_G_config.h
# And the two bits files.
all:
install: install-axp-mt-headers
install-axp-mt-headers:
$(INSTALL_DATA) libc-lock.h $(gxx_include_dir)/libc-lock.h
$(INSTALL_DATA) stdio-lock.h $(gxx_include_dir)/stdio-lock.h
# Use the libio which comes with the local libc.
# Comment this out to avoid including the stdio functions in libiostream.a:
# LIBIOSTREAM_OBJECTS = $(IO_OBJECTS) $(IOSTREAM_OBJECTS) $(STDIO_WRAP_OBJECTS) $(OSPRIM_OBJECTS)
# LIBIOSTREAM_DEP = $(LIBIOSTREAM_OBJECTS) stdio.list
# LIBIOSTREAM_USE = $(LIBIOSTREAM_OBJECTS) `cat stdio.list`
# We must not see the libio.h file from this library.
LIBIO_INCLUDE=
# We have those in libc.a.
IO_OBJECTS=iogetc.o ioputc.o iofeof.o ioferror.o \
filedoalloc.o fileops.o genops.o iofclose.o \
iovsprintf.o iovsscanf.o strops.o iogetline.o
STDIO_WRAP_OBJECTS=
OSPRIM_OBJECTS=
STDIO_OBJECTS=
# We have the rest in /usr/include.
USER_INCLUDES=PlotFile.h SFile.h builtinbuf.h editbuf.h fstream.h \
indstream.h iomanip.h iostream.h istream.h ostream.h \
parsestream.h pfstream.h procbuf.h stdiostream.h stream.h \
streambuf.h strfile.h strstream.h libio.h
# A bad kludge
MT_CFLAGS=-D_G_HAVE_MMAP -D_G_STDIO_USES_LIBIO -D_G_HAVE_WEAK_SYMBOL
# Flags to pass to gen-params when building _G_config.h.
# For example: G_CONFIG_ARGS = size_t="unsigned long"
G_CONFIG_ARGS = NO_USE_DTOA=1 USE_INT32_FLAGS=1
# Flags to pass to gen-params when building _G_config.h.
# For example: G_CONFIG_ARGS = size_t="unsigned long"
G_CONFIG_ARGS = DOLLAR_IN_LABEL=1
#
# gen-params tries to determine whether or not printf_fp exists by
# simply compiling a test program. Since MPE is by definition a
# shared runtime environment, this won't work unless the resulting
# program is run. Simply run _G_config.h through a sed script to
# update the values accordingly.
#
_G_CONFIG_H = stmp-Gconfig
stmp-Gconfig: _G_config.h
sed -e "s/_G_HAVE_PRINTF_FP 1/_G_HAVE_PRINTF_FP 0/" \
-e "s/_G_HAVE_LONG_DOUBLE_IO 1/_G_HAVE_LONG_DOUBLE_IO 0/" \
<_G_config.h > tmp-config.h
mv -f tmp-config.h _G_config.h
touch stmp-Gconfig
$(MAKE) $(FLAGS_TO_PASS) _G_CONFIG_H=_G_config.h all
# tell we want the mt-safe version
MT_CFLAGS = -D_IO_MTSAFE_IO
IMPDIR= $(srcdir)/config/netware
PRELUDE= prelude.o
iostream.def: Makefile
-rm -f iostream.def
echo "description \"libiostream\"" >> iostream.def
echo "screenname \"NONE\"" >> iostream.def
echo "version `echo $(VERSION) | sed 's|\.|,|g'`" >> iostream.def
echo "export @$(IMPDIR)/iostream.imp" >> iostream.def
iostream.O: $(PRELUDE) $(LIBIOSTREAM_OBJECTS)
$(CC) -Xlinker -Ur -o $@ $(PRELUDE) $(LIBIOSTREAM_OBJECTS)
iostream.nlm: iostream.def iostream.O $(IMPDIR)/iostream.imp
$(NLMCONV) -l $(LD) -T iostream.def iostream.O iostream.nlm
G_CONFIG_ARGS = HAVE_PRINTF_FP=0 HAVE_LONG_DOUBLE_IO=0
# This file is a shell script fragment that supplies the information
# necessary for a configure script to process the program in
# this directory. For more information, look at ../configure.
# If the language specific compiler does not exist, but the "gcc" directory
# does, we do not build anything. Note, $r is set by the top-level Makefile.
# Note that when we look for the compiler, we search both with and without
# extension to handle cross and canadian cross builds.
# Note that if $norecursion is set we're being called from config.status,
# so don't check for the compiler; we might be doing a make clean.
compiler_name=cc1plus
rm -f skip-this-dir
if test -n "$r" && [ -z "$norecursion" ] ; then
if test -d "$r"/gcc; then
if test -f "$r"/gcc/$compiler_name \
|| test -f "$r"/gcc/$compiler_name.exe; then
true
else
echo "rm -f multilib.out" > skip-this-dir
fi
fi
fi
if [ "${srcdir}" = "." ] ; then
if [ "${with_target_subdir}" != "." ] ; then
topsrcdir=${with_multisrctop}../..
else
topsrcdir=${with_multisrctop}..
fi
else
topsrcdir=${srcdir}/..
fi
if [ -d ${topsrcdir}/gcc ] ; then
configdirs="tests dbz stdio testsuite"
else
configdirs="tests dbz stdio"
fi
srctrigger=libioP.h
srcname="input/output library"
package_makefile_frag=Make.pack
package_makefile_rules_frag=Make.pack.r
# per-host:
# per-target:
echo "# Warning: this fragment is automatically generated" > temp.mt
frags=
case x$enable_threads in
xno) ;;
*) mtsafe=mtsafe.mt ;;
esac
case "${target}" in
*-mpeix*) frags="mpeix.mt" ;;
*-hpux*) frags=hpux.mt ;;
alpha*-*-linux*libc1)
frags="linux.mt linuxaxp1.mt $mtsafe" ;;
powerpc*-*-linux*libc1)
frags="linux.mt linuxaxp1.mt $mtsafe" ;;
*-linux*libc1)
frags=linuxlibc1.mt ;;
*-linux*)
frags="linux.mt $mtsafe" ;;
*-isc*) frags=isc.mt ;;
*-netware*) frags=netware.mt ;;
*-dgux*) frags=dgux.mt ;;
*vxworks*) frags="vxworks.mt" ;;
*-beos*) frags="beos.mt $mtsafe" ;;
*) frags=${target_cpu}.mt ;;
esac
case "${enable_shared}" in
yes) shared=yes ;;
no) shared=no ;;
*libio*) shared=yes ;;
*) shared=no ;;
esac
if [ "${shared}" = "yes" ]; then
case "${target}" in
alpha*-*-linux*) frags="${frags} ../../config/mh-elfalphapic" ;;
arm*-*-*) frags="${frags} ../../config/mh-armpic" ;;
hppa*-*-*) frags="${frags} ../../config/mh-papic" ;;
i[3456]86-*-*) frags="${frags} ../../config/mh-x86pic" ;;
powerpc*-*-aix*) ;;
powerpc*-*-*) frags="${frags} ../../config/mh-ppcpic" ;;
sparc*-*-*) frags="${frags} ../../config/mh-sparcpic" ;;
*-*-*) frags="${frags} ../../config/mh-${target_cpu}pic" ;;
esac
fi
# Take care of header file lossage.
case "${target}" in
alpha*-*-linux*libc1)
# For some reason stdio-lock.h is not installed on Red Hat systems.
# Further, libc-lock.h needs to define the pthreads stuff weak, and
# fails to do this for other than _LIBC. Install our own versions
# of these files.
cp ${srcdir}/config/linuxaxp1-libc-lock.h libc-lock.h
cp ${srcdir}/config/linuxaxp1-stdio-lock.h stdio-lock.h
;;
powerpc*-*-linux*libc1)
# For some reason stdio-lock.h is not installed on Red Hat systems.
# Further, libc-lock.h needs to define the pthreads stuff weak, and
# fails to do this for other than _LIBC. Install our own versions
# of these files.
cp ${srcdir}/config/linuxaxp1-libc-lock.h libc-lock.h
cp ${srcdir}/config/linuxaxp1-stdio-lock.h stdio-lock.h
;;
*-linux*)
# We have a correct libc-lock.h in glibc 2.1 but not all glibc 2.0.
# Create a wrapper if necessary.
(echo "#include <bits/libc-lock.h>" | ${CC-cc} -E -) >/dev/null 2>&1 ||
{
echo " #include_next <libc-lock.h>" > libc-lock.h
echo 'asm (".weak _pthread_cleanup_pop_restore");' >> libc-lock.h
echo 'asm (".weak _pthread_cleanup_push_defer");' >> libc-lock.h
}
;;
esac
for frag in ${frags}; do
case ${frag} in
../* )
if [ ${srcdir} = . ]; then
[ -n "${with_target_subdir}" ] && frag=../${frag}
[ -n "${with_multisrctop}" ] && frag=${with_multisrctop}${frag}
fi
;;
esac
frag=${srcdir}/config/$frag
if [ -f ${frag} ]; then
echo "Appending ${frag} to target-mkfrag"
echo "# Following fragment copied from ${frag}" >> temp.mt
cat ${frag} >> temp.mt
fi
done
target_makefile_frag=target-mkfrag
${moveifchange} temp.mt target-mkfrag
LIBDIR=yes
TO_TOPDIR=../
ALL='$(_G_CONFIG_H) libio.a libiostream.a iostream.list'
case "${target}" in
*-*-cygwin*)
XCINCLUDES='-I. -I$(srcdir) -I$(srcdir)/../winsup/include'
XCXXINCLUDES='-I. -I$(srcdir) -I$(srcdir)/../winsup/include'
;;
*)
XCINCLUDES='-I. -I$(srcdir)'
XCXXINCLUDES='-I. -I$(srcdir)'
;;
esac
MOSTLYCLEAN='*.o pic stamp-picdir core iostream.list'
DISTCLEAN='config.status Makefile *~ Make.pack target-mkfrag multilib.out'
CLEAN='_G_config.h *.a'
INFO_FILES=iostream
if [ -n "${with_cross_host}" -a -d ${topsrcdir}/gcc ]; then
CHECK_SUBDIRS=testsuite
fi
(. ${srcdir}/config.shared) >${package_makefile_frag} 2>${package_makefile_rules_frag}
# post-target:
# If cross-compiling, we install in $(tooldir)/lib or in $(libsubdir)
# depending on --enable-version-specific-runtime-libs.
if [ -n "${with_cross_host}" ] ; then
rm -f Makefile.tem
sed \
-e 's|\(^[ ]*INSTALLDIR[ ]*=[ ]*\)\$(libdir)|\1$(tooldir)/lib|' \
Makefile >Makefile.tem
mv -f Makefile.tem Makefile
fi
. ${topsrcdir}/config-ml.in
gxx_include_dir=
# Specify the g++ header file directory
# Check whether --with-gxx-include-dir or --without-gxx-include-dir was given.
if test "${with_gxx_include_dir+set}" = set; then
withval="$with_gxx_include_dir"
case "${withval}" in
yes)
echo "configure.in: error: bad value ${withval} given for g++ include directory" 1>&2
exit 1
;;
no) ;;
*) gxx_include_dir=$with_gxx_include_dir ;;
esac
fi
if test x${gxx_include_dir} = x; then
if test x${enable_version_specific_runtime_libs} = xyes; then
gxx_include_dir='${libsubdir}/include/g++'
else
. ${topsrcdir}/config.if
gxx_include_dir='${prefix}/include/g++'-${libstdcxx_interface}
fi
fi
rm -f Makefile.tem
sed -e "s%^gxx_include_dir[ ]*=.*$%gxx_include_dir=${gxx_include_dir}%" \
Makefile >Makefile.tem
mv -f Makefile.tem Makefile
srcdir = .
CFLAGS = -g
C_FLAGS = $(CFLAGS) -I$(srcdir) -I.. -I$(srcdir)/.. -DDBZ_FINISH='_IO_flush_all()'
CC = `if [ -f ../../../gcc/gcc ] ; \
then echo ../../../gcc/gcc -B../../../gcc/ ; \
else echo gcc ; fi`
LIBIO = ../libio.a ../../libiberty/libiberty.a
LIBS = $(LIBIO)
# LIBS = ../libcnews.a
DBM =
RFC = -DHAVERFCIZE
CASE = case.o
DEBUG = -DDBZDEBUG
LINTFLAGS = -h $(DEBUG) $(RFC) -I$(srcdir)
LDFLAGS =
# =()<NEWSBIN = @<NEWSBIN>@>()=
NEWSBIN = /usr/lib/newsbin
# workaround for System V make bug
SHELL = /bin/sh
# database sizes for performance tests, regression, and regression prime-find
TSIZE=12007
RSIZE=4019
RPSIZE=2679
#### host and target dependent Makefile fragments come in here.
##
# history files for regression and performance tests
RHIST=hist3.3
R2HIST=hist10
THIST=hist13
#all: dbz
all:
install:
install-info:
info:
check: r
$(MAKE) rclean
bininstall: dbz
cp dbz $(NEWSBIN)
cmp: dbz
cmp dbz $(NEWSBIN)/dbz
newsinstall:
: nothing
u: dbz.o
ar ruv ../libcnews.a dbz.o
cmp dbz.h ../h/dbz.h
t: tdbz fake
lint:
lint $(LINTFLAGS) dbzmain.c dbz.c
.c.o:
$(CC) $(C_FLAGS) -c $<
rdbz.o: rdbz.c
$(CC) $(C_FLAGS) $(DEBUG) -DDEFSIZE=$(RSIZE) -c rdbz.c
rdbzmain.o: rdbzmain.c
$(CC) $(C_FLAGS) $(RFC) -c rdbzmain.c
tdbz.o: $(srcdir)/dbz.c
cp $(srcdir)/dbz.c tdbz.c
$(CC) $(C_FLAGS) -DDEFSIZE=$(TSIZE) -c tdbz.c
rm tdbz.c
dbz: dbzmain.o $(CASE)
$(CC) $(LDFLAGS) dbzmain.o $(CASE) $(PRE) $(DBM) $(LIBS) $(POST) -o $@
tdbz: dbzmain.o tdbz.o $(CASE)
$(CC) $(LDFLAGS) dbzmain.o tdbz.o $(CASE) $(PRE) $(LIBS) $(POST) -o $@
rdbz: rdbzmain.o rdbz.o $(CASE)
$(CC) $(LDFLAGS) rdbzmain.o rdbz.o $(CASE) $(PRE) $(LIBS) $(POST) -o $@
fake: fake.o random.o
$(CC) $(LDFLAGS) fake.o random.o $(PRE) $(LIBS) $(POST) -o $@
byteflip: byteflip.o
$(CC) $(LDFLAGS) byteflip.o $(PRE) $(LIBS) $(POST) -o $@
hist10: fake
./fake -t -e 75 10000 >$@
hist3.3: fake
./fake -t -e 75 3300 >$@
hist13: fake
./fake -t -e 75 13000 >$@
r: $(srcdir)/getmap $(srcdir)/revbytes $(srcdir)/altbytes stamp-r8
: success!
stamp-r0:
: 'WARNING: creates about 2MB of debris; do "make rclean" afterward'
rm -f dbase dbase[23] dbase.* dbase[23].*
test ! -d xx || rmdir xx
@touch stamp-r0
stamp-r1: $(RHIST) $(R2HIST) stamp-r0
: crude check of synthetic history file
( sed 25q $(RHIST) ; tail -25 $(RHIST) ) >histjunk
cmp histjunk $(srcdir)/firstlast25
rm histjunk
@touch stamp-r1
r2a: rdbz stamp-r1
: basic tests, exercising as many options as possible
cp $(RHIST) dbase
mkdir xx
chmod -w xx
./rdbz -E 1000 -0 -M -i -S -u -U -C xx dbase
rmdir xx
sed '/> 0/d' $(RHIST) >dbase.used
test "`cat dbase.used | wc -l`" -eq "`sed -n '2s/ .*//p' dbase.dir`" ;
stamp-r2: r2a
cp $(RHIST) dbase2
./rdbz -E 1000 -0 -p $(RPSIZE) -t ' ' dbase2
cmp $(RHIST) dbase
cmp dbase dbase2
cmp dbase.dir dbase2.dir
cmp dbase.pag dbase2.pag
./rdbz -E 1000 -0 -c dbase
./rdbz -E 1000 -0 -c -i -q -M -U dbase
@touch stamp-r2
stamp-r3: stamp-r2
: build a database and then add to it
sed 1000q $(RHIST) >dbase2
sed 1,1000d $(RHIST) >dbase2.add
./rdbz -E 1000 -0 dbase2
./rdbz -E 1000 -0 -a dbase2 dbase2.add
cmp dbase dbase2
cmp dbase.dir dbase2.dir
cmp dbase.pag dbase2.pag
@touch stamp-r3
stamp-r4: stamp-r3
: build based on existing one, test extraction and readonly files
./rdbz -E 1000 -0 -f dbase dbase2
test "`cat dbase.used | wc -l`" -eq "`awk 'NR==2{print $$1}' dbase2.dir`" ;
test "`cat dbase.used | wc -l`" -eq "`awk 'NR==2{print $$2}' dbase2.dir`" ;
chmod -w dbase2.dir dbase2.pag
./rdbz -E 1000 -x dbase2 dbase >dbase.temp
cmp dbase.used dbase.temp
@touch stamp-r4
stamp-r5: stamp-r4
: try some small case perversions
sed 's/\(@[^ ]*\)A/\1a/' dbase >dbase.ick
./rdbz -E 1000 -x dbase2 dbase.ick >dbase.temp
cmp dbase.used dbase.temp
sed -n 's/A\([^ ]*@\)/a\1/p' dbase >dbase.ick
./rdbz -x dbase2 dbase.ick >dbase.temp
test ! -s dbase.temp ;
rm -f dbase2.dir dbase2.pag
@touch stamp-r5
stamp-r6: stamp-r5
: try it without tags, case-insensitive, with case perversions
./rdbz -E 1000 -0 -p '0 b 1' dbase2
tr 'ABCDEFGHIJKLMnopqrstuvwxyz' 'abcdefghijklmNOPQRSTUVWXYZ' <dbase2 >dbase.ick
./rdbz -E 1000 -x dbase2 dbase.ick >dbase.temp
cmp dbase.used dbase.temp
rm -f dbase.temp dbase.ick
@touch stamp-r6
stamp-r7: byteflip stamp-r6
: test various perversions of byte ordering
awk -f $(srcdir)/revbytes dbase.dir >dbase2.dir
./byteflip `$(srcdir)/getmap dbase.dir` `$(srcdir)/getmap dbase2.dir` <dbase.pag >dbase2.pag
cp dbase dbase2
./rdbz -E 1000 -0 -c dbase2
awk -f $(srcdir)/altbytes dbase.dir >dbase2.dir
dd conv=swab <dbase.pag >dbase2.pag
./rdbz -E 1000 -0 -c dbase2
cp dbase2 dbase3
./rdbz -E 1000 -0 -f dbase2 dbase3
./rdbz -E 1000 -0 -c dbase3
test " `$(srcdir)/getmap dbase2.dir`" = " `$(srcdir)/getmap dbase3.dir`" ;
@touch stamp-r7
stamp-r8: stamp-r7
: test massive overflow, throw in case sensitivity and tag mask
cp $(R2HIST) dbase
./rdbz -E 1000 -0 -p '0 0 7ffc0000' dbase
./rdbz -E 1000 -0 -cq dbase
sed 100q dbase | egrep '[aA].* ' | tr aA Aa >dbase.ick
./rdbz -x dbase dbase.ick >dbase.temp
test ! -s dbase.temp ;
@touch stamp-r8
rclean:
rm -f dbase dbase[23] dbase.* dbase[23].* fake fake.o random.o
rm -f rdbz rdbz.o rdbzmain.o $(RHIST) $(R2HIST) byteflip byteflip.o
rm -f histjunk core stamp-r? *~
test ! -d xx || rmdir xx
mostlyclean: rclean
rm -f *.o [a-z]dbz [a-z][a-z]dbz junk* PostScript.out
rm -f hist* dbase* *.bak mon.out gmon.out core dbm.h
clean: mostlyclean
rm -f dbz
distclean: clean
rm -rf Makefile config.status rdbz.c rdbzmain.c
maintainer-clean realclean: distclean
The dbz package was "liberated" from C News.
It is included with the GNU libio because it provides
a fairly good work-out for a stdio implementation.
The Makefile.in, configure.in, and stdio.h have been
set up to test libio.
------
This is the new, improved, lemon-freshened :-) dbz.
Just "make" will get you dbz.o and the dbz program. "make r" runs an
extensive set of regression tests; most of the mysterious oddments lying
around here are to do with that. "make rclean" cleans up after "make r".
You probably want to inspect the #ifdef list early in dbz.c before
compiling, although the defaults should work all right on most systems.
If you are not building this as part of C News, you will need to change
the -I option in FLAGS in the Makefile to "-I.", and delete the DBMLIBS
and RFC lines entirely. That will break some of the regression tests;
at some point I'll fix this.
If you are using this independently from C News, you probably still want
to look through ../notebook/problems, as some of the portability problems
described in there can affect dbz.
NR == 1 {
printf "%s %s %s %s %s %s %s %s %s", $1, $2, $3, $4, $5, $6, $7, $8, $9
for (i = 10; i <= NF; i += 2)
printf " %s %s", $(i+1), $i
printf "\n"
}
NR > 1 { print }
#include <stdio.h>
#define MAXWORD 32
int
main(argc, argv)
int argc;
char *argv[];
{
register int len;
int inmap[MAXWORD];
int outmap[MAXWORD];
char in[MAXWORD];
char out[MAXWORD];
register int i;
register int a;
a = 1;
len = atoi(argv[a++]);
if (len > MAXWORD)
abort(); /* kind of drastic... */
for (i = 0; i < len; i++)
inmap[i] = atoi(argv[a++]);
if (atoi(argv[a++]) != len)
abort();
for (i = 0; i < len; i++)
outmap[i] = atoi(argv[a++]);
while (fread(in, 1, len, stdin) == len) {
for (i = 0; i < len; i++)
out[outmap[i]] = in[inmap[i]];
fwrite(out, 1, len, stdout);
}
#ifdef DBZ_FINISH
DBZ_FINISH;
#endif
exit(0);
}
/*
* case-mapping stuff
*
* We exploit the fact that we are dealing only with headers here, and
* headers are limited to the ASCII characters by RFC822. It is barely
* possible that we might be dealing with a translation into another
* character set, but in particular it's very unlikely for a header
* character to be outside -128..255.
*
* Life would be a whole lot simpler if tolower() could safely and portably
* be applied to any char.
*/
#include <stdio.h>
#include "string.h"
#include "case.h"
/* note that case.h knows the value of OFFSET */
#define OFFSET 128 /* avoid trouble with negative chars */
#define MAPSIZE (256+OFFSET)
char casemap[MAPSIZE]; /* relies on init to '\0' */
static int primed = 0; /* has casemap been set up? */
/*
- prime - set up case-mapping stuff
*/
static void
prime()
{
register char *lp;
register char *up;
register int c;
register int i;
static char lower[] = "abcdefghijklmnopqrstuvwxyz";
static char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (lp = lower, up = upper; *lp != '\0'; lp++, up++) {
c = *lp;
casemap[c+OFFSET] = c;
casemap[*up+OFFSET] = c;
}
for (i = 0; i < MAPSIZE; i++)
if (casemap[i] == '\0')
casemap[i] = (char)(i-OFFSET);
primed = 1;
}
/*
- cistrncmp - case-independent strncmp
*/
int /* < == > 0 */
cistrncmp(s1, s2, len)
char *s1;
char *s2;
int len;
{
register char *p1;
register char *p2;
register int n;
if (!primed)
prime();
p1 = s1;
p2 = s2;
n = len;
while (--n >= 0 && *p1 != '\0' && TOLOW(*p1) == TOLOW(*p2)) {
p1++;
p2++;
}
if (n < 0)
return(0);
/*
* The following case analysis is necessary so that characters
* which look negative collate low against normal characters but
* high against the end-of-string NUL.
*/
if (*p1 == '\0' && *p2 == '\0')
return(0);
else if (*p1 == '\0')
return(-1);
else if (*p2 == '\0')
return(1);
else
return(TOLOW(*p1) - TOLOW(*p2));
}
/*
- rfc822ize - do the bizarre case conversion needed for rfc822 message-ids
*
* Actually, this is not quite complete. Absolute, total, full RFC822
* compliance requires a horrible parsing job, because of the arcane
* quoting conventions -- abc"def"ghi is not equivalent to abc"DEF"ghi,
* for example. There are three or four things that might occur in the
* domain part of a message-id that are case-sensitive. They don't seem
* to ever occur in real news, thank Cthulhu. (What? You were expecting
* a merciful and forgiving deity to be invoked in connection with RFC822?
* Forget it; none of them would come near it.)
*/
char * /* returns the argument */
rfc822ize(s)
char *s;
{
register char *p;
static char post[] = "postmaster";
static int postlen = sizeof(post)-1;
if (!primed)
prime();
p = strrchr(s, '@');
if (p == NULL) /* no local/domain split */
p = ""; /* assume all local */
else if (p - (s+1) == postlen && CISTREQN(s+1, post, postlen)) {
/* crazy special case -- "postmaster" is case-insensitive */
p = s;
}
#ifdef NONSTANDARD
#ifdef RFCVIOLATION
#ifdef B_2_11_MISTAKE
p = s; /* all case-insensitive */
#endif
#endif
#endif
for (; *p != '\0'; p++)
*p = TOLOW(*p);
return(s);
}
extern int cistrncmp();
extern char *rfc822ize();
extern char casemap[];
/* must call cistrncmp before invoking TOLOW... */
#define TOLOW(c) (casemap[(c)+128]) /* see case.c for why 128 */
/* ...but the use of it in CISTREQN is safe without the preliminary call (!) */
/* CISTREQN is an optimised case-insensitive strncmp(a,b,n)==0; n > 0 */
#define CISTREQN(a, b, n) \
(TOLOW((a)[0]) == TOLOW((b)[0]) && cistrncmp(a, b, n) == 0)
# This file is a shell script fragment that supplies the information
# necessary for a configure script to process the program in
# this directory. For more information, look at ../configure.
configdirs=
srctrigger=dbzmain.c
srcname="libio dbz test"
# per-host:
# per-target:
files="dbz.c dbzmain.c"
links="rdbz.c rdbzmain.c"
# post-target:
.TH DBZ 1 "11 Feb 1992"
.BY "C News"
.SH NAME
dbz \- operate on dbz databases of text
.SH SYNOPSIS
.B dbz
[
.BR \- { axmc }
] [
.B \-t
c
] [
.B \-l
length
] [
.BR \- { qiue }
] [
.B \-f
old
] [
.B \-p
parms
] database file ...
.SH DESCRIPTION
.I Dbz
is a shell-level interface to the
.IR dbz (3z)
database routines for indexed access to a text file.
.PP
The
.I database
file must be a text file,
one line per database record,
with the key the first field on the line.
The
.B \-t
option sets the field-separator character; the default is tab.
Setting the separator character to NUL (with
.BR "\-t\ ''" )
makes the whole line the key.
Lines must not exceed 1023 bytes in length including the newline;
this limit can be increased with the
.B \-l
option.
The limitations and restrictions of
.IR dbz (3z)
must also be observed;
in particular, it remains the user's responsibility to ensure that
no attempt is made to store two entries (whether identical or not)
with the same key.
.PP
In the absence of options,
.I dbz
creates a
.IR dbz (3z)
index for the database;
the index comprises files
.IB database .pag
and
.IB database .dir
in the same directory.
Any previous index is silently overwritten.
The
.BR \-a ,
.BR \-x ,
.BR \-m ,
and
.B \-c
options specify other operations.
.PP
With
.BR \-a ,
.I dbz
appends lines from the
.IR file (s)
(standard input if none)
to the database, updating both the
text file and the indexes.
.PP
With
.BR \-x ,
.I dbz
reads keys from the
.IR file (s)
(standard input if none)
and prints (on standard output) the corresponding lines, if any,
from the database.
The input is in the form of database lines, although only the keys are
significant.
The
.B \-q
option makes
.B \-x
print the input lines whose keys are found instead of the database
lines; this is somewhat faster.
.PP
With
.BR \-m ,
operation is the same as for
.B \-x
except that the keys which are \fInot\fR present in the database are printed.
.PP
With
.BR \-c ,
.I dbz
checks the database for internal consistency.
The
.B \-q
option causes this check to be done more quickly but less thoroughly
(each key is looked up in the index, but no check is made to be sure
that the index entry points to the right place).
.PP
The
.B \-i
option suppresses the use of
.IR dbz (3z)'s
.I incore
facility.
This makes accesses slower, but keeps the files current
during updating
and reduces
startup/shutdown overhead.
.PP
Normally,
.I dbz
checks whether a key is already in the database before adding it.
The
.B \-u
option suppresses this check, speeding things up at the expense of safety.
.PP
A new index is normally created with default size,
case mapping, and tagging.
The default size is right for 90-100,000 records.
The default case mapping is right for RFC822 message-ids.
See
.IR dbz (3z)
for what tagging is about.
(Note, these defaults can be changed when
.IR dbz (3z)
is installed.)
.PP
If the
.B \-f
option is given,
size, case mapping, and tagging
are instead initialized based on the
database
.IR old .
This is mostly useful when
creating a new generation of an existing database.
(See the description of
.I dbzagain
in
.IR dbz (3z)
for details.)
.PP
If the
.B \-p
option is given, the
.I parms
string specifies the size, case mapping, and tagging.
If
.I parms
is a single decimal number,
that is taken as the expected number of records
in the index, with case mapping and tagging defaulted.
Alternatively,
.I parms
can be three fields\(ema decimal number, a case-mapping code character, and a
hexadecimal tag mask\(emseparated by white space.
The decimal number is, again, the expected number of records;
0 means ``use the default''.
See
.IR dbz (3z)
for possible choices of case-mapping code,
but in particular,
.B 0
means ``no case mapping''.
See
.IR dbz (3z)
for details on tag masks;
0 means ``use the default''.
.PP
If the
.B \-e
option is given, the decimal number in
.B \-p
is taken to be the exact table size, not the expected number of records,
and invocation of
.I dbzsize
(see
.IR dbz (3z))
to predict a good size for that number of records is suppressed.
.PP
The
.B \&.pag
file is normally about 6 bytes per record (based on the estimate given to
.B \-p
or the previous history of the
.B \-f
database).
The
.B \&.dir
file is tiny.
.SH SEE ALSO
dbz(3z)
.SH HISTORY
Written at U of Toronto by Henry Spencer, for the C News project.
See
.IR dbz (3z)
for the history of the underlying database routines.
.SH BUGS
There are a number of undocumented options with obscure effects,
meant for debugging and regression testing of
.IR dbz (3z).
.PP
Permissions for the index files probably ought to be taken from those
of the base file.
.PP
The line-length limit is a blemish, alleviated only slightly by
.BR \-l .
/* for dbm and dbz */
typedef struct {
char *dptr;
int dsize;
} datum;
/* standard dbm functions */
extern int dbminit();
extern datum fetch();
extern int store();
extern int delete(); /* not in dbz */
extern datum firstkey(); /* not in dbz */
extern datum nextkey(); /* not in dbz */
extern int dbmclose(); /* in dbz, but not in old dbm */
/* new stuff for dbz */
extern int dbzfresh();
extern int dbzagain();
extern datum dbzfetch();
extern int dbzstore();
extern int dbzsync();
extern long dbzsize();
extern int dbzincore();
extern int dbzcancel();
extern int dbzdebug();
/*
* In principle we could handle unlimited-length keys by operating a chunk
* at a time, but it's not worth it in practice. Setting a nice large
* bound on them simplifies the code and doesn't hurt anything.
*/
#define DBZMAXKEY 255
/*
* fake - make up random lines resembling history-file entries, reproducibly
*
* -Log-
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#define MAXSTR 500 /* For sizing strings -- DON'T use BUFSIZ! */
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
int midonly = 0; /* just message ids, rest not realistic */
int tag = 0; /* tag lines with random digit for later use */
int expired = -1; /* percentage of lines to be expired */
int debug = 0;
char *progname;
char *inname; /* filename for messages etc. */
long lineno; /* line number for messages etc. */
void doline();
void addchars();
void seed();
/*
- main - parse arguments and handle options
*/
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
int errflg = 0;
FILE *in;
struct stat statbuf;
extern int optind;
extern char *optarg;
void process();
register long no;
extern long atol();
char line[MAXSTR];
progname = argv[0];
while ((c = getopt(argc, argv, "ms:te:d")) != EOF)
switch (c) {
case 'm': /* message-ids only */
midonly = 1;
break;
case 's': /* seed */
seed(atol(optarg));
break;
case 't': /* tag lines with a random digit */
tag = 1;
break;
case 'e': /* percentage to be expired */
expired = atoi(optarg);
break;
case 'd': /* Debugging. */
debug++;
break;
case '?':
default:
errflg++;
break;
}
if (errflg || optind != argc - 1) {
fprintf(stderr, "usage: %s ", progname);
fprintf(stderr, "[-m] [-s seed] length\n");
exit(2);
}
for (no = atol(argv[optind]); no > 0; no--) {
doline(line);
puts(line);
}
#ifdef DBZ_FINISH
DBZ_FINISH;
#endif
exit(0);
}
/*
- doline - generate random history pseudo-line
*/
void
doline(buf)
char *buf;
{
char tagch[2];
(void) strcpy(buf, "<");
addchars(buf, range(4, 20));
(void) strcat(buf, "@");
addchars(buf, range(8, 20));
if (midonly)
(void) strcat(buf, ">\tx");
else {
if (tag) {
tagch[0] = "1234567890"[range(0,9)];
tagch[1] = '\0';
(void) strcat(buf, ">\t");
(void) strcat(buf, tagch);
(void) strcat(buf, "00000000~-");
} else
(void) strcat(buf, ">\t1234567890~-");
}
if (range(1, 100) > expired) {
if (midonly)
(void) strcat(buf, "\tx");
else {
(void) strcat(buf, "\t");
addchars(buf, range(10, 30));
}
}
}
/*
- addchars - generate n random characters suitable for history file
*/
void
addchars(buf, len)
char *buf;
int len;
{
register int i;
register char *p = buf + strlen(buf);
static char vocab[] = "1234567890.abcde.fghij.klmno.pqrst.uvwxyz.\
1234567890.ABCDE.FGHIJ.KLMNO.PQRST.UVWXYZ.1234567890.\
1234567890.abcde.fghij.klmno.pqrst.uvwxyz.1234567890";
for (i = len; i > 0; i--)
*p++ = vocab[range(0, sizeof(vocab)-2)];
*p++ = '\0';
}
<m....VO1.9q.@s95e1zKsIj7LrIwa1> 600000000~- 90fz0706yo.1Env21x8b
<H5.i.R6ZQ2@Vg6.5mqj8..z> 200000000~-
<1Hy.ufmjqe371x5.o@HEEl0tAp4> 700000000~-
<T6.c9.xM4i@943..7z.c..3h> 600000000~-
<Exus7LsME4fPL9v8@2.ouu97O25z9cdft> 700000000~-
<6kUzkf.v74@iC1iGj882RQ0zli> 400000000~-
<J.7YT7dV.Kkul8Bh0fc@Rar.EnMx2lm0.6Yeob> 600000000~-
<.wVJi1DX42@5.4i6.jaZ6qw9Ln1.> 500000000~-
<uUd9e18vxzevae7uY@33a480208l0.4p2q> 300000000~-
<43hQ.5shbE7@912400.ajES6x0sXl.M> 400000000~-
<g25r..2r.0WOZ6k3@tb3.U9xrR.uw61a2y0> 600000000~-
<923s5e67d5Oq085Y.1@6Pik68584> 900000000~-
<.5.n5cx5aD62i9q8@Ai60Sc.4x> 200000000~-
<9N9n@3.1ql87.yj2xFs.zLqI> 700000000~- Q2.kni8kZps7kF5uiEv32B38y4z.p
<.X.fw.6LtoT.0@pp6bp.5s6yh74.> 400000000~-
<54c1w@7..u1.99m9T4j.BNGBiK> 600000000~- .F3hb.OFh06V..p
<j12Mtn6q9@m2.m1X1s> 500000000~-
<o1WJV9G4H.zf0BX44w@W7.76xn33> 000000000~-
<0C605s6plaAgfM.ap40@e6d66n.uv01W.j.8ph.> 100000000~- m.x7TY8.8DQ5
<.2.14xdn.@D0g.W.uZ.75gyyg.q1G> 100000000~-
<.A..03.@5v..64.5v3.3tbjUo.> 500000000~-
<72..c19ms65.WCf0G3.@83seEG9nnhM.O.j22> 900000000~-
<D..xX.kti9@u739li.xvy2> 000000000~- NPLL42XVfM
<6HO.nFal1ufl3.8b@3.n0k7a.IDgNy> 700000000~- Wv4j3Itccnh0Zp3
<x5RjUnIpd03xBBnuN@z0puc82Q26Ou.0T6> 400000000~- k67.hvXwv6X745R4rh2ybuFN3n.
<62dIeg.fW92.ov375@x76mf5c6.37.v> 000000000~-
<chdpqs.0mgZOp.@Dxl9v..94e7ar2> 900000000~-
<.9Xr.7V91..oe5CG.hX@p5x3jos3s27R6O3yj1> 400000000~-
<Mm6dr.231dH35ua@SE1u0za3V1M43lRn9> 100000000~-
<JIhw2@.Qdf.8v28Tnf1M> 200000000~-
<z4FCa.q4MF..EE0.2@W9U63e33h9w3lcFFl> 400000000~-
<87.W3r6is4.@svVqQCBiNqz400A.qwj> 200000000~-
<0liI7Lu0Mx435m7M99@87Xw.8j63.9.> 500000000~-
<tRtht5M.6d0@06gj.qm3.s9> 200000000~- e27S.BKVD70P.o
<Jpga8@m68yvw.b4b> 200000000~-
<.2.69hy3JT1@Aq3.r83o.9> 700000000~-
<.W7EurYppo4fhzs.I@8651m2W7v> 700000000~-
<3m02.@22074.a5ct2j3> 900000000~-
<.fy9Epa@.1.kNGCNokFwB8ezo1WM> 800000000~-
<c758d64.FS4yY7L5@43sw.kI6> 900000000~-
<vLd0.t@.kq70oHl96ixdnXd.GVv> 100000000~- 9A6Ejq5t55I4VJ6.q1
<d3.4@n17p4N.77N7W..7.8> 300000000~-
<f2lv064.8@4jokk3e07> 400000000~-
<rr7hoxA.U7.JXxnpvd@1rbMO437vHnakx> 000000000~-
<.0p3G7novlrYz9kjI@Sx.2w.yqzerZl12781.k> 700000000~-
<51ny.pQ7ay4@nfU2l1f0ixG09584.m> 000000000~- 38K5bhK7cr6.bg.5MlC2Fxq06Ziuw.
<2.cau.9s@.n4Pk0Jd9g> 300000000~-
<bEH1Bwa.662i@zm.3g.gx4.lp3> 300000000~- c8.t4Q0.8t0.m50
<.t13789u5AqM4m3.z0T@P17e.ypf> 200000000~- q17z.fZ3.FyD533WthqZs8q7
<M4r1I@Ovaev.dp> 100000000~-
#!/bin/sh
awk 'NR == 1 {
for (i = 9; i <= NF; i++)
printf "%s ", $i
printf "\n"
}' $*
/*
* random-number generator for testing
*/
static unsigned long next = 1;
/*
- range - generate a random number within an inclusive range
*
* Algorithm from ANSI C standard. Limitation: max-min <= 32767.
*/
int
range(min, max)
int min;
int max;
{
register int temp;
next = next * 1103515245 + 12345;
temp = (int)((next/65536)%32768);
return(temp%(max - min + 1) + min);
}
/*
- seed - seed random number generator
*/
void
seed(n)
long n;
{
next = (unsigned long)n;
}
NR == 1 {
printf "%s %s %s %s %s %s %s %s %s", $1, $2, $3, $4, $5, $6, $7, $8, $9
for (i = NF; i > 9; i--)
printf " %s", $i
printf "\n"
}
NR > 1 { print }
#include "../iostdio.h"
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 1993, 2000 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License.
Written by Per Bothner (bothner@cygnus.com). */
#ifndef _EDITBUF_H
#define _EDITBUF_H
#ifdef __GNUG__
#pragma interface
#endif
#include <stdio.h>
#include <fstream.h>
extern "C++" {
typedef unsigned long mark_pointer;
// At some point, it might be nice to parameterize this code
// in terms of buf_char.
typedef /*unsigned*/ char buf_char;
// Logical pos from start of buffer (does not count gap).
typedef long buf_index;
// Pos from start of buffer, possibly including gap_size.
typedef long buf_offset;
#if 0
struct buf_cookie {
FILE *file;
struct edit_string *str;
struct buf_cookie *next;
buf_index tell();
};
#endif
struct edit_buffer;
struct edit_mark;
// A edit_string is defined as the region between the 'start' and 'end' marks.
// Normally (always?) 'start->insert_before()' should be false,
// and 'end->insert_before()' should be true.
struct edit_string {
struct edit_buffer *buffer; // buffer that 'start' and 'end' belong to
struct edit_mark *start, *end;
int length() const; // count of buf_chars currently in string
edit_string(struct edit_buffer *b,
struct edit_mark *ms, struct edit_mark *me)
{ buffer = b; start = ms; end = me; }
/* Make a fresh, contiguous copy of the data in STR.
Assign length of STR to *LENP.
(Output has extra NUL at out[*LENP].) */
buf_char *copy_bytes(int *lenp) const;
// FILE *open_file(char *mode);
void assign(struct edit_string *src); // copy bytes from src to this
};
struct edit_streambuf : public streambuf {
friend class edit_buffer;
edit_string *str;
edit_streambuf* next; // Chain of edit_streambuf's for a edit_buffer.
short _mode;
edit_streambuf(edit_string* bstr, int mode);
~edit_streambuf();
virtual int underflow();
virtual int overflow(int c = EOF);
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
void flush_to_buffer();
void flush_to_buffer(edit_buffer* buffer);
int _inserting;
int inserting() { return _inserting; }
void inserting(int i) { _inserting = i; }
// int delete_chars(int count, char* cut_buf); Not implemented.
int truncate();
int is_reading() { return gptr() != NULL; }
buf_char* current() { return is_reading() ? gptr() : pptr(); }
void set_current(char *p, int is_reading);
protected:
void disconnect_gap_from_file(edit_buffer* buffer);
};
// A 'edit_mark' indicates a position in a buffer.
// It is "attached" the text (rather than the offset).
// There are two kinds of mark, which have different behavior
// when text is inserted at the mark:
// If 'insert_before()' is true the mark will be adjusted to be
// *after* the new text.
struct edit_mark {
struct edit_mark *chain;
mark_pointer _pos;
inline int insert_before() { return _pos & 1; }
inline unsigned long index_in_buffer(struct edit_buffer *)
{ return _pos >> 1; }
inline buf_char *ptr(struct edit_buffer *buf);
buf_index tell();
edit_mark() { }
edit_mark(struct edit_string *str, long delta);
edit_buffer *buffer();
~edit_mark();
};
// A 'edit_buffer' consists of a sequence of buf_chars (the data),
// a list of edit_marks pointing into the data, and a list of FILEs
// also pointing into the data.
// A 'edit_buffer' coerced to a edit_string is the string of
// all the buf_chars in the buffer.
// This implementation uses a conventional buffer gap (as in Emacs).
// The gap start is defined by de-referencing a (buf_char**).
// This is because sometimes a FILE is inserting into the buffer,
// so rather than having each putc adjust the gap, we use indirection
// to have the gap be defined as the write pointer of the FILE.
// (This assumes that putc adjusts a pointer (as in GNU's libc), not an index.)
struct edit_buffer {
buf_char *data; /* == emacs buffer_text.p1+1 */
buf_char *_gap_start;
edit_streambuf* _writer; // If non-NULL, currently writing stream
inline buf_char *gap_start()
{ return _writer ? _writer->pptr() : _gap_start; }
buf_offset __gap_end_pos; // size of part 1 + size of gap
/* int gap; implicit: buf_size - size1 - size2 */
int buf_size;
struct edit_streambuf *files;
struct edit_mark start_mark;
struct edit_mark end_mark;
edit_buffer();
inline buf_offset gap_end_pos() { return __gap_end_pos; }
inline struct edit_mark *start_marker() { return &start_mark; }
inline struct edit_mark *end_marker() { return &end_mark; }
/* these should be protected, ultimately */
buf_index tell(edit_mark*);
buf_index tell(buf_char*);
inline buf_char *gap_end() { return data + gap_end_pos(); }
inline int gap_size() { return gap_end() - gap_start(); }
inline int size1() { return gap_start() - data; }
inline int size2() { return buf_size - gap_end_pos(); }
inline struct edit_mark * mark_list() { return &start_mark; }
void make_gap (buf_offset);
void move_gap (buf_offset pos);
void move_gap (buf_char *pos) { move_gap(pos - data); }
void gap_left (int pos);
void gap_right (int pos);
void adjust_markers(mark_pointer low, mark_pointer high,
int amount, buf_char *old_data);
void delete_range(buf_index from, buf_index to);
void delete_range(struct edit_mark *start, struct edit_mark *end);
};
extern buf_char * bstr_copy(struct edit_string *str, int *lenp);
// Convert a edit_mark to a (buf_char*)
inline buf_char *edit_mark::ptr(struct edit_buffer *buf)
{ return buf->data + index_in_buffer(buf); }
inline void edit_streambuf::flush_to_buffer()
{
edit_buffer* buffer = str->buffer;
if (buffer->_writer == this) flush_to_buffer(buffer);
}
} // extern "C++"
#endif /* !_EDITBUF_H*/
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 1993, 1995, 1999 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License.
Written by Per Bothner (bothner@cygnus.com). */
#include "iostreamP.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "builtinbuf.h"
void filebuf::init()
{
_IO_file_init(this);
}
filebuf::filebuf()
{
_IO_file_init(this);
}
#if !_IO_UNIFIED_JUMPTABLES
/* This is like "new filebuf()", but it uses the _IO_file_jump jumptable,
for eficiency. */
filebuf* filebuf::__new()
{
filebuf *fb = new filebuf;
_IO_JUMPS(fb) = &_IO_file_jumps;
fb->_vtable() = builtinbuf_vtable;
return fb;
}
#endif
filebuf::filebuf(int fd)
{
_IO_file_init(this);
_IO_file_attach(this, fd);
}
filebuf::filebuf(int fd, char* p, int len)
{
_IO_file_init(this);
_IO_file_attach(this, fd);
setbuf(p, len);
}
filebuf::~filebuf()
{
if (_IO_file_is_open(this))
{
_IO_do_flush (this);
if (!(xflags() & _IO_DELETE_DONT_CLOSE))
_IO_SYSCLOSE (this);
}
}
filebuf* filebuf::open(const char *filename, ios::openmode mode, int prot)
{
if (_IO_file_is_open (this))
return NULL;
int posix_mode;
int read_write;
if (mode & ios::app)
mode |= ios::out;
if ((mode & (ios::in|ios::out)) == (ios::in|ios::out)) {
posix_mode = O_RDWR;
read_write = 0;
}
else if (mode & ios::out)
posix_mode = O_WRONLY, read_write = _IO_NO_READS;
else if (mode & (int)ios::in)
posix_mode = O_RDONLY, read_write = _IO_NO_WRITES;
else
posix_mode = 0, read_write = _IO_NO_READS+_IO_NO_WRITES;
if (mode & ios::binary)
{
mode &= ~ios::binary;
#ifdef O_BINARY
/* This is a (mis-)feature of DOS/Windows C libraries. */
posix_mode |= O_BINARY;
#endif
}
if ((mode & (int)ios::trunc) || mode == (int)ios::out)
posix_mode |= O_TRUNC;
if (mode & ios::app)
posix_mode |= O_APPEND, read_write |= _IO_IS_APPENDING;
if (!(mode & (int)ios::nocreate) && mode != ios::in)
posix_mode |= O_CREAT;
if (mode & (int)ios::noreplace)
posix_mode |= O_EXCL;
#if _G_HAVE_IO_FILE_OPEN
if (!_IO_file_open (this, filename, posix_mode, prot,
read_write, 0))
return NULL;
if (mode & ios::ate) {
if (pubseekoff(0, ios::end) == EOF) {
_IO_un_link (this);
return NULL;
}
}
return this;
#else
int fd = ::open(filename, posix_mode, prot);
if (fd < 0)
return NULL;
_fileno = fd;
xsetflags(read_write, _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
if (mode & ios::ate) {
if (pubseekoff(0, ios::end) == EOF)
return NULL;
}
_IO_link_in(this);
return this;
#endif
}
filebuf* filebuf::open(const char *filename, const char *mode)
{
#if _G_IO_IO_FILE_VERSION == 0x20001
return (filebuf*)_IO_file_fopen(this, filename, mode, 0);
#else
return (filebuf*)_IO_file_fopen(this, filename, mode);
#endif
}
filebuf* filebuf::attach(int fd)
{
return (filebuf*)_IO_file_attach(this, fd);
}
streambuf* filebuf::setbuf(char* p, int len)
{
return (streambuf*)_IO_file_setbuf (this, p, len);
}
int filebuf::doallocate() { return _IO_file_doallocate(this); }
int filebuf::overflow(int c)
{
return _IO_file_overflow(this, c);
}
int filebuf::underflow()
{
return _IO_file_underflow(this);
}
int filebuf::sync()
{
return _IO_file_sync(this);
}
streampos filebuf::seekoff(streamoff offset, _seek_dir dir, int mode)
{
return _IO_file_seekoff (this, offset, dir, mode);
}
filebuf* filebuf::close()
{
return (_IO_file_close_it(this) ? (filebuf*)NULL : this);
}
streamsize filebuf::sys_read(char* buf, streamsize size)
{
return _IO_file_read(this, buf, size);
}
streampos filebuf::sys_seek(streamoff offset, _seek_dir dir)
{
return _IO_file_seek(this, offset, dir);
}
streamsize filebuf::sys_write(const char *buf, streamsize n)
{
return _IO_file_write (this, buf, n);
}
int filebuf::sys_stat(void* st)
{
return _IO_file_stat (this, st);
}
int filebuf::sys_close()
{
return _IO_file_close (this);
}
streamsize filebuf::xsputn(const char *s, streamsize n)
{
return _IO_file_xsputn(this, s, n);
}
streamsize filebuf::xsgetn(char *s, streamsize n)
{
// FIXME: OPTIMIZE THIS (specifically, when unbuffered()).
return streambuf::xsgetn(s, n);
}
// Non-ANSI AT&T-ism: Default open protection.
const int filebuf::openprot = 0644;
/* 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. */
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. [rescinded 22 July 1999]
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* Modified for GNU iostream by Per Bothner 1991, 1992. */
#include "libioP.h"
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __STDC__
#include <stdlib.h>
#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.
*
* As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
* optimisation) right after the _fstat() that finds the buffer size.
*/
int
_IO_file_doallocate (fp)
_IO_FILE *fp;
{
_IO_size_t size;
int couldbetty;
char *p;
struct stat st;
#if !defined(_LIBC) && !defined(__linux__)
/* 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) ();
#endif
if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0)
{
couldbetty = 0;
size = _IO_BUFSIZ;
#if 0
/* do not try to optimise fseek() */
fp->_flags |= __SNPT;
#endif
}
else
{
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
}
ALLOC_BUF (p, size, EOF);
_IO_setb (fp, p, p + size, 1);
if (couldbetty && isatty (fp->_fileno))
fp->_flags |= _IO_LINE_BUF;
return 1;
}
/*
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. [rescinded 22 July 1999]
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* %W% (Berkeley) %G%
*/
/*
* Floating point scanf/printf (input/output) definitions.
*/
/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
#define MAXEXP 308
/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
#define MAXFRACT 39
/* 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
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License.
Written by Per Bothner (bothner@cygnus.com). */
#ifdef __GNUG__
#pragma implementation
#endif
#define _STREAM_COMPAT
extern "C" {
#include "libioP.h"
}
#include <fstream.h>
inline void
fstreambase::__fb_init()
{
#ifdef _IO_NEW_STREAMS
#if !_IO_UNIFIED_JUMPTABLES
/* Uses the _IO_file_jump jumptable, for eficiency. */
__my_fb._jumps = &_IO_file_jumps;
__my_fb._vtable() = builtinbuf_vtable;
#endif
init (&__my_fb);
#else
init(filebuf::__new());
_flags &= ~ios::dont_close;
#endif
}
fstreambase::fstreambase()
{
__fb_init ();
}
fstreambase::fstreambase(int fd)
{
__fb_init ();
_IO_file_attach(rdbuf(), fd);
}
fstreambase::fstreambase(const char *name, int mode, int prot)
{
__fb_init ();
if (!rdbuf()->open(name, mode, prot))
set(ios::badbit);
}
fstreambase::fstreambase(int fd, char *p, int l)
{
#ifdef _IO_NEW_STREAMS
__fb_init ();
#else
init(filebuf::__new());
#endif
_IO_file_attach(rdbuf(), fd);
_IO_file_setbuf(rdbuf(), p, l);
}
void fstreambase::open(const char *name, int mode, int prot)
{
clear();
if (!rdbuf()->open(name, mode, prot))
set(ios::badbit);
}
void fstreambase::close()
{
if (!rdbuf()->close())
set(ios::failbit);
}
void fstreambase::attach(int fd)
{
if (!rdbuf()->attach(fd))
set(ios::failbit);
}
#if 0
static int mode_to_sys(enum open_mode mode)
{
return O_WRONLY;
}
static char* fopen_cmd_arg(io_mode i)
{
return "w";
}
#endif
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 1993, 2000 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef _FSTREAM_H
#define _FSTREAM_H
#ifdef __GNUG__
#pragma interface
#endif
#include <iostream.h>
extern "C++" {
class fstreambase : virtual public ios {
#ifdef _IO_NEW_STREAMS
mutable filebuf __my_fb; // mutable so rdbuf() can be const
#endif
void __fb_init ();
public:
fstreambase();
fstreambase(int fd);
fstreambase(int fd, char *p, int l); /* Deprecated */
fstreambase(const char *name, int mode, int prot=0664);
void close();
#ifdef _IO_NEW_STREAMS
filebuf* rdbuf() const { return &__my_fb; }
#else
filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
#endif
void open(const char *name, int mode, int prot=0664);
int is_open() const { return rdbuf()->is_open(); }
void setbuf(char *ptr, int len) { rdbuf()->setbuf(ptr, len); }
void attach(int fd);
#ifdef _STREAM_COMPAT
int filedesc() { return rdbuf()->fd(); }
fstreambase& raw() { rdbuf()->setbuf(NULL, 0); return *this; }
#endif
};
class ifstream : public fstreambase, public istream {
public:
ifstream() : fstreambase() { }
ifstream(int fd) : fstreambase(fd) { }
ifstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
ifstream(const char *name, int mode=ios::in, int prot=0664)
: fstreambase(name, mode | ios::in, prot) { }
void open(const char *name, int mode=ios::in, int prot=0664)
{ fstreambase::open(name, mode | ios::in, prot); }
};
class ofstream : public fstreambase, public ostream {
public:
ofstream() : fstreambase() { }
ofstream(int fd) : fstreambase(fd) { }
ofstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
ofstream(const char *name, int mode=ios::out, int prot=0664)
: fstreambase(name, mode | ios::out, prot) { }
void open(const char *name, int mode=ios::out, int prot=0664)
{ fstreambase::open(name, mode | ios::out, prot); }
};
class fstream : public fstreambase, public iostream {
public:
fstream() : fstreambase() { }
fstream(int fd) : fstreambase(fd) { }
fstream(const char *name, int mode, int prot=0664)
: fstreambase(name, mode, prot) { }
fstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
void open(const char *name, int mode, int prot=0664)
{ fstreambase::open(name, mode, prot); }
};
} // extern "C++"
#endif /*!_FSTREAM_H*/
/* Thread package specific definitions of stream lock type.
Copyright (C) 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. */
#ifndef _LIBIO_LOCK_H
#define _LIBIO_LOCK_H 1
typedef void *_IO_lock_t;
/* We need recursive (counting) mutexes. */
#define _IO_lock_initializer NULL
#define _IO_cleanup_region_start(_fct, _fp)
#define _IO_cleanup_region_end(_doit)
#define _IO_lock_init(_name)
#define _IO_lock_fini(_name)
#define _IO_lock_lock(_name)
#define _IO_lock_unlock(_name)
#endif /* libio-lock.h */
/* this will be used later*/
/* 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
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License.
Written by Per Bothner (bothner@cygnus.com). */
#ifdef __GNUG__
#pragma implementation
#endif
#include <indstream.h>
indirectbuf::indirectbuf(streambuf *get, streambuf *put, int delete_mode)
: streambuf()
{
_get_stream = get;
_put_stream = put == NULL ? get : put;
_delete_flags = delete_mode;
}
indirectbuf::~indirectbuf()
{
if (_delete_flags & ios::in) delete get_stream();
if (_delete_flags & ios::out) delete put_stream();
}
streamsize indirectbuf::xsputn(const char* s, streamsize n)
{
return put_stream()->sputn(s, n);
}
streamsize indirectbuf::xsgetn(char* s, streamsize n)
{
return get_stream()->sgetn(s, n);
}
int indirectbuf::overflow(int c /* = EOF */)
{
if (c == EOF)
return put_stream()->overflow(c);
else
return put_stream()->sputc(c);
}
int indirectbuf::underflow()
{
return get_stream()->sgetc();
}
int indirectbuf::uflow()
{
return get_stream()->sbumpc();
}
streampos indirectbuf::seekoff(streamoff off, _seek_dir dir, int mode)
{
int ret_val = 0;
int select = mode == 0 ? (ios::in|ios::out) : mode;
streambuf *gbuf = (select & ios::in) ? get_stream() : (streambuf*)NULL;
streambuf *pbuf = (select & ios::out) ? put_stream() : (streambuf*)NULL;
if (gbuf == pbuf)
ret_val = gbuf->seekoff(off, dir, mode);
else {
if (gbuf)
ret_val = gbuf->seekoff(off, dir, ios::in);
if (pbuf && ret_val != EOF)
ret_val = pbuf->seekoff(off, dir, ios::out);
}
return ret_val;
}
streampos indirectbuf::seekpos(streampos pos, int mode)
{
int ret_val = EOF;
int select = mode == 0 ? (ios::in|ios::out) : mode;
streambuf *gbuf = (select & ios::in) ? get_stream() : (streambuf*)NULL;
streambuf *pbuf = (select & ios::out) ? put_stream() : (streambuf*)NULL;
if (gbuf == pbuf && gbuf != NULL)
ret_val = gbuf->seekpos(pos, mode);
else {
if (gbuf)
ret_val = gbuf->seekpos(pos, ios::in);
if (pbuf && ret_val != EOF)
ret_val = pbuf->seekpos(pos, ios::out);
}
return ret_val;
}
int indirectbuf::sync()
{
streambuf *gbuf = get_stream();
int get_ret_val = gbuf ? gbuf->sync() : 0;
streambuf *pbuf = put_stream();
int put_ret_val = (pbuf && pbuf != gbuf) ? pbuf->sync() : 0;
return get_ret_val || put_ret_val;
}
int indirectbuf::pbackfail(int c)
{
return get_stream()->sputbackc(c);
}
/* 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
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License.
Written by Per Bothner (bothner@cygnus.com). */
#ifndef _INDSTREAM_H
#define _INDSTREAM_H
#ifdef __GNUG__
#pragma interface
#endif
#include <iostream.h>
extern "C++" {
// An indirectbuf is one that forwards all of its I/O requests
// to another streambuf.
// All get-related requests are sent to get_stream().
// All put-related requests are sent to put_stream().
// An indirectbuf can be used to implement Common Lisp
// synonym-streams and two-way-streams.
//
// class synonymbuf : public indirectbuf {
// Symbol *sym;
// synonymbuf(Symbol *s) { sym = s; }
// virtual streambuf *lookup_stream(int mode) {
// return coerce_to_streambuf(lookup_value(sym)); }
// };
class indirectbuf : public streambuf {
protected:
streambuf *_get_stream; // Optional cache for get_stream().
streambuf *_put_stream; // Optional cache for put_stream().
int _delete_flags;
public:
streambuf *get_stream()
{ return _get_stream ? _get_stream : lookup_stream(ios::in); }
streambuf *put_stream()
{ return _put_stream ? _put_stream : lookup_stream(ios::out); }
virtual streambuf *lookup_stream(int/*mode*/) { return NULL; } // ERROR!
indirectbuf(streambuf *get=NULL, streambuf *put=NULL, int delete_mode=0);
virtual ~indirectbuf();
virtual streamsize xsputn(const char* s, streamsize n);
virtual streamsize xsgetn(char* s, streamsize n);
virtual int underflow();
virtual int uflow();
virtual int overflow(int c = EOF);
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
virtual int sync();
virtual int pbackfail(int c);
};
} // extern "C++"
#endif /* !_INDSTREAM_H */
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 1994 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/* Written by Per Bothner (bothner@cygnus.com). */
#include <iostream.h>
#include "libioP.h"
// These method are provided for backward compatibility reasons.
// It's generally poor style to use them.
// They are not supported by the ANSI/ISO working paper.
_IO_istream_withassign& _IO_istream_withassign::operator=(istream& rhs)
{
if (&rhs != (istream*)this)
{
init (rhs.rdbuf ());
_gcount = 0;
}
return *this;
}
_IO_ostream_withassign& _IO_ostream_withassign::operator=(ostream& rhs)
{
if (&rhs != (ostream*)this)
init (rhs.rdbuf ());
return *this;
}
/*
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#include <iostream.h>
static int __xalloc = 0;
int ios::xalloc()
{
return __xalloc++;
}
static ios::fmtflags __used_fmt_flags
= ios::skipws | ios::left | ios::right | ios::internal
| ios::dec | ios::oct | ios::hex | ios::showbase | ios::showpoint
| ios::uppercase | ios::showpos | ios::scientific | ios::fixed
#ifndef _IO_NEW_STREAMS
| ios::dont_close
#endif
| ios::unitbuf | ios::stdio;
ios::fmtflags ios::bitalloc()
{
fmtflags bit_to_try = (fmtflags)1;
for (; bit_to_try; bit_to_try <<= 1)
{
if ((__used_fmt_flags & bit_to_try) == 0)
{
__used_fmt_flags |= bit_to_try;
return bit_to_try;
}
}
return 0;
}
// NOTE: This implementation of ios::iword and ios::pword assumes
// that these methods are seldom used, so we want to minimize
// the space and time overhead when NOT using these methods.
//
// ANSI specifies two conceptually-infinite arrays, one whose
// elements are longs, and one whose elements are (void*)s.
// We implement this as a single array, each of whose element is
// a (struct ptr_and_long), which has space for both a long and a void*.
// We also specify that (the i field of) the 0'th element of the array
// contains the allocated length of the array (not counting that
// initial element).
struct ptr_and_long {
void *p;
long i;
};
static struct ptr_and_long&
get_array_element(ios& io, int index)
{
if (index < 0)
io._throw_failure();
register struct ptr_and_long *array = (ptr_and_long*)io._arrays;
int old_length = array == NULL ? 0 : array[0].i;
if (index >= old_length)
{
register int i;
int new_length = index + 10;
register struct ptr_and_long *new_array
= new ptr_and_long[1 + new_length];
if (array != NULL)
{
for (i = 1; i <= old_length; i++)
new_array[i] = array[i];
delete [] array;
}
for (i = old_length + 1; i <= new_length; i++)
{
new_array[i].i = 0;
new_array[i].p = NULL;
}
new_array[0].i = new_length;
new_array[0].p = NULL;
io._arrays = (void*)new_array;
array = new_array;
}
return array[index+1];
}
long& ios::iword(int index)
{
return get_array_element(*this, index).i;
}
void*& ios::pword(int index)
{
return get_array_element(*this, index).p;
}
long ios::iword(int index) const
{
if (index < 0)
_throw_failure();
register struct ptr_and_long *pl_array = (ptr_and_long*)_arrays;
int len = pl_array == NULL ? 0 : pl_array[0].i;
return index >= len ? 0 : pl_array[index+1].i;
}
void* ios::pword(int index) const
{
if (index < 0)
_throw_failure();
register struct ptr_and_long *pl_array = (ptr_and_long*)_arrays;
int len = pl_array == NULL ? 0 : pl_array[0].i;
return index >= len ? 0 : pl_array[index+1].p;
}
/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#ifdef __STDC__
#include <stdlib.h>
#endif
int
_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);
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)
#elif defined(_G_STDIO_USES_LIBIO) && defined(_G_HAVE_WEAK_SYMBOL)
int fclose (_IO_FILE *) __attribute__ ((weak, alias("_IO_fclose")));
#endif
/* Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#ifdef __STDC__
#include <stdlib.h>
#endif
#include "libioP.h"
#include <fcntl.h>
#ifndef _IO_fcntl
#define _IO_fcntl fcntl
#endif
_IO_FILE *
_IO_fdopen (fd, mode)
int fd;
const char *mode;
{
int read_write;
int posix_mode = 0;
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f;
int fd_flags;
switch (*mode++)
{
case 'r':
read_write = _IO_NO_WRITES;
break;
case 'w':
read_write = _IO_NO_READS;
break;
case 'a':
posix_mode = O_APPEND;
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
MAYBE_SET_EINVAL;
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
read_write &= _IO_IS_APPENDING;
#ifdef F_GETFL
fd_flags = _IO_fcntl (fd, F_GETFL);
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
if (fd_flags == -1
|| ((fd_flags & O_ACCMODE) == O_RDONLY && !(read_write & _IO_NO_WRITES))
|| ((fd_flags & O_ACCMODE) == O_WRONLY && !(read_write & _IO_NO_READS)))
return NULL;
/* The May 93 draft of P1003.4/D14.1 (redesignated as 1003.1b)
[System Application Program Interface (API) Amendment 1:
Realtime Extensions], Rationale B.8.3.3
Open a Stream on a File Descriptor says:
Although not explicitly required by POSIX.1, a good
implementation of append ("a") mode would cause the
O_APPEND flag to be set.
(Historical implementations [such as Solaris2] do a one-time
seek in fdopen.)
However, we do not turn O_APPEND off if the mode is "w" (even
though that would seem consistent) because that would be more
likely to break historical programs.
*/
if ((posix_mode & O_APPEND) && !(fd_flags & O_APPEND))
{
#ifdef F_SETFL
if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
#endif
return NULL;
}
#endif
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_attach (&new_f->fp.file, fd) == NULL)
{
_IO_un_link (&new_f->fp.file);
free (new_f);
return NULL;
}
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
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 *) &new_f->fp;
}
#ifdef weak_alias
weak_alias (_IO_fdopen, fdopen)
#endif
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
_IO_feof (fp)
_IO_FILE* fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_flockfile (fp);
result = _IO_feof_unlocked (fp);
_IO_funlockfile (fp);
return result;
}
#ifdef weak_alias
weak_alias (_IO_feof, feof)
#elif defined(_G_STDIO_USES_LIBIO) && defined(_G_HAVE_WEAK_SYMBOL)
int feof (_IO_FILE *) __attribute__ ((weak, alias("_IO_feof")));
#endif
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
int
_IO_ferror (fp)
_IO_FILE* fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_flockfile (fp);
result = _IO_ferror_unlocked (fp);
_IO_funlockfile (fp);
return result;
}
#ifdef weak_alias
weak_alias (_IO_ferror, ferror)
#elif defined(_G_STDIO_USES_LIBIO) && defined(_G_HAVE_WEAK_SYMBOL)
int ferror (_IO_FILE *) __attribute__ ((weak, alias("_IO_ferror")));
#endif
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <stdio.h>
int
_IO_fflush (fp)
_IO_FILE *fp;
{
if (fp == NULL)
return _IO_flush_all ();
else
{
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
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <stdio.h>
int
fflush_unlocked (fp)
_IO_FILE *fp;
{
if (fp == NULL)
return _IO_flush_all ();
else
{
CHECK_FILE (fp, EOF);
return _IO_SYNC (fp) ? EOF : 0;
}
}
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
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 <errno.h>
/* ANSI explicitly requires setting errno to a positive value on failure. */
int
_IO_fgetpos (fp, posp)
_IO_FILE* fp;
_IO_fpos_t *posp;
{
_IO_fpos_t pos;
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)
__set_errno (EIO);
#endif
return EOF;
}
*posp = pos;
return 0;
}
#ifdef weak_alias
weak_alias (_IO_fgetpos, fgetpos)
#endif
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include <stdio.h>
char *
_IO_fgets (buf, n, fp)
char *buf;
int n;
_IO_FILE *fp;
{
_IO_size_t count;
char *result;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
_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))
result = NULL;
else
{
buf[count] = '\0';
result = buf;
}
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_fgets, fgets)
#endif
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#ifdef __STDC__
#include <stdlib.h>
#endif
_IO_FILE *
_IO_fopen (filename, mode)
const char *filename;
const char *mode;
{
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#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
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
int
#ifdef __STDC__
_IO_fprintf (_IO_FILE *fp, const char* format, ...)
#else
_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);
return ret;
}
/* 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 <string.h>
int
_IO_fputs (str, fp)
const char *str;
_IO_FILE *fp;
{
_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
/* 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"
_IO_size_t
_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);
if (bytes_requested == 0)
return 0;
_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
/*
Copyright (C) 1993 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#include "libioP.h"
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
int
_IO_fscanf
#ifdef __STDC__
(_IO_FILE *fp, const char* format, ...)
#else
(fp, format, va_alist) _IO_FILE *fp; char *format; va_dcl
#endif
{
int ret;
va_list args;
CHECK_FILE(fp, EOF);
_IO_va_start(args, format);
ret = _IO_vfscanf(fp, format, args, NULL);
va_end(args);
return ret;
}
/* 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 <errno.h>
int
_IO_fsetpos (fp, posp)
_IO_FILE *fp;
const _IO_fpos_t *posp;
{
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 explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
result = EOF;
}
else
result = 0;
_IO_cleanup_region_end (1);
return result;
}
#ifdef weak_alias
weak_alias (_IO_fsetpos, fsetpos)
#endif
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
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 <errno.h>
/* ANSI explicily requires setting errno to a positive value on failure. */
long int
_IO_ftell (fp)
_IO_FILE *fp;
{
_IO_pos_t pos;
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)
__set_errno (EIO);
#endif
return -1L;
}
return _IO_pos_as_off (pos);
}
#ifdef weak_alias
weak_alias (_IO_ftell, ftell)
#endif
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
_IO_size_t
_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 written;
CHECK_FILE (fp, 0);
if (request == 0)
return 0;
_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 requires us to return count in this case. */
if (written == request)
return count;
else
return written / size;
}
#ifdef weak_alias
weak_alias (_IO_fwrite, fwrite)
#endif
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU General
Public License. This exception does not however invalidate any
other reasons why the executable file might be covered by the GNU
General Public License. */
#include "libioP.h"
#include "stdio.h"
#undef _IO_getc
int
_IO_getc (fp)
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_getc_unlocked (fp);
_IO_cleanup_region_end (1);
return result;
}
#undef getc
#ifdef weak_alias
weak_alias (_IO_getc, getc)
#elif defined(_G_STDIO_USES_LIBIO) && defined(_G_HAVE_WEAK_SYMBOL)
int getc (_IO_FILE *) __attribute__ ((weak, alias("_IO_getc")));
#endif
/* Copyright (C) 1994, 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. */
#ifdef __STDC__
#include <stdlib.h>
#endif
#include "libioP.h"
#include <string.h>
#include <errno.h>
/* Read up to (and including) a TERMINATOR from FP into *LINEPTR
(and null-terminate it). *LINEPTR is a pointer returned from malloc (or
NULL), pointing to *N characters of space. It is realloc'ed as
necessary. Returns the number of characters read (not including the
null terminator), or -1 on error or EOF. */
_IO_ssize_t
_IO_getdelim (lineptr, n, delimiter, fp)
char **lineptr;
_IO_size_t *n;
int delimiter;
_IO_FILE *fp;
{
int result;
_IO_ssize_t cur_len = 0;
_IO_ssize_t len;
if (lineptr == NULL || n == NULL)
{
MAYBE_SET_EINVAL;
return -1;
}
CHECK_FILE (fp, -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)
{
result = -1;
goto unlock_return;
}
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len <= 0)
{
if (__underflow (fp) == EOF)
{
result = -1;
goto unlock_return;
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
for (;;)
{
_IO_size_t needed;
char *t;
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. */
needed = cur_len + len + 1;
if (needed > *n)
{
if (needed < 2 * *n)
needed = 2 * *n; /* Be generous. */
*n = needed;
*lineptr = (char *) realloc (*lineptr, needed);
if (*lineptr == NULL)
{
result = -1;
goto unlock_return;
}
}
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
cur_len += len;
if (t != NULL || __underflow (fp) == EOF)
break;
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
(*lineptr)[cur_len] = '\0';
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
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment