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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
a11ba478
Commit
a11ba478
authored
Oct 23, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e1e09762
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
+23
-6
wcfs/internal/wcfs_misc.cpp
wcfs/internal/wcfs_misc.cpp
+20
-4
wcfs/internal/wcfs_misc.h
wcfs/internal/wcfs_misc.h
+3
-2
No files found.
wcfs/internal/wcfs_misc.cpp
View file @
a11ba478
...
...
@@ -17,14 +17,22 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// XXX #define _GNU_SOURCE ?
#include "wcfs_misc.h"
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <memory>
// os::
namespace
os
{
tuple
<
File
,
error
>
open
(
const
string
&
path
,
int
flags
,
mode_t
mode
)
{
File
f
=
{.
_fd
=
-
1
,
.
path
=
path
};
int
err
=
std
::
open
(
path
.
c_str
(),
flags
,
mode
);
int
err
=
::
open
(
path
.
c_str
(),
flags
,
mode
);
if
(
err
!=
0
)
return
make_tuple
(
f
,
f
.
_errno
(
"open"
));
}
...
...
@@ -32,7 +40,7 @@ tuple<File, error> open(const string &path, int flags, mode_t mode) {
error
File
::
close
()
{
File
*
f
=
this
;
int
err
=
close
(
f
->
_fd
);
int
err
=
::
close
(
f
->
_fd
);
if
(
err
!=
0
)
return
f
->
_errno
(
"close"
);
}
...
...
@@ -50,7 +58,9 @@ error File::stat(struct stat *st) {
// _errno returns error corresponding to op and errno.
error
File
::
_errno
(
const
char
*
op
)
{
File
*
f
=
this
;
return
errorf
(
"%s %s: %s"
,
op
,
f
->
path
,
strerror_r
(
errno
));
char
ebuf
[
128
];
char
*
estr
=
strerror_r
(
errno
,
ebuf
,
sizeof
(
ebuf
));
return
fmt
::
errorf
(
"%s %s: %s"
,
op
,
f
->
_path
,
estr
);
}
}
// os::
...
...
@@ -60,7 +70,7 @@ error File::_errno(const char *op) {
namespace
fmt
{
string
sprintf
(
const
string
&
format
,
...)
{
// https://stackoverflow.com/a/26221725/9456786
//
based on
https://stackoverflow.com/a/26221725/9456786
va_list
ap
;
va_start
(
ap
,
format
);
...
...
@@ -74,4 +84,10 @@ string sprintf(const string &format, ...) {
return
string
(
buf
.
get
(),
buf
.
get
()
+
size
-
1
);
// without trailing '\0'
}
error
errorf
(
const
string
&
format
,
...)
{
error
err
;
err
.
err
=
fmt
::
sprintf
(
format
,
...);
// XXX
return
err
;
}
}
// fmt::
wcfs/internal/wcfs_misc.h
View file @
a11ba478
...
...
@@ -35,7 +35,7 @@ const nullptr_t nil = nullptr;
// error mimics error from Go.
struct
error
{
string
err
;
string
err
;
// XXX -> private + ,error() ?
error
()
{}
error
(
nullptr_t
)
{}
// = nil
...
...
@@ -61,7 +61,7 @@ class File {
string
_path
;
public:
friend
open
...
friend
tuple
<
File
,
error
>
open
(
const
string
&
path
,
int
flags
,
mode_t
mode
);
// XXX empty ctor -> fd=-1, path=?
int
fd
();
string
name
();
...
...
@@ -85,6 +85,7 @@ tuple<File, error> open(const string &path, int flags = O_RDONLY,
namespace
fmt
{
string
sprintf
(
const
string
&
format
,
...);
error
errorf
(
const
string
&
format
,
...);
}
// fmt::
...
...
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