Commit b7d7b8d4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 786cab49
......@@ -19,6 +19,7 @@
#include "wcfs_misc.h"
// os::
namespace os {
tuple<File, error> open(const string &path) {
......@@ -51,5 +52,25 @@ error File::_err(const char *op) {
return errorf("%s %s: %s", op, f->path, strerror_r(errno));
}
} // os::
// fmt::
namespace fmt {
string sprintf(const string &format, ...) {
// https://stackoverflow.com/a/26221725/9456786
va_list ap;
va_start(ap, format);
size_t size = vsnprintf(NULL, 0, format.c_str(), ap);
va_end(ap);
std::unique_ptr<char[]> buf( new char[size] );
va_start(ap, format);
vsnprintf(buf.get(), size, format.c_str(), ap);
va_end(ap);
return string(buf.get(), buf.get() + size - 1 ); // without trailing '\0'
}
} // fmt::
......@@ -27,6 +27,7 @@ using std::string;
#include <tuple>
using std::tuple;
using std::tie;
// nil is synonim for nullptr and NULL.
const nullptr_t nil = nullptr;
......@@ -45,6 +46,7 @@ struct error {
}
};
// os::
namespace os {
// os::File mimics os.File from Go.
......@@ -63,4 +65,12 @@ tuple<File, error> open(const string &path);
} // os::
// fmt::
namespace fmt {
string sprintf(const string &format, ...);
} // fmt::
#endif
......@@ -240,6 +240,7 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
ASSERT(mmap->blk_start <= blk && blk < mmap->blk_stop());
_File *f = mmap->file;
error err;
uint8_t *blkmem = mmap->mem_start + (blk - mmap->blk_start)*f->blksize;
os::File fsfile;
......@@ -248,13 +249,15 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
}
else {
// TODO share @rev fd until wconn is resynced?
fsfile = f->wconn->_wc->_open("@%s/bigfile/%s" % (h(at), h(f->foid)), "rb");
// XXX err
tie(fsfile, err) = f->wconn->_wc->_open(
fmt::sprintf("@%s/bigfile/%s", h(at), h(f->foid), "rb");
if (err != nil)
return err;
defer(fsfile.close);
}
struct stat st;
auto err = fsfile.stat(&st);
err = fsfile.stat(&st);
if (err != nil)
return err;
ASSERT(st.st_blksize == f->blksize); // FIXME assert
......
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