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