3628
|
1 /* |
|
2 |
|
3 Copyright (C) 2000 John W. Eaton |
|
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 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3629
|
31 #include "c-file-ptr-stream.h" |
3628
|
32 |
|
33 #ifndef SEEK_SET |
|
34 #define SEEK_SET 0 |
|
35 #endif |
|
36 |
|
37 #ifndef SEEK_CUR |
|
38 #define SEEK_CUR 1 |
|
39 #endif |
|
40 |
|
41 #ifndef SEEK_END |
|
42 #define SEEK_END 2 |
|
43 #endif |
|
44 |
|
45 c_file_ptr_buf::~c_file_ptr_buf (void) { fflush (f); } |
|
46 |
|
47 // XXX FIXME XXX -- I'm sure there is room for improvement here... |
|
48 |
|
49 int |
|
50 c_file_ptr_buf::overflow (int c) |
|
51 { |
|
52 return (c != EOF) ? fputc (c, f) : fflush (f); |
|
53 } |
|
54 |
|
55 int |
|
56 c_file_ptr_buf::underflow (void) |
|
57 { |
|
58 return fgetc (f); |
|
59 } |
|
60 |
|
61 int |
|
62 c_file_ptr_buf::uflow (void) |
|
63 { |
|
64 return underflow (); |
|
65 } |
|
66 |
|
67 int |
|
68 c_file_ptr_buf::pbackfail (int c) |
|
69 { |
|
70 return (c != EOF) ? ungetc (c, f) : EOF; |
|
71 } |
|
72 |
|
73 std::streamsize |
|
74 c_file_ptr_buf::xsputn (const char* s, std::streamsize n) |
|
75 { |
|
76 return fwrite (s, 1, n, f); |
|
77 } |
|
78 |
|
79 std::streamsize |
|
80 c_file_ptr_buf::xsgetn (char *s, std::streamsize n) |
|
81 { |
|
82 return fread (s, 1, n, f); |
|
83 } |
|
84 |
|
85 static inline int |
|
86 seekdir_to_whence (std::ios::seekdir dir) |
|
87 { |
|
88 return ((dir == std::ios::beg) ? SEEK_SET : |
|
89 (dir == std::ios::cur) ? SEEK_CUR : |
|
90 (dir == std::ios::end) ? SEEK_END : |
|
91 dir); |
|
92 } |
|
93 |
|
94 std::streampos |
|
95 c_file_ptr_buf::seekoff (std::streamoff offset, std::ios::seekdir dir, |
|
96 std::ios::openmode) |
|
97 { |
|
98 // XXX FIXME XXX -- is this the right thing to do? |
|
99 |
|
100 fseek (f, offset, seekdir_to_whence (dir)); |
|
101 |
|
102 return ftell (f); |
|
103 } |
|
104 |
|
105 std::streampos |
|
106 c_file_ptr_buf::seekpos (std::streampos offset, std::ios::openmode) |
|
107 { |
|
108 // XXX FIXME XXX -- is this the right thing to do? |
|
109 |
|
110 fseek (f, offset, SEEK_SET); |
|
111 |
|
112 return ftell (f); |
|
113 } |
|
114 |
|
115 int |
|
116 c_file_ptr_buf::sync (void) |
|
117 { |
|
118 return 0; |
|
119 } |
|
120 |
|
121 /* |
|
122 ;;; Local Variables: *** |
|
123 ;;; mode: C++ *** |
|
124 ;;; End: *** |
|
125 */ |
|
126 |