Mercurial > hg > octave-nkf
annotate src/oct-fstrm.cc @ 11118:d517388b1c41
Added tag ss-3-3-53 for changeset 6c69a7c39039
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 19 Oct 2010 02:25:45 -0400 |
parents | bbe99b2a5ba7 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
2081 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2007 |
4 John W. Eaton | |
2081 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2081 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2081 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <cerrno> | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
29 #include <cstring> |
2081 | 30 |
31 #include "error.h" | |
32 #include "oct-fstrm.h" | |
33 | |
3340 | 34 octave_stream |
3570 | 35 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
36 oct_mach_info::float_format ff) |
3340 | 37 { |
4587 | 38 return octave_stream (new octave_fstream (nm_arg, arg_md, ff)); |
3340 | 39 } |
40 | |
3552 | 41 octave_fstream::octave_fstream (const std::string& nm_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
42 std::ios::openmode arg_md, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
43 oct_mach_info::float_format ff) |
4587 | 44 : octave_base_stream (arg_md, ff), nm (nm_arg) |
2081 | 45 { |
3775 | 46 |
47 #if CXX_ISO_COMPLIANT_LIBRARY | |
48 | |
49 fs.open (nm.c_str (), arg_md); | |
50 | |
51 #else | |
2081 | 52 // Override default protection of 0664 so that umask will appear to |
53 // do the right thing. | |
54 | |
3570 | 55 fs.open (nm.c_str (), arg_md, 0666); |
2081 | 56 |
3775 | 57 #endif |
58 | |
2081 | 59 if (! fs) |
10411 | 60 error (gnulib::strerror (errno)); |
2081 | 61 } |
62 | |
63 // Position a stream at OFFSET relative to ORIGIN. | |
64 | |
65 int | |
4797 | 66 octave_fstream::seek (long, int) |
2081 | 67 { |
4797 | 68 error ("fseek: invalid_operation"); |
69 return -1; | |
2081 | 70 } |
71 | |
72 // Return current stream position. | |
73 | |
4797 | 74 long |
75 octave_fstream::tell (void) | |
2081 | 76 { |
4797 | 77 error ("ftell: invalid_operation"); |
78 return -1; | |
2081 | 79 } |
80 | |
81 // Return non-zero if EOF has been reached on this stream. | |
82 | |
83 bool | |
84 octave_fstream::eof (void) const | |
85 { | |
86 return fs.eof (); | |
87 } | |
88 | |
3652 | 89 void |
90 octave_fstream::do_close (void) | |
91 { | |
92 fs.close (); | |
93 } | |
94 | |
3523 | 95 std::istream * |
2081 | 96 octave_fstream::input_stream (void) |
97 { | |
3523 | 98 std::istream *retval = 0; |
2081 | 99 |
3544 | 100 if (mode () & std::ios::in) |
2081 | 101 retval = &fs; |
102 | |
103 return retval; | |
104 } | |
105 | |
3523 | 106 std::ostream * |
2081 | 107 octave_fstream::output_stream (void) |
108 { | |
3523 | 109 std::ostream *retval = 0; |
2081 | 110 |
3544 | 111 if (mode () & std::ios::out) |
2081 | 112 retval = &fs; |
113 | |
114 return retval; | |
115 } |