Commit 17f98edc authored by Kirill Smelkov's avatar Kirill Smelkov

X wcfs: client: os: Factor syserr -> string into _sysErrString

Currently the code to convert `int err` or errno into string is usde
only in _pathError, but in the next patches we'll need it to also handle
error from pthread_atfork. -> Factor-out to separate function.
parent 603e22dd
...@@ -45,6 +45,7 @@ global<error> ErrClosed = errors::New("file already closed"); ...@@ -45,6 +45,7 @@ global<error> ErrClosed = errors::New("file already closed");
// TODO -> os.PathError + err=syscall.Errno // 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);
static string _sysErrString(int syserr);
int _File::fd() const { return _fd; } int _File::fd() const { return _fd; }
string _File::name() const { return _path; } string _File::name() const { return _path; }
...@@ -128,10 +129,16 @@ error _File::_errno(const char *op) { ...@@ -128,10 +129,16 @@ error _File::_errno(const char *op) {
// _pathError returns os.PathError-like for op/path and system error // _pathError returns os.PathError-like for op/path and system error
// indicated by syserr. // indicated by syserr.
static error _pathError(const char *op, const string &path, int syserr) { static error _pathError(const char *op, const string &path, int syserr) {
// TODO v(_sysErrString(syserr)) -> v(syscall.Errno(syserr))
return fmt::errorf("%s %s: %s", op, v(path), v(_sysErrString(syserr)));
}
// _sysErrString returns string corresponding to system error syserr.
static string _sysErrString(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 string(estr);
return fmt::errorf("%s %s: %s", op, v(path), estr); // TODO estr -> syscall.Errno
} }
} // os:: } // os::
......
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