1 #include "daq/slc/system/File.h"
3 #include <daq/slc/base/IOException.h>
14 void File::open(
const std::string& path,
const std::string& mode_s)
17 if (mode_s.find(
"w") != std::string::npos) {
19 if (mode_s.find(
"r") != std::string::npos) {
25 if ((m_fd = ::open(path.c_str(), mode, 0666)) < 0) {
27 throw (
IOException(
"Failed to open file : %s", path.c_str()));
31 void File::unlink(
const std::string& path)
33 if ((::unlink(path.c_str())) < 0) {
39 size_t File::write(
const void* buf,
size_t count)
45 ret = ::write(m_fd, ((
unsigned char*)buf + c), (count - c));
63 size_t File::read(
void* buf,
size_t count)
69 ret = ::read(m_fd, ((
unsigned char*)buf + c), (count - c));
73 case EAGAIN:
continue;
75 throw (
IOException(
"Error while reading. %d", errno));
83 bool File::exist(
const std::string& filename)
86 if (stat(
filename.c_str(), &st) != 0) {
89 mode_t m = st.st_mode;