Mercurial > octave
annotate libinterp/corefcn/c-file-ptr-stream.cc @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | bd51beb6205e |
children | 3988112c7116 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 2000-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3628 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21550
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
3628 | 28 #endif |
29 | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
30 #include <iomanip> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
31 |
21913
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
32 #include "filepos-wrappers.h" |
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
33 |
3629 | 34 #include "c-file-ptr-stream.h" |
3628 | 35 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21550
diff
changeset
|
36 #if ! defined (SEEK_SET) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21184
diff
changeset
|
37 # define SEEK_SET 0 |
3628 | 38 #endif |
39 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21550
diff
changeset
|
40 #if ! defined (SEEK_CUR) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21184
diff
changeset
|
41 # define SEEK_CUR 1 |
3628 | 42 #endif |
43 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21550
diff
changeset
|
44 #if ! defined (SEEK_END) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21184
diff
changeset
|
45 # define SEEK_END 2 |
3628 | 46 #endif |
47 | |
3642 | 48 c_file_ptr_buf::~c_file_ptr_buf (void) |
49 { | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
50 buf_close (); |
3642 | 51 } |
3628 | 52 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 // FIXME: I'm sure there is room for improvement here... |
3628 | 54 |
3775 | 55 c_file_ptr_buf::int_type |
56 c_file_ptr_buf::overflow (int_type c) | |
3628 | 57 { |
3775 | 58 if (f) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21913
diff
changeset
|
59 return (c != traits_type::eof ()) ? std::fputc (c, f) : flush (); |
3775 | 60 else |
61 return traits_type::not_eof (c); | |
3628 | 62 } |
63 | |
3775 | 64 c_file_ptr_buf::int_type |
4310 | 65 c_file_ptr_buf::underflow_common (bool bump) |
3628 | 66 { |
3644 | 67 if (f) |
4310 | 68 { |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21913
diff
changeset
|
69 int_type c = std::fgetc (f); |
4310 | 70 |
21183
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
71 if (! bump && c != traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
72 ungetc (c, f); |
4310 | 73 |
74 return c; | |
75 } | |
3644 | 76 else |
3775 | 77 return traits_type::eof (); |
3628 | 78 } |
79 | |
3775 | 80 c_file_ptr_buf::int_type |
81 c_file_ptr_buf::pbackfail (int_type c) | |
3628 | 82 { |
21183
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
83 return ((c != traits_type::eof () && f) |
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
84 ? ungetc (c, f) : traits_type::not_eof (c)); |
3628 | 85 } |
86 | |
87 std::streamsize | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
88 c_file_ptr_buf::xsputn (const char *s, std::streamsize n) |
3628 | 89 { |
3644 | 90 if (f) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21913
diff
changeset
|
91 return std::fwrite (s, 1, n, f); |
3644 | 92 else |
93 return 0; | |
3628 | 94 } |
95 | |
96 std::streamsize | |
97 c_file_ptr_buf::xsgetn (char *s, std::streamsize n) | |
98 { | |
3644 | 99 if (f) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21913
diff
changeset
|
100 return std::fread (s, 1, n, f); |
3644 | 101 else |
102 return 0; | |
3628 | 103 } |
104 | |
105 static inline int | |
106 seekdir_to_whence (std::ios::seekdir dir) | |
107 { | |
21183
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
108 return (dir == std::ios::beg |
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
109 ? SEEK_SET : (dir == std::ios::cur |
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
110 ? SEEK_CUR : (dir == std::ios::end |
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
111 ? SEEK_END : dir))); |
3628 | 112 } |
113 | |
114 std::streampos | |
21550
7ebd8ac26178
Enable seekg and tellg on octave_stream (bug #47517)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
115 c_file_ptr_buf::seekoff (std::streamoff offset, |
7ebd8ac26178
Enable seekg and tellg on octave_stream (bug #47517)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
116 std::ios::seekdir dir, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
117 std::ios::openmode) |
3628 | 118 { |
3644 | 119 if (f) |
120 { | |
21913
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
121 octave_fseeko_wrapper (f, offset, seekdir_to_whence (dir)); |
3628 | 122 |
21913
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
123 return octave_ftello_wrapper (f); |
3644 | 124 } |
125 else | |
126 return 0; | |
3628 | 127 } |
128 | |
129 std::streampos | |
21550
7ebd8ac26178
Enable seekg and tellg on octave_stream (bug #47517)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
130 c_file_ptr_buf::seekpos (std::streampos offset, std::ios::openmode) |
3628 | 131 { |
3644 | 132 if (f) |
133 { | |
21913
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
134 octave_fseeko_wrapper (f, offset, SEEK_SET); |
3628 | 135 |
21913
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
136 return octave_ftello_wrapper (f); |
3644 | 137 } |
138 else | |
139 return 0; | |
3628 | 140 } |
141 | |
142 int | |
143 c_file_ptr_buf::sync (void) | |
144 { | |
3652 | 145 flush (); |
146 | |
3628 | 147 return 0; |
148 } | |
149 | |
3652 | 150 int |
151 c_file_ptr_buf::flush (void) | |
152 { | |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21913
diff
changeset
|
153 return f ? std::fflush (f) : traits_type::eof (); |
3652 | 154 } |
155 | |
156 int | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
157 c_file_ptr_buf::buf_close (void) |
3652 | 158 { |
3693 | 159 int retval = -1; |
160 | |
3716 | 161 flush (); |
162 | |
3652 | 163 if (f) |
3693 | 164 { |
3716 | 165 retval = cf (f); |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
166 f = nullptr; |
3693 | 167 } |
168 | |
169 return retval; | |
3652 | 170 } |
171 | |
10411 | 172 int |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
173 c_file_ptr_buf::seek (off_t offset, int origin) |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
174 { |
21913
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
175 return f ? octave_fseeko_wrapper (f, offset, origin) : -1; |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
176 } |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
177 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
178 off_t |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
179 c_file_ptr_buf::tell (void) |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
180 { |
21913
c0604bba8da1
provide wrappers for fseeko and ftello
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
181 return f ? octave_ftello_wrapper (f) : -1; |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
182 } |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
183 |
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
184 int |
10411 | 185 c_file_ptr_buf::file_close (FILE *f) |
186 { | |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21913
diff
changeset
|
187 return std::fclose (f); |
10411 | 188 } |
189 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21550
diff
changeset
|
190 #if defined (HAVE_ZLIB) |
5325 | 191 |
192 c_zfile_ptr_buf::~c_zfile_ptr_buf (void) | |
193 { | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
194 buf_close (); |
5325 | 195 } |
196 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 // FIXME: I'm sure there is room for improvement here... |
5325 | 198 |
199 c_zfile_ptr_buf::int_type | |
200 c_zfile_ptr_buf::overflow (int_type c) | |
201 { | |
202 if (f) | |
203 return (c != traits_type::eof ()) ? gzputc (f, c) : flush (); | |
204 else | |
205 return traits_type::not_eof (c); | |
206 } | |
207 | |
208 c_zfile_ptr_buf::int_type | |
209 c_zfile_ptr_buf::underflow_common (bool bump) | |
210 { | |
211 if (f) | |
212 { | |
213 int_type c = gzgetc (f); | |
214 | |
21183
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
215 if (! bump && c != traits_type::eof ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
216 gzungetc (c, f); |
5325 | 217 |
218 return c; | |
219 } | |
220 else | |
221 return traits_type::eof (); | |
222 } | |
223 | |
224 c_zfile_ptr_buf::int_type | |
225 c_zfile_ptr_buf::pbackfail (int_type c) | |
226 { | |
21183
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
227 return ((c != traits_type::eof () && f) |
e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
228 ? gzungetc (c, f) : traits_type::not_eof (c)); |
5325 | 229 } |
230 | |
231 std::streamsize | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
232 c_zfile_ptr_buf::xsputn (const char *s, std::streamsize n) |
5325 | 233 { |
234 if (f) | |
235 return gzwrite (f, s, n); | |
236 else | |
237 return 0; | |
238 } | |
239 | |
240 std::streamsize | |
241 c_zfile_ptr_buf::xsgetn (char *s, std::streamsize n) | |
242 { | |
243 if (f) | |
244 return gzread (f, s, n); | |
245 else | |
246 return 0; | |
247 } | |
248 | |
249 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
250 c_zfile_ptr_buf::seekoff (std::streamoff /* offset */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
251 std::ios::seekdir /* dir */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
252 std::ios::openmode) |
5325 | 253 { |
5775 | 254 // FIXME |
5325 | 255 #if 0 |
256 if (f) | |
257 { | |
258 gzseek (f, offset, seekdir_to_whence (dir)); | |
259 | |
260 return gztell (f); | |
261 } | |
262 else | |
263 return 0; | |
264 #endif | |
265 return -1; | |
266 } | |
267 | |
268 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
269 c_zfile_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) |
5325 | 270 { |
5775 | 271 // FIXME |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
272 #if 0 |
5325 | 273 if (f) |
274 { | |
275 gzseek (f, offset, SEEK_SET); | |
276 | |
277 return gztell (f); | |
278 } | |
279 else | |
280 return 0; | |
281 #endif | |
282 return -1; | |
283 } | |
284 | |
285 int | |
286 c_zfile_ptr_buf::sync (void) | |
287 { | |
288 flush (); | |
289 | |
290 return 0; | |
291 } | |
292 | |
293 int | |
294 c_zfile_ptr_buf::flush (void) | |
295 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
296 // FIXME: do we need something more complex here, passing |
5325 | 297 // something other than 0 for the second argument to gzflush and |
298 // checking the return value, etc.? | |
299 | |
21184
3db899f1d54c
use istream::traits_type::eof () instead of EOF
John W. Eaton <jwe@octave.org>
parents:
21183
diff
changeset
|
300 return f ? gzflush (f, 0) : traits_type::eof (); |
5325 | 301 } |
302 | |
303 int | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
304 c_zfile_ptr_buf::buf_close (void) |
5325 | 305 { |
306 int retval = -1; | |
307 | |
308 flush (); | |
309 | |
310 if (f) | |
311 { | |
312 retval = cf (f); | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
313 f = nullptr; |
5325 | 314 } |
315 | |
316 return retval; | |
317 } | |
318 | |
319 #endif |