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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <cerrno> |
|
28 #include <cstring> |
|
29 |
|
30 #include "error.h" |
|
31 #include "oct-fstrm.h" |
|
32 |
3340
|
33 octave_stream |
3570
|
34 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md, |
4587
|
35 oct_mach_info::float_format ff) |
3340
|
36 { |
4587
|
37 return octave_stream (new octave_fstream (nm_arg, arg_md, ff)); |
3340
|
38 } |
|
39 |
3552
|
40 octave_fstream::octave_fstream (const std::string& nm_arg, |
3570
|
41 std::ios::openmode arg_md, |
4587
|
42 oct_mach_info::float_format ff) |
|
43 : octave_base_stream (arg_md, ff), nm (nm_arg) |
2081
|
44 { |
3775
|
45 |
|
46 #if CXX_ISO_COMPLIANT_LIBRARY |
|
47 |
|
48 fs.open (nm.c_str (), arg_md); |
|
49 |
|
50 #else |
2081
|
51 // Override default protection of 0664 so that umask will appear to |
|
52 // do the right thing. |
|
53 |
3570
|
54 fs.open (nm.c_str (), arg_md, 0666); |
2081
|
55 |
3775
|
56 #endif |
|
57 |
2081
|
58 if (! fs) |
3531
|
59 { |
|
60 using namespace std; |
|
61 |
|
62 error (strerror (errno)); |
|
63 } |
2081
|
64 } |
|
65 |
|
66 // Position a stream at OFFSET relative to ORIGIN. |
|
67 |
|
68 int |
4797
|
69 octave_fstream::seek (long, int) |
2081
|
70 { |
4797
|
71 error ("fseek: invalid_operation"); |
|
72 return -1; |
2081
|
73 } |
|
74 |
|
75 // Return current stream position. |
|
76 |
4797
|
77 long |
|
78 octave_fstream::tell (void) |
2081
|
79 { |
4797
|
80 error ("ftell: invalid_operation"); |
|
81 return -1; |
2081
|
82 } |
|
83 |
|
84 // Return non-zero if EOF has been reached on this stream. |
|
85 |
|
86 bool |
|
87 octave_fstream::eof (void) const |
|
88 { |
|
89 return fs.eof (); |
|
90 } |
|
91 |
3652
|
92 void |
|
93 octave_fstream::do_close (void) |
|
94 { |
|
95 fs.close (); |
|
96 } |
|
97 |
3523
|
98 std::istream * |
2081
|
99 octave_fstream::input_stream (void) |
|
100 { |
3523
|
101 std::istream *retval = 0; |
2081
|
102 |
3544
|
103 if (mode () & std::ios::in) |
2081
|
104 retval = &fs; |
|
105 |
|
106 return retval; |
|
107 } |
|
108 |
3523
|
109 std::ostream * |
2081
|
110 octave_fstream::output_stream (void) |
|
111 { |
3523
|
112 std::ostream *retval = 0; |
2081
|
113 |
3544
|
114 if (mode () & std::ios::out) |
2081
|
115 retval = &fs; |
|
116 |
|
117 return retval; |
|
118 } |
|
119 |
|
120 /* |
|
121 ;;; Local Variables: *** |
|
122 ;;; mode: C++ *** |
|
123 ;;; End: *** |
|
124 */ |