libzypp  17.36.3
filestreambuf.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include "filestreambuf.h"
12 
13 namespace 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 }
unsigned short b
bool openImpl(int fd, std::ios_base::openmode mode_r)
std::streamsize readData(char *buffer_r, std::streamsize maxcount_r)
void resetDispose()
Set no dispose function.
Definition: AutoDispose.h:171
auto eintrSafeCall(Fun &&function, Args &&... args)
bool writeData(const char *buffer_r, std::streamsize count_r)
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
Definition: sysconfig.cc:34
bool write(const Pathname &path_r, const std::string &key_r, const std::string &val_r, const std::string &newcomment_r)
Add or change a value in sysconfig file path_r.
Definition: sysconfig.cc:80
std::ios_base::openmode _mode
Definition: filestreambuf.h:65