libzypp 17.37.17
filestreambuf.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include "filestreambuf.h"
12
13namespace zypp::detail {
14
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
56 {
57 _fd = -1;
58 _mode = std::ios_base::openmode(0);
59 return true;
60 }
61
62}
std::streamsize readData(char *buffer_r, std::streamsize maxcount_r)
std::ios_base::openmode _mode
bool writeData(const char *buffer_r, std::streamsize count_r)
bool openImpl(int fd, std::ios_base::openmode mode_r)
unsigned short b
auto eintrSafeCall(Fun &&function, Args &&... args)