Commit b09b8abf authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7a731b3c
......@@ -138,19 +138,27 @@ error map_into(void *addr, size_t size, int prot, int flags, const os::File &f,
namespace fmt {
static
string _vsprintf(const string &format, va_list argp) {
string _vsprintf(const char *format, va_list argp) {
// based on https://stackoverflow.com/a/26221725/9456786
va_list argp2;
va_copy(argp2, argp);
size_t size = vsnprintf(NULL, 0, format.c_str(), argp2);
size_t size = vsnprintf(NULL, 0, format, argp2);
va_end(argp2);
std::unique_ptr<char[]> buf( new char[size] );
vsnprintf(buf.get(), size, format.c_str(), argp);
vsnprintf(buf.get(), size, format, argp);
return string(buf.get(), buf.get() + size - 1 ); // without trailing '\0'
}
string sprintf(const string &format, ...) {
va_list argp;
va_start(argp, format);
string str = fmt::_vsprintf(format.c_str(), argp);
va_end(argp);
return str;
}
string sprintf(const char *format, ...) {
va_list argp;
va_start(argp, format);
string str = fmt::_vsprintf(format, argp);
......@@ -159,6 +167,15 @@ string sprintf(const string &format, ...) {
}
error errorf(const string &format, ...) {
error err;
va_list argp;
va_start(argp, format);
err.err = fmt::sprintf(format.c_str(), argp);
va_end(argp);
return err;
}
error errorf(const char *format, ...) {
error err;
va_list argp;
va_start(argp, format);
......
......@@ -107,6 +107,13 @@ namespace fmt {
string sprintf(const string &format, ...);
error errorf (const string &format, ...);
// `const char *` overload just to catch format mistakes as
// __attribute__(format) does not work with std::string.
string sprintf(const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
error errorf (const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
} // fmt::
#endif
......@@ -355,11 +355,13 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
err = fsfile.stat(&st);
if (err != nil)
return err;
ASSERT(st.st_blksize == f->blksize); // FIXME assert -> return err ?
if ((size_t)st.st_blksize != f->blksize)
return fmt::errorf("wcfs bug: blksize changed: expected %lu; got %ld",
f->blksize, st.st_blksize);
// block is beyond file size - mmap with zeros - else access to memory
// after file.size will raise SIGBUS. (assumes head/f size ↑=)
if ((blk+1)*f->blksize > st.st_size) {
if ((blk+1)*f->blksize > (size_t)st.st_size) {
err = mmap_zero_into_ro(blkmem, 1*f->blksize);
if (err != nil)
return err;
......@@ -422,7 +424,7 @@ error WatchLink::_send(StreamID stream, const string &msg) {
pkt.rawdata = // XXX copy msg XXX + "%d <stream> ...\n" ?
return wlink->_write(&pkt)
#endif
string pkt = fmt::sprintf("%ul %s\n", stream, msg.c_str());
string pkt = fmt::sprintf("%lu %s\n", stream, msg.c_str());
return wlink->_write(pkt);
}
......@@ -522,7 +524,7 @@ tuple<os::File, error> WCFS::_open(const string &path, int flags) {
// ---- misc ----
static string h(uint64_t v) {
return fmt::sprintf("%016x", v);
return fmt::sprintf("%016lx", v);
}
// map_zero_ro mmaps read-only zeros into [addr +size) so that region as all zeros.
......
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