Commit d392cd57 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 64fddd20
...@@ -43,7 +43,7 @@ namespace os { ...@@ -43,7 +43,7 @@ namespace os {
global<error> ErrClosed = errors::New("file already closed"); global<error> ErrClosed = errors::New("file already closed");
// XXX -> make public // TODO -> os.PathError + err=syscall.Errno
static error _pathError(const char *op, const string &path, int syserr); static error _pathError(const char *op, const string &path, int syserr);
int _File::fd() const { return _fd; } int _File::fd() const { return _fd; }
...@@ -60,7 +60,7 @@ void _File::decref() { ...@@ -60,7 +60,7 @@ void _File::decref() {
tuple<File, error> open(const string &path, int flags, mode_t mode) { tuple<File, error> open(const string &path, int flags, mode_t mode) {
int fd = ::open(path.c_str(), flags, mode); int fd = ::open(path.c_str(), flags, mode);
if (fd == -1) if (fd == -1)
return make_tuple(nil, _pathError("open", path, errno)); // XXX -> wrapper? return make_tuple(nil, _pathError("open", path, errno));
File f = adoptref(new _File); File f = adoptref(new _File);
f->_path = path; f->_path = path;
...@@ -131,7 +131,7 @@ static error _pathError(const char *op, const string &path, int syserr) { ...@@ -131,7 +131,7 @@ static error _pathError(const char *op, const string &path, int syserr) {
char ebuf[128]; char ebuf[128];
char *estr = strerror_r(syserr, ebuf, sizeof(ebuf)); char *estr = strerror_r(syserr, ebuf, sizeof(ebuf));
return fmt::errorf("%s %s: %s", op, v(path), estr); // XXX estr -> errnoError return fmt::errorf("%s %s: %s", op, v(path), estr); // TODO estr -> syscall.Errno
} }
} // os:: } // os::
...@@ -174,7 +174,7 @@ error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t o ...@@ -174,7 +174,7 @@ error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t o
error unmap(void *addr, size_t size) { error unmap(void *addr, size_t size) {
int err = ::munmap(addr, size); int err = ::munmap(addr, size);
if (err != 0) if (err != 0)
return os::_pathError("munmap", "<memory>" /*XXX ok?*/, errno); return os::_pathError("munmap", "<memory>", errno);
return nil; return nil;
} }
...@@ -228,18 +228,18 @@ tuple<uint64_t, error> parseHex64(const string& s) { ...@@ -228,18 +228,18 @@ tuple<uint64_t, error> parseHex64(const string& s) {
return make_tuple(0, fmt::errorf("hex64 %s invalid", v(s))); return make_tuple(0, fmt::errorf("hex64 %s invalid", v(s)));
uint64_t v; uint64_t v;
int n = sscanf(s.c_str(), "%16" SCNx64, &v); // XXX verify int n = sscanf(s.c_str(), "%16" SCNx64, &v);
if (n != 1) if (n != 1)
return make_tuple(0, fmt::errorf("hex64 %s invalid", v(s))); return make_tuple(0, fmt::errorf("hex64 %s invalid", v(s)));
return make_tuple(v, nil); return make_tuple(v, nil);
} }
// paeseInt decodes string s as signed decimal integer. // parseInt decodes string s as signed decimal integer.
tuple<int64_t, error> parseInt(const string& s) { tuple<int64_t, error> parseInt(const string& s) {
int64_t v; int64_t v;
int n = sscanf(s.c_str(), "%" SCNi64, &v); // XXX verify int n = sscanf(s.c_str(), "%" SCNi64, &v);
if (!(n == 1 && std::to_string(v) == s)) // XXX verify if (!(n == 1 && std::to_string(v) == s))
return make_tuple(0, fmt::errorf("int %s invalid", v(s))); return make_tuple(0, fmt::errorf("int %s invalid", v(s)));
return make_tuple(v, nil); return make_tuple(v, nil);
} }
...@@ -247,8 +247,8 @@ tuple<int64_t, error> parseInt(const string& s) { ...@@ -247,8 +247,8 @@ tuple<int64_t, error> parseInt(const string& s) {
// parseUint decodes string s as unsigned decimal integer. // parseUint decodes string s as unsigned decimal integer.
tuple<uint64_t, error> parseUint(const string& s) { tuple<uint64_t, error> parseUint(const string& s) {
uint64_t v; uint64_t v;
int n = sscanf(s.c_str(), "%" SCNu64, &v); // XXX verify int n = sscanf(s.c_str(), "%" SCNu64, &v);
if (!(n == 1 && std::to_string(v) == s)) // XXX verify if (!(n == 1 && std::to_string(v) == s))
return make_tuple(0, fmt::errorf("uint %s invalid", v(s))); return make_tuple(0, fmt::errorf("uint %s invalid", v(s)));
return make_tuple(v, nil); return make_tuple(v, nil);
} }
...@@ -310,7 +310,7 @@ void __Logf(const char *file, int line, char level, const char *format, ...) { ...@@ -310,7 +310,7 @@ void __Logf(const char *file, int line, char level, const char *format, ...) {
pid_t tid = syscall(SYS_gettid); pid_t tid = syscall(SYS_gettid);
string prefix = fmt::sprintf("%c%s.%06d % 7d %s:%d] ", level, t_buf, t_us, tid, file, line); string prefix = fmt::sprintf("%c%s.%06d % 7d %s:%d] ", level, t_buf, t_us, tid, file, line);
// XXX better to emit prefix and msg in one go. // TODO better to emit prefix and msg in one go.
flockfile(stderr); flockfile(stderr);
fprintf(stderr, "%s", v(prefix)); fprintf(stderr, "%s", v(prefix));
......
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