30 #include <sys/types.h>
38 namespace gzstream_detail
80 if ( mode_r == std::ios_base::in )
82 _fd =
::open( name_r, O_RDONLY | O_CLOEXEC );
85 else if ( mode_r == std::ios_base::out )
87 _fd =
::open( name_r, O_WRONLY|O_CREAT|O_CLOEXEC, 0666 );
104 setg( NULL, NULL, NULL );
129 int r = gzclose(
_file );
141 _mode = std::ios_base::openmode(0);
143 setg( NULL, NULL, NULL );
159 if ( pbase() < pptr() ) {
161 if ( traits_type::eq_int_type( res, traits_type::eof() ) )
172 fgzstreambuf::int_type
175 int_type ret = traits_type::eof();
178 if ( ! traits_type::eq_int_type( c, traits_type::eof() ) )
180 *pptr() = traits_type::to_char_type( c );
183 if ( pbase() <= pptr() )
185 if (
zWriteFrom( pbase(), pptr() - pbase() ) )
188 ret = traits_type::not_eof( c );
201 fgzstreambuf::int_type
204 int_type ret = traits_type::eof();
207 if ( gptr() < egptr() )
208 return traits_type::to_int_type( *gptr() );
214 ret = traits_type::to_int_type( *gptr() );
234 int read = gzread(
_file, buffer_r, maxcount_r );
251 if ( (written = gzwrite(
_file, buffer_r, count_r )) == 0 )
254 return( written == count_r );
262 fgzstreambuf::pos_type
265 z_off_t ret = gzseek(
_file, off_r, way_r );
276 fgzstreambuf::pos_type
279 z_off_t ret = gztell(
_file );
290 fgzstreambuf::pos_type
293 pos_type ret = pos_type(off_type(-1));
303 off_type zegptr =
zTell();
304 if ( zegptr != off_type(-1) )
306 if ( way_r == std::ios_base::end )
317 off_type zeback = zegptr - ( egptr() - eback() );
318 off_type zgptr = zegptr - ( egptr() - gptr() );
319 off_type zngptr = off_r;
320 if ( way_r == std::ios_base::cur )
323 way_r = std::ios_base::beg;
326 if ( way_r == std::ios_base::beg )
328 if ( zeback <= zngptr && zngptr <= zegptr )
333 eback() + (zngptr-zeback),
335 ret = pos_type(zngptr);
351 fgzstreambuf::pos_type
354 off_t pos = lseek (
_fd, 0, SEEK_CUR);