libzypp 17.37.10

filestreambuf.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include "filestreambuf.h"
11#include <zypp-core/zyppng/base/private/linuxhelpers_p.h>
12
13 namespace zypp::detail {
14
15 void FdStreamBufImpl::disableAutoClose()
16 {
17 _fd.resetDispose();
18 }
19
20 std::streamsize FdStreamBufImpl::readData( char *buffer_r, std::streamsize maxcount_r )
21 {
22 if ( !isOpen() || !canRead() )
23 return 0;
24
25 const auto r = zyppng::eintrSafeCall( ::read, _fd, buffer_r, maxcount_r );
26 if ( r <= 0 )
27 return false;
28
29 return true;
30 }
31
32 bool FdStreamBufImpl::writeData( const char *buffer_r, std::streamsize count_r )
33 {
34 if ( !isOpen() || !canWrite() )
35 return false;
36
37 std::streamsize written = 0;
38 while ( written < count_r ) {
39 const auto b = zyppng::eintrSafeCall( ::write, _fd, buffer_r + written, count_r - written );
40 if ( b == -1 ) {
41 return false;
42 }
43 written += b;
44 }
45 return true;
46 }
47
48 bool FdStreamBufImpl::openImpl(int fd, std::ios_base::openmode mode_r)
49 {
50 _fd = fd;
51 _mode = mode_r;
52 return true;
53 }
54
55 bool FdStreamBufImpl::closeImpl()
56 {
57 _fd = -1;
58 _mode = std::ios_base::openmode(0);
59 return true;
60 }
61
62}
zypp::detail::FdStreamBufImpl::disableAutoClose
void disableAutoClose()
Definition filestreambuf.cc:15
zypp::detail::FdStreamBufImpl::readData
std::streamsize readData(char *buffer_r, std::streamsize maxcount_r)
Definition filestreambuf.cc:20
zypp::detail::FdStreamBufImpl::_fd
zypp::AutoFD _fd
Definition filestreambuf.h:64
zypp::detail::FdStreamBufImpl::canRead
bool canRead() const
Definition filestreambuf.h:34
zypp::detail::FdStreamBufImpl::_mode
std::ios_base::openmode _mode
Definition filestreambuf.h:65
zypp::detail::FdStreamBufImpl::closeImpl
bool closeImpl()
Definition filestreambuf.cc:55
zypp::detail::FdStreamBufImpl::writeData
bool writeData(const char *buffer_r, std::streamsize count_r)
Definition filestreambuf.cc:32
zypp::detail::FdStreamBufImpl::isOpen
bool isOpen() const
Definition filestreambuf.h:30
zypp::detail::FdStreamBufImpl::canWrite
bool canWrite() const
Definition filestreambuf.h:38
zypp::detail::FdStreamBufImpl::openImpl
bool openImpl(int fd, std::ios_base::openmode mode_r)
Definition filestreambuf.cc:48
filestreambuf.h
linuxhelpers_p.h
b
unsigned short b
Definition mediablocklist.cc:1
zypp::detail
Definition PoolQuery.cc:1509
zyppng::eintrSafeCall
auto eintrSafeCall(Fun &&function, Args &&... args)
Definition linuxhelpers_p.h:50