2081
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2081
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2081
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <cerrno> |
|
29 #include <cstring> |
|
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, |
4587
|
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, |
3570
|
42 std::ios::openmode arg_md, |
4587
|
43 oct_mach_info::float_format ff) |
|
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) |
3531
|
60 { |
|
61 using namespace std; |
|
62 |
|
63 error (strerror (errno)); |
|
64 } |
2081
|
65 } |
|
66 |
|
67 // Position a stream at OFFSET relative to ORIGIN. |
|
68 |
|
69 int |
4797
|
70 octave_fstream::seek (long, int) |
2081
|
71 { |
4797
|
72 error ("fseek: invalid_operation"); |
|
73 return -1; |
2081
|
74 } |
|
75 |
|
76 // Return current stream position. |
|
77 |
4797
|
78 long |
|
79 octave_fstream::tell (void) |
2081
|
80 { |
4797
|
81 error ("ftell: invalid_operation"); |
|
82 return -1; |
2081
|
83 } |
|
84 |
|
85 // Return non-zero if EOF has been reached on this stream. |
|
86 |
|
87 bool |
|
88 octave_fstream::eof (void) const |
|
89 { |
|
90 return fs.eof (); |
|
91 } |
|
92 |
3652
|
93 void |
|
94 octave_fstream::do_close (void) |
|
95 { |
|
96 fs.close (); |
|
97 } |
|
98 |
3523
|
99 std::istream * |
2081
|
100 octave_fstream::input_stream (void) |
|
101 { |
3523
|
102 std::istream *retval = 0; |
2081
|
103 |
3544
|
104 if (mode () & std::ios::in) |
2081
|
105 retval = &fs; |
|
106 |
|
107 return retval; |
|
108 } |
|
109 |
3523
|
110 std::ostream * |
2081
|
111 octave_fstream::output_stream (void) |
|
112 { |
3523
|
113 std::ostream *retval = 0; |
2081
|
114 |
3544
|
115 if (mode () & std::ios::out) |
2081
|
116 retval = &fs; |
|
117 |
|
118 return retval; |
|
119 } |
|
120 |
|
121 /* |
|
122 ;;; Local Variables: *** |
|
123 ;;; mode: C++ *** |
|
124 ;;; End: *** |
|
125 */ |