w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RfileFd.cpp
Go to the documentation of this file.
1// $Id: RfileFd.cpp 1180 2019-07-08 15:46:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2019- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-07-08 1180 1.1 add Open(fnam,flags,mode,emsg)
8// 2019-06-15 1163 1.0 Initial version
9// ---------------------------------------------------------------------------
10
14#include <errno.h>
15
16#include "RfileFd.hpp"
17
18using namespace std;
19
25// all method definitions in namespace Retro
26namespace Retro {
27
28//------------------------------------------+-----------------------------------
30
32 : RfileFd("RfileFd::")
33{}
34
35//------------------------------------------+-----------------------------------
37
38RfileFd::RfileFd(const char* cnam)
39 : Rfd(cnam)
40{}
41
42//------------------------------------------+-----------------------------------
44
45bool RfileFd::Open(const char* fname, int flags, RerrMsg& emsg)
46{
47 Close();
48 if (!SetFd(::open(fname, flags))) {
49 emsg.InitErrno(fCnam+"Open()",
50 string("open() for '") + fname + "' failed: ", errno);
51 }
52 return IsOpen();
53}
54
55//------------------------------------------+-----------------------------------
57
58bool RfileFd::Open(const char* fname, int flags, mode_t mode, RerrMsg& emsg)
59{
60 Close();
61 if (!SetFd(::open(fname, flags, mode))) {
62 emsg.InitErrno(fCnam+"Open()",
63 string("open() for '") + fname + "' failed: ", errno);
64 }
65 return IsOpen();
66}
67
68//------------------------------------------+-----------------------------------
70
71bool RfileFd::Stat(struct stat *sbuf, RerrMsg& emsg)
72{
73 if (::fstat(fFd, sbuf) < 0) {
74 emsg.InitErrno(fCnam+"Stat()", "stat() failed: ", errno);
75 return false;
76 }
77 return true;
78}
79
80//------------------------------------------+-----------------------------------
82
83off_t RfileFd::Seek(off_t offset, int whence, RerrMsg& emsg)
84{
85 if (::lseek(fFd, offset, whence) < 0) {
86 emsg.InitErrno(fCnam+"Seek()", "seek() failed: ", errno);
87 return false;
88 }
89 return true;
90}
91
92//------------------------------------------+-----------------------------------
94
95bool RfileFd::Truncate(off_t length, RerrMsg& emsg)
96{
97 if (::ftruncate(fFd, length) < 0) {
98 emsg.InitErrno(fCnam+"Truncate()", "ftruncate() failed: ", errno);
99 return false;
100 }
101 return true;
102}
103
104//------------------------------------------+-----------------------------------
106
107ssize_t RfileFd::Read(void *buf, size_t count, RerrMsg& emsg)
108{
109 ssize_t irc = ::read(fFd, buf, count);
110 if (irc < 0) {
111 emsg.InitErrno(fCnam+"Read()", "read() failed: ", errno);
112 }
113 return irc;
114}
115
116//------------------------------------------+-----------------------------------
118
119bool RfileFd::WriteAll(const void *buf, size_t count, RerrMsg& emsg)
120{
121 ssize_t irc = ::write(fFd, buf, count);
122 if (irc < ssize_t(count)) {
123 emsg.InitErrno("WriteAll()", "write() failed: ", errno);
124 return false;
125 }
126 return true;
127}
128
129} // end namespace Retro
FIXME_docs.
Definition: RerrMsg.hpp:25
void InitErrno(const std::string &meth, const std::string &text, int errnum)
FIXME_docs.
Definition: RerrMsg.cpp:84
FIXME_docs.
Definition: Rfd.hpp:25
int fFd
Definition: Rfd.hpp:48
bool IsOpen() const
FIXME_docs.
Definition: Rfd.ipp:28
std::string fCnam
Definition: Rfd.hpp:49
void Close()
FIXME_docs.
Definition: Rfd.cpp:82
bool SetFd(int fd)
FIXME_docs.
Definition: Rfd.cpp:71
FIXME_docs.
Definition: RfileFd.hpp:30
RfileFd()
FIXME_docs.
Definition: RfileFd.cpp:31
bool WriteAll(const void *buf, size_t count, RerrMsg &emsg)
FIXME_docs.
Definition: RfileFd.cpp:119
ssize_t Read(void *buf, size_t count, RerrMsg &emsg)
FIXME_docs.
Definition: RfileFd.cpp:107
bool Stat(struct stat *sbuf, RerrMsg &emsg)
FIXME_docs.
Definition: RfileFd.cpp:71
off_t Seek(off_t offset, int whence, RerrMsg &emsg)
FIXME_docs.
Definition: RfileFd.cpp:83
bool Open(const char *fname, int flags, RerrMsg &emsg)
FIXME_docs.
Definition: RfileFd.cpp:45
bool Truncate(off_t length, RerrMsg &emsg)
FIXME_docs.
Definition: RfileFd.cpp:95
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47