Mercurial > octave
annotate src/oct-fstrm.cc @ 10447:12d25a1d84bf
Use gnulib headers instead of C++ std headers where needed.
author | David Grundberg <davidg@cs.umu.se> |
---|---|
date | Wed, 24 Mar 2010 17:27:58 +0100 |
parents | 479cc8a0a846 |
children | bbe99b2a5ba7 |
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> | |
10447
12d25a1d84bf
Use gnulib headers instead of C++ std headers where needed.
David Grundberg <davidg@cs.umu.se>
parents:
10411
diff
changeset
|
29 #include "string.h" |
12d25a1d84bf
Use gnulib headers instead of C++ std headers where needed.
David Grundberg <davidg@cs.umu.se>
parents:
10411
diff
changeset
|
30 #include "stdlib.h" |
2081 | 31 |
32 #include "error.h" | |
33 #include "oct-fstrm.h" | |
34 | |
3340 | 35 octave_stream |
3570 | 36 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
|
37 oct_mach_info::float_format ff) |
3340 | 38 { |
4587 | 39 return octave_stream (new octave_fstream (nm_arg, arg_md, ff)); |
3340 | 40 } |
41 | |
3552 | 42 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
|
43 std::ios::openmode arg_md, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
44 oct_mach_info::float_format ff) |
4587 | 45 : octave_base_stream (arg_md, ff), nm (nm_arg) |
2081 | 46 { |
3775 | 47 |
48 #if CXX_ISO_COMPLIANT_LIBRARY | |
49 | |
50 fs.open (nm.c_str (), arg_md); | |
51 | |
52 #else | |
2081 | 53 // Override default protection of 0664 so that umask will appear to |
54 // do the right thing. | |
55 | |
3570 | 56 fs.open (nm.c_str (), arg_md, 0666); |
2081 | 57 |
3775 | 58 #endif |
59 | |
2081 | 60 if (! fs) |
10411 | 61 error (gnulib::strerror (errno)); |
2081 | 62 } |
63 | |
64 // Position a stream at OFFSET relative to ORIGIN. | |
65 | |
66 int | |
4797 | 67 octave_fstream::seek (long, int) |
2081 | 68 { |
4797 | 69 error ("fseek: invalid_operation"); |
70 return -1; | |
2081 | 71 } |
72 | |
73 // Return current stream position. | |
74 | |
4797 | 75 long |
76 octave_fstream::tell (void) | |
2081 | 77 { |
4797 | 78 error ("ftell: invalid_operation"); |
79 return -1; | |
2081 | 80 } |
81 | |
82 // Return non-zero if EOF has been reached on this stream. | |
83 | |
84 bool | |
85 octave_fstream::eof (void) const | |
86 { | |
87 return fs.eof (); | |
88 } | |
89 | |
3652 | 90 void |
91 octave_fstream::do_close (void) | |
92 { | |
93 fs.close (); | |
94 } | |
95 | |
3523 | 96 std::istream * |
2081 | 97 octave_fstream::input_stream (void) |
98 { | |
3523 | 99 std::istream *retval = 0; |
2081 | 100 |
3544 | 101 if (mode () & std::ios::in) |
2081 | 102 retval = &fs; |
103 | |
104 return retval; | |
105 } | |
106 | |
3523 | 107 std::ostream * |
2081 | 108 octave_fstream::output_stream (void) |
109 { | |
3523 | 110 std::ostream *retval = 0; |
2081 | 111 |
3544 | 112 if (mode () & std::ios::out) |
2081 | 113 retval = &fs; |
114 | |
115 return retval; | |
116 } |