1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 #include "zypp/base/ZckStream.h"
10 #include "zypp/base/String.h"
12 #include <sys/types.h>
26 zckstreambufimpl::~zckstreambufimpl()
31 bool zckstreambufimpl::openImpl( const char *name_r, std::ios_base::openmode mode_r )
36 if ( mode_r == std::ios_base::in ) {
37 _fd = ::open( name_r, O_RDONLY | O_CLOEXEC );
40 } else if ( mode_r == std::ios_base::out ) {
41 _fd = ::open( name_r, O_WRONLY|O_CREAT|O_CLOEXEC, 0666 );
45 _lastErr = str::Format("ZChunk backend does not support the given open mode.");
50 const int errSrv = errno;
51 _lastErr = str::Format("Opening file failed: %1%") % ::strerror( errSrv );
55 _zContext = ::zck_create();
62 if ( !::zck_init_read( _zContext, _fd ) ) {
67 if ( !::zck_init_write( _zContext, _fd ) ) {
77 bool zckstreambufimpl::closeImpl()
84 if ( !zck_close( _zContext ) ) {
89 zck_free( &_zContext );
96 void zckstreambufimpl::setError()
98 if ( !zck_is_error( _zContext ) )
100 _lastErr = zck_get_error( _zContext );
101 zck_clear_error( _zContext );
104 std::streamsize zckstreambufimpl::readData(char *buffer_r, std::streamsize maxcount_r)
106 if ( !isOpen() || !canRead() )
109 ssize_t read = zck_read( _zContext, buffer_r, maxcount_r );
118 bool zckstreambufimpl::writeData(const char *buffer_r, std::streamsize count_r)
120 if ( !isOpen() || !canWrite() )
123 ssize_t wrote = zck_write( _zContext, buffer_r, count_r );
132 bool zckstreambufimpl::isOpen() const
137 bool zckstreambufimpl::canRead() const
142 bool zckstreambufimpl::canWrite() const
147 bool zckstreambufimpl::canSeek( std::ios_base::seekdir ) const
152 off_t zckstreambufimpl::seekTo(off_t, std::ios_base::seekdir , std::ios_base::openmode)
157 off_t zckstreambufimpl::tell() const