Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
d392cd57
Commit
d392cd57
authored
Apr 03, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
64fddd20
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
wcfs/client/wcfs_misc.cpp
wcfs/client/wcfs_misc.cpp
+11
-11
No files found.
wcfs/client/wcfs_misc.cpp
View file @
d392cd57
...
@@ -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
);
}
}
// pa
e
seInt decodes string s as signed decimal integer.
// pa
r
seInt 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
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment