Commit 969dbe4b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 90301a73
......@@ -31,12 +31,19 @@ using namespace golang;
#include <memory>
static error _pathError(const char *op, const string &path, int syserr);
// io::
namespace io {
const error EOF_ = fmt::errorf("EOF");
} // io::
// os::
namespace os {
static error _pathError(const char *op, const string &path, int syserr);
tuple<File, error> open(const string &path, int flags, mode_t mode) {
File f;
f._path = path;
......@@ -63,7 +70,7 @@ tuple<int, error> File::read(void *buf, size_t count) {
n = ::read(f->_fd, buf, count);
if (n == 0)
return make_tuple(n, io::EOF);
return make_tuple(n, io::EOF_);
if (n < 0)
return make_tuple(0, f->_errno("read"));
......@@ -81,7 +88,7 @@ tuple <int, error> File::write(const void *buf, size_t count) {
return make_tuple(wrote, f->_errno("write"));
wrote += n;
buf += n;
buf = ((const char *)buf) + n;
count -= n;
}
......@@ -104,8 +111,6 @@ error File::_errno(const char *op) {
return _pathError(op, f->_path, errno);
}
} // os::
// _pathError returns os.PathError-like for op/path and system error
// indicated by syserr.
static error _pathError(const char *op, const string &path, int syserr) {
......@@ -114,6 +119,9 @@ static error _pathError(const char *op, const string &path, int syserr) {
return fmt::errorf("%s %s: %s", op, path.c_str(), estr);
}
} // os::
// mm::
namespace mm {
......@@ -125,7 +133,7 @@ error map_into(void *addr, size_t size, int prot, int flags, const os::File &f,
addr2 = mmap(addr, size, prot, MAP_FIXED | flags, f.fd(), offset);
if (addr2 == MAP_FAILED)
return _pathError("mmap", f.name(), errno);
return os::_pathError("mmap", f.name(), errno);
if (addr2 != addr)
panic("mmap(addr, MAP_FIXED): returned !addr");
return nil;
......
......@@ -47,6 +47,15 @@ struct error {
}
};
// io::
namespace io {
extern const error EOF_;
} // io::
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment