1f2ced752SOliver Tappe/* This is part of libio/iostream, providing -*- C++ -*- input/output.
2f2ced752SOliver TappeCopyright (C) 1993, 2000 Free Software Foundation
3f2ced752SOliver Tappe
4f2ced752SOliver TappeThis file is part of the GNU IO Library.  This library is free
5f2ced752SOliver Tappesoftware; you can redistribute it and/or modify it under the
6f2ced752SOliver Tappeterms of the GNU General Public License as published by the
7f2ced752SOliver TappeFree Software Foundation; either version 2, or (at your option)
8f2ced752SOliver Tappeany later version.
9f2ced752SOliver Tappe
10f2ced752SOliver TappeThis library is distributed in the hope that it will be useful,
11f2ced752SOliver Tappebut WITHOUT ANY WARRANTY; without even the implied warranty of
13f2ced752SOliver TappeGNU General Public License for more details.
14f2ced752SOliver Tappe
15f2ced752SOliver TappeYou should have received a copy of the GNU General Public License
16f2ced752SOliver Tappealong with this library; see the file COPYING.  If not, write to the Free
17f2ced752SOliver TappeSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18f2ced752SOliver Tappe
19f2ced752SOliver TappeAs a special exception, if you link this library with files
20f2ced752SOliver Tappecompiled with a GNU compiler to produce an executable, this does not cause
21f2ced752SOliver Tappethe resulting executable to be covered by the GNU General Public License.
22f2ced752SOliver TappeThis exception does not however invalidate any other reasons why
23f2ced752SOliver Tappethe executable file might be covered by the GNU General Public License. */
24f2ced752SOliver Tappe
25f2ced752SOliver Tappe#ifndef _FSTREAM_H
26f2ced752SOliver Tappe#define _FSTREAM_H
27f2ced752SOliver Tappe#ifdef __GNUG__
28f2ced752SOliver Tappe#pragma interface
29f2ced752SOliver Tappe#endif
30f2ced752SOliver Tappe#include <iostream.h>
31f2ced752SOliver Tappe
32f2ced752SOliver Tappeextern "C++" {
33f2ced752SOliver Tappeclass fstreambase : virtual public ios {
34f2ced752SOliver Tappe#ifdef _IO_NEW_STREAMS
35f2ced752SOliver Tappe    mutable filebuf __my_fb; // mutable so rdbuf() can be const
36f2ced752SOliver Tappe#endif
37f2ced752SOliver Tappe    void __fb_init ();
38f2ced752SOliver Tappe  public:
39f2ced752SOliver Tappe    fstreambase();
40f2ced752SOliver Tappe    fstreambase(int fd);
41f2ced752SOliver Tappe    fstreambase(int fd, char *p, int l); /* Deprecated */
42f2ced752SOliver Tappe    fstreambase(const char *name, int mode, int prot=0664);
43f2ced752SOliver Tappe    void close();
44f2ced752SOliver Tappe#ifdef _IO_NEW_STREAMS
45f2ced752SOliver Tappe    filebuf* rdbuf() const { return &__my_fb; }
46f2ced752SOliver Tappe#else
47f2ced752SOliver Tappe    filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
48f2ced752SOliver Tappe#endif
49f2ced752SOliver Tappe    void open(const char *name, int mode, int prot=0664);
50f2ced752SOliver Tappe    int is_open() const { return rdbuf()->is_open(); }
51f2ced752SOliver Tappe    void setbuf(char *ptr, int len) { rdbuf()->setbuf(ptr, len); }
52f2ced752SOliver Tappe    void attach(int fd);
53f2ced752SOliver Tappe#ifdef _STREAM_COMPAT
54f2ced752SOliver Tappe    int filedesc() { return rdbuf()->fd(); }
55f2ced752SOliver Tappe    fstreambase& raw() { rdbuf()->setbuf(NULL, 0); return *this; }
56f2ced752SOliver Tappe#endif
57f2ced752SOliver Tappe};
58f2ced752SOliver Tappe
59f2ced752SOliver Tappeclass ifstream : public fstreambase, public istream {
60f2ced752SOliver Tappe  public:
61f2ced752SOliver Tappe    ifstream() : fstreambase() { }
62f2ced752SOliver Tappe    ifstream(int fd) : fstreambase(fd) { }
63f2ced752SOliver Tappe    ifstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
64f2ced752SOliver Tappe    ifstream(const char *name, int mode=ios::in, int prot=0664)
65f2ced752SOliver Tappe	: fstreambase(name, mode | ios::in, prot) { }
66f2ced752SOliver Tappe    void open(const char *name, int mode=ios::in, int prot=0664)
67f2ced752SOliver Tappe	{ fstreambase::open(name, mode | ios::in, prot); }
68f2ced752SOliver Tappe};
69f2ced752SOliver Tappe
70f2ced752SOliver Tappeclass ofstream : public fstreambase, public ostream {
71f2ced752SOliver Tappe  public:
72f2ced752SOliver Tappe    ofstream() : fstreambase() { }
73f2ced752SOliver Tappe    ofstream(int fd) : fstreambase(fd) { }
74f2ced752SOliver Tappe    ofstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
75f2ced752SOliver Tappe    ofstream(const char *name, int mode=ios::out, int prot=0664)
76f2ced752SOliver Tappe	: fstreambase(name, mode | ios::out, prot) { }
77f2ced752SOliver Tappe    void open(const char *name, int mode=ios::out, int prot=0664)
78f2ced752SOliver Tappe	{ fstreambase::open(name, mode | ios::out, prot); }
79f2ced752SOliver Tappe};
80f2ced752SOliver Tappe
81f2ced752SOliver Tappeclass fstream : public fstreambase, public iostream {
82f2ced752SOliver Tappe  public:
83f2ced752SOliver Tappe    fstream() : fstreambase() { }
84f2ced752SOliver Tappe    fstream(int fd) : fstreambase(fd) { }
85f2ced752SOliver Tappe    fstream(const char *name, int mode, int prot=0664)
86f2ced752SOliver Tappe	: fstreambase(name, mode, prot) { }
87f2ced752SOliver Tappe    fstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
88f2ced752SOliver Tappe    void open(const char *name, int mode, int prot=0664)
89f2ced752SOliver Tappe	{ fstreambase::open(name, mode, prot); }
90f2ced752SOliver Tappe};
91f2ced752SOliver Tappe} // extern "C++"
92f2ced752SOliver Tappe#endif /*!_FSTREAM_H*/