summaryrefslogtreecommitdiff
path: root/contrib/iostream/zfstream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/iostream/zfstream.cpp')
-rw-r--r--contrib/iostream/zfstream.cpp36
1 files changed, 18 insertions, 18 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{