oct-fstrm.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <cerrno>
00028 #include <cstring>
00029 
00030 #include "error.h"
00031 #include "oct-fstrm.h"
00032 
00033 octave_stream
00034 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md,
00035                         oct_mach_info::float_format ff)
00036 {
00037   return octave_stream (new octave_fstream (nm_arg, arg_md, ff));
00038 }
00039 
00040 octave_fstream::octave_fstream (const std::string& nm_arg,
00041                                 std::ios::openmode arg_md,
00042                                 oct_mach_info::float_format ff)
00043   : octave_base_stream (arg_md, ff), nm (nm_arg)
00044 {
00045 
00046 #if CXX_ISO_COMPLIANT_LIBRARY
00047 
00048   fs.open (nm.c_str (), arg_md);
00049 
00050 #else
00051   // Override default protection of 0664 so that umask will appear to
00052   // do the right thing.
00053 
00054   fs.open (nm.c_str (), arg_md, 0666);
00055 
00056 #endif
00057 
00058   if (! fs)
00059     error (gnulib::strerror (errno));
00060 }
00061 
00062 // Position a stream at OFFSET relative to ORIGIN.
00063 
00064 int
00065 octave_fstream::seek (long, int)
00066 {
00067   error ("fseek: invalid_operation");
00068   return -1;
00069 }
00070 
00071 // Return current stream position.
00072 
00073 long
00074 octave_fstream::tell (void)
00075 {
00076   error ("ftell: invalid_operation");
00077   return -1;
00078 }
00079 
00080 // Return non-zero if EOF has been reached on this stream.
00081 
00082 bool
00083 octave_fstream::eof (void) const
00084 {
00085   return fs.eof ();
00086 }
00087 
00088 void
00089 octave_fstream::do_close (void)
00090 {
00091   fs.close ();
00092 }
00093 
00094 std::istream *
00095 octave_fstream::input_stream (void)
00096 {
00097   std::istream *retval = 0;
00098 
00099   if (mode () & std::ios::in)
00100     retval = &fs;
00101 
00102   return retval;
00103 }
00104 
00105 std::ostream *
00106 octave_fstream::output_stream (void)
00107 {
00108   std::ostream *retval = 0;
00109 
00110   if (mode () & std::ios::out)
00111     retval = &fs;
00112 
00113   return retval;
00114 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines