1/* This is part of libio/iostream, providing -*- C++ -*- input/output. 2Copyright (C) 1993 Free Software Foundation 3 4This file is part of the GNU IO Library. This library is free 5software; you can redistribute it and/or modify it under the 6terms of the GNU General Public License as published by the 7Free Software Foundation; either version 2, or (at your option) 8any later version. 9 10This library is distributed in the hope that it will be useful, 11but WITHOUT ANY WARRANTY; without even the implied warranty of 12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13GNU General Public License for more details. 14 15You should have received a copy of the GNU General Public License 16along with this library; see the file COPYING. If not, write to the Free 17Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19As a special exception, if you link this library with files 20compiled with a GNU compiler to produce an executable, this does not cause 21the resulting executable to be covered by the GNU General Public License. 22This exception does not however invalidate any other reasons why 23the executable file might be covered by the GNU General Public License. 24 25Written by Per Bothner (bothner@cygnus.com). */ 26 27#ifdef __GNUG__ 28#pragma implementation 29#endif 30#define _STREAM_COMPAT 31extern "C" { 32#include "libioP.h" 33} 34#include <fstream.h> 35 36inline void 37fstreambase::__fb_init() 38{ 39#ifdef _IO_NEW_STREAMS 40#if !_IO_UNIFIED_JUMPTABLES 41 /* Uses the _IO_file_jump jumptable, for eficiency. */ 42 __my_fb._jumps = &_IO_file_jumps; 43 __my_fb._vtable() = builtinbuf_vtable; 44#endif 45 init (&__my_fb); 46#else 47 init(filebuf::__new()); 48 _flags &= ~ios::dont_close; 49#endif 50} 51 52fstreambase::fstreambase() 53{ 54 __fb_init (); 55} 56 57fstreambase::fstreambase(int fd) 58{ 59 __fb_init (); 60 _IO_file_attach(rdbuf(), fd); 61} 62 63fstreambase::fstreambase(const char *name, int mode, int prot) 64{ 65 __fb_init (); 66 if (!rdbuf()->open(name, mode, prot)) 67 set(ios::badbit); 68} 69 70fstreambase::fstreambase(int fd, char *p, int l) 71{ 72#ifdef _IO_NEW_STREAMS 73 __fb_init (); 74#else 75 init(filebuf::__new()); 76#endif 77 _IO_file_attach(rdbuf(), fd); 78 _IO_file_setbuf(rdbuf(), p, l); 79} 80 81void fstreambase::open(const char *name, int mode, int prot) 82{ 83 clear(); 84 if (!rdbuf()->open(name, mode, prot)) 85 set(ios::badbit); 86} 87 88void fstreambase::close() 89{ 90 if (!rdbuf()->close()) 91 set(ios::failbit); 92} 93 94void fstreambase::attach(int fd) 95{ 96 if (!rdbuf()->attach(fd)) 97 set(ios::failbit); 98} 99 100#if 0 101static int mode_to_sys(enum open_mode mode) 102{ 103 return O_WRONLY; 104} 105 106static char* fopen_cmd_arg(io_mode i) 107{ 108 return "w"; 109} 110#endif 111