summaryrefslogtreecommitdiff
path: root/contrib/iostream
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/iostream')
-rw-r--r--contrib/iostream/zfstream.cpp36
-rw-r--r--contrib/iostream/zfstream.h34
2 files changed, 28 insertions, 42 deletions
diff --git a/contrib/iostream/zfstream.cpp b/contrib/iostream/zfstream.cpp
index a690bbe..d0cd85f 100644
--- a/contrib/iostream/zfstream.cpp
+++ b/contrib/iostream/zfstream.cpp
@@ -1,5 +1,4 @@
1 1
2#include <memory.h>
3#include "zfstream.h" 2#include "zfstream.h"
4 3
5gzfilebuf::gzfilebuf() : 4gzfilebuf::gzfilebuf() :
@@ -17,15 +16,13 @@ gzfilebuf::~gzfilebuf() {
17} 16}
18 17
19gzfilebuf *gzfilebuf::open( const char *name, 18gzfilebuf *gzfilebuf::open( const char *name,
20 int io_mode ) { 19 int io_mode ) {
21 20
22 if ( is_open() ) 21 if ( is_open() )
23 return NULL; 22 return NULL;
24 23
25 char char_mode[10]; 24 char char_mode[10];
26 char *p; 25 char *p = char_mode;
27 memset(char_mode,'\0',10);
28 p = char_mode;
29 26
30 if ( io_mode & ios::in ) { 27 if ( io_mode & ios::in ) {
31 mode = ios::in; 28 mode = ios::in;
@@ -48,6 +45,9 @@ gzfilebuf *gzfilebuf::open( const char *name,
48 *p++ = '9'; 45 *p++ = '9';
49 } 46 }
50 47
48 // Put the end-of-string indicator
49 *p = '\0';
50
51 if ( (file = gzopen(name, char_mode)) == NULL ) 51 if ( (file = gzopen(name, char_mode)) == NULL )
52 return NULL; 52 return NULL;
53 53
@@ -58,15 +58,13 @@ gzfilebuf *gzfilebuf::open( const char *name,
58} 58}
59 59
60gzfilebuf *gzfilebuf::attach( int file_descriptor, 60gzfilebuf *gzfilebuf::attach( int file_descriptor,
61 int io_mode ) { 61 int io_mode ) {
62 62
63 if ( is_open() ) 63 if ( is_open() )
64 return NULL; 64 return NULL;
65 65
66 char char_mode[10]; 66 char char_mode[10];
67 char *p; 67 char *p = char_mode;
68 memset(char_mode,'\0',10);
69 p = char_mode;
70 68
71 if ( io_mode & ios::in ) { 69 if ( io_mode & ios::in ) {
72 mode = ios::in; 70 mode = ios::in;
@@ -89,6 +87,9 @@ gzfilebuf *gzfilebuf::attach( int file_descriptor,
89 *p++ = '9'; 87 *p++ = '9';
90 } 88 }
91 89
90 // Put the end-of-string indicator
91 *p = '\0';
92
92 if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) 93 if ( (file = gzdopen(file_descriptor, char_mode)) == NULL )
93 return NULL; 94 return NULL;
94 95
@@ -112,13 +113,13 @@ gzfilebuf *gzfilebuf::close() {
112 113
113} 114}
114 115
115int gzfilebuf::setcompressionlevel( short comp_level ) { 116int gzfilebuf::setcompressionlevel( int comp_level ) {
116 117
117 return gzsetparams(file, comp_level, -2); 118 return gzsetparams(file, comp_level, -2);
118 119
119} 120}
120 121
121int gzfilebuf::setcompressionstrategy( short comp_strategy ) { 122int gzfilebuf::setcompressionstrategy( int comp_strategy ) {
122 123
123 return gzsetparams(file, -2, comp_strategy); 124 return gzsetparams(file, -2, comp_strategy);
124 125
@@ -151,7 +152,7 @@ int gzfilebuf::underflow() {
151 152
152 if ( out_waiting() ) { 153 if ( out_waiting() ) {
153 if ( flushbuf() == EOF ) 154 if ( flushbuf() == EOF )
154 return EOF; 155 return EOF;
155 } 156 }
156 157
157 } 158 }
@@ -180,11 +181,11 @@ int gzfilebuf::overflow( int c ) {
180 setg(0,0,0); 181 setg(0,0,0);
181 } else { 182 } else {
182 if (in_avail()) { 183 if (in_avail()) {
183 return EOF; 184 return EOF;
184 } 185 }
185 if (out_waiting()) { 186 if (out_waiting()) {
186 if (flushbuf() == EOF) 187 if (flushbuf() == EOF)
187 return EOF; 188 return EOF;
188 } 189 }
189 } 190 }
190 191
@@ -282,12 +283,11 @@ void gzfilestream_common::close() {
282 283
283} 284}
284 285
285gzfilebuf *gzfilestream_common::rdbuf() { 286gzfilebuf *gzfilestream_common::rdbuf()
286 287{
287 return &buffer; 288 return &buffer;
288
289} 289}
290 290
291gzifstream::gzifstream() : 291gzifstream::gzifstream() :
292 ios( gzfilestream_common::rdbuf() ) 292 ios( gzfilestream_common::rdbuf() )
293{ 293{
diff --git a/contrib/iostream/zfstream.h b/contrib/iostream/zfstream.h
index c87fa08..ed79098 100644
--- a/contrib/iostream/zfstream.h
+++ b/contrib/iostream/zfstream.h
@@ -1,6 +1,6 @@
1 1
2#ifndef _zfstream_h 2#ifndef zfstream_h
3#define _zfstream_h 3#define zfstream_h
4 4
5#include <fstream.h> 5#include <fstream.h>
6#include "zlib.h" 6#include "zlib.h"
@@ -16,8 +16,8 @@ public:
16 gzfilebuf *attach( int file_descriptor, int io_mode ); 16 gzfilebuf *attach( int file_descriptor, int io_mode );
17 gzfilebuf *close(); 17 gzfilebuf *close();
18 18
19 int setcompressionlevel( short comp_level ); 19 int setcompressionlevel( int comp_level );
20 int setcompressionstrategy( short comp_strategy ); 20 int setcompressionstrategy( int comp_strategy );
21 21
22 inline int is_open() const { return (file !=NULL); } 22 inline int is_open() const { return (file !=NULL); }
23 23
@@ -98,18 +98,19 @@ private:
98 T val; 98 T val;
99}; 99};
100 100
101template<class T> gzofstream &operator<<(gzofstream &s, 101template<class T> gzofstream &operator<<(gzofstream &s, const gzomanip<T> &m)
102 const gzomanip<T> &m) { 102{
103 return (*m.func)(s, m.val); 103 return (*m.func)(s, m.val);
104
105} 104}
106 105
107inline gzofstream &setcompressionlevel( gzofstream &s, int l ) { 106inline gzofstream &setcompressionlevel( gzofstream &s, int l )
107{
108 (s.rdbuf())->setcompressionlevel(l); 108 (s.rdbuf())->setcompressionlevel(l);
109 return s; 109 return s;
110} 110}
111 111
112inline gzofstream &setcompressionstrategy( gzofstream &s, int l ) { 112inline gzofstream &setcompressionstrategy( gzofstream &s, int l )
113{
113 (s.rdbuf())->setcompressionstrategy(l); 114 (s.rdbuf())->setcompressionstrategy(l);
114 return s; 115 return s;
115} 116}
@@ -125,18 +126,3 @@ inline gzomanip<int> setcompressionstrategy(int l)
125} 126}
126 127
127#endif 128#endif
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142