8#include "daq/slc/system/File.h"
10#include <daq/slc/base/IOException.h>
21void File::open(
const std::string& path,
const std::string& mode_s)
24 if (mode_s.find(
"w") != std::string::npos) {
26 if (mode_s.find(
"r") != std::string::npos) {
32 if ((m_fd = ::open(path.c_str(), mode, 0666)) < 0) {
34 throw (
IOException(
"Failed to open file : %s", path.c_str()));
38void File::unlink(
const std::string& path)
40 if ((::unlink(path.c_str())) < 0) {
46size_t File::write(
const void* buf,
size_t count)
51 int ret = ::write(m_fd, ((
unsigned char*)buf + c), (count - c));
69size_t File::read(
void* buf,
size_t count)
74 int ret = ::read(m_fd, ((
unsigned char*)buf + c), (count - c));
78 case EAGAIN:
continue;
80 throw (
IOException(
"Error while reading. %d", errno));
88bool File::exist(
const std::string& filename)
91 if (stat(filename.c_str(), &st) != 0) {
94 mode_t m = st.st_mode;
Abstract base class for different kinds of events.