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
ad39a4c6
Commit
ad39a4c6
authored
Nov 14, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5a045ed1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
20 deletions
+33
-20
wcfs/internal/wcfs_misc.cpp
wcfs/internal/wcfs_misc.cpp
+23
-18
wcfs/internal/wcfs_misc.h
wcfs/internal/wcfs_misc.h
+10
-2
No files found.
wcfs/internal/wcfs_misc.cpp
View file @
ad39a4c6
...
...
@@ -22,6 +22,7 @@
#include "wcfs_misc.h"
#include <golang/libgolang.h>
#include <golang/errors.h>
using
namespace
golang
;
#include <inttypes.h>
...
...
@@ -33,6 +34,7 @@ using namespace golang;
#include <memory>
#if 0
// error
error error::New(const string &text) {
error err;
...
...
@@ -43,23 +45,24 @@ error error::New(const string &text) {
string error::Error() const {
return _err;
}
#endif
// io::
namespace
io
{
const
error
EOF_
=
error
::
New
(
"EOF"
);
const
error
ErrUnexpectedEOF
=
error
::
New
(
"unexpected EOF"
);
const
error
EOF_
=
error
s
::
New
(
"EOF"
);
const
error
ErrUnexpectedEOF
=
error
s
::
New
(
"unexpected EOF"
);
}
// io::
// os::
namespace
os
{
// XXX -> make public
static
error
_pathError
(
const
char
*
op
,
const
string
&
path
,
int
syserr
);
int
File
::
fd
()
const
{
return
_fd
;
}
string
File
::
name
()
const
{
return
_path
;
}
int
_File
::
fd
()
const
{
return
_fd
;
}
string
_File
::
name
()
const
{
return
_path
;
}
tuple
<
File
,
error
>
open
(
const
string
&
path
,
int
flags
,
mode_t
mode
)
{
...
...
@@ -72,8 +75,8 @@ tuple<File, error> open(const string &path, int flags, mode_t mode) {
return
make_tuple
(
f
,
err
);
}
error
File
::
close
()
{
File
&
f
=
*
this
;
error
_
File
::
close
()
{
_
File
&
f
=
*
this
;
int
err
=
::
close
(
f
.
_fd
);
if
(
err
!=
0
)
...
...
@@ -82,8 +85,8 @@ error File::close() {
return
nil
;
}
tuple
<
int
,
error
>
File
::
read
(
void
*
buf
,
size_t
count
)
{
File
&
f
=
*
this
;
tuple
<
int
,
error
>
_
File
::
read
(
void
*
buf
,
size_t
count
)
{
_
File
&
f
=
*
this
;
int
n
;
n
=
::
read
(
f
.
_fd
,
buf
,
count
);
...
...
@@ -95,8 +98,8 @@ tuple<int, error> File::read(void *buf, size_t count) {
return
make_tuple
(
n
,
nil
);
}
tuple
<
int
,
error
>
File
::
write
(
const
void
*
buf
,
size_t
count
)
{
File
&
f
=
*
this
;
tuple
<
int
,
error
>
_
File
::
write
(
const
void
*
buf
,
size_t
count
)
{
_
File
&
f
=
*
this
;
int
n
,
wrote
=
0
;
// NOTE contrary to write(2) we have to write all data as io.Writer requires.
...
...
@@ -113,8 +116,8 @@ tuple <int, error> File::write(const void *buf, size_t count) {
return
make_tuple
(
wrote
,
nil
);
}
error
File
::
stat
(
struct
stat
*
st
)
{
File
&
f
=
*
this
;
error
_
File
::
stat
(
struct
stat
*
st
)
{
_
File
&
f
=
*
this
;
int
err
=
fstat
(
f
.
_fd
,
st
);
if
(
err
!=
0
)
...
...
@@ -124,8 +127,8 @@ error File::stat(struct stat *st) {
// _errno returns error corresponding to op(file) and errno.
error
File
::
_errno
(
const
char
*
op
)
{
File
&
f
=
*
this
;
error
_
File
::
_errno
(
const
char
*
op
)
{
_
File
&
f
=
*
this
;
return
_pathError
(
op
,
f
.
_path
,
errno
);
}
...
...
@@ -146,12 +149,12 @@ namespace mm {
// map_into memory-maps f.fd[offset +size) into [addr +size).
// prot is PROT_* from mmap(2).
// flags is MAP_* from mmap(2); MAP_FIXED is added automatically.
error
map_into
(
void
*
addr
,
size_t
size
,
int
prot
,
int
flags
,
const
os
::
File
&
f
,
off_t
offset
)
{
error
map_into
(
void
*
addr
,
size_t
size
,
int
prot
,
int
flags
,
const
os
::
File
f
,
off_t
offset
)
{
void
*
addr2
;
addr2
=
mmap
(
addr
,
size
,
prot
,
MAP_FIXED
|
flags
,
f
.
fd
(),
offset
);
addr2
=
mmap
(
addr
,
size
,
prot
,
MAP_FIXED
|
flags
,
f
->
fd
(),
offset
);
if
(
addr2
==
MAP_FAILED
)
return
os
::
_pathError
(
"mmap"
,
f
.
name
(),
errno
);
return
os
::
_pathError
(
"mmap"
,
f
->
name
(),
errno
);
if
(
addr2
!=
addr
)
panic
(
"mmap(addr, MAP_FIXED): returned !addr"
);
return
nil
;
...
...
@@ -239,6 +242,7 @@ vector<string> split(const string &s, char sep) {
}
// strings::
#if 0
// context::
namespace context {
...
...
@@ -262,6 +266,7 @@ Context* background() {
}
} // context::
#endif
// xstrconv:: (strconv-like)
namespace
xstrconv
{
...
...
wcfs/internal/wcfs_misc.h
View file @
ad39a4c6
...
...
@@ -53,6 +53,7 @@ using std::vector;
// nil is synonym for nullptr and NULL.
const
nullptr_t
nil
=
nullptr
;
#if 0
// error mimics error from Go.
class error {
string _err;
...
...
@@ -82,6 +83,7 @@ public:
// New creats error with text
static error New(const string &text);
};
#endif
// io::
namespace
io
{
...
...
@@ -102,7 +104,9 @@ namespace os {
// os::File mimics os.File from Go.
// its operations return error with full file context.
class
File
{
class
_File
;
typedef
refptr
<
_File
>
File
;
class
_File
{
int
_fd
;
string
_path
;
...
...
@@ -141,7 +145,7 @@ tuple<File, error> open(const string &path, int flags = O_RDONLY,
// mm::
namespace
mm
{
error
map_into
(
void
*
addr
,
size_t
,
int
prot
,
int
flags
,
const
os
::
File
&
f
,
off_t
offset
);
error
map_into
(
void
*
addr
,
size_t
,
int
prot
,
int
flags
,
const
os
::
File
f
,
off_t
offset
);
// XXX unmap
}
// mm::
...
...
@@ -173,6 +177,7 @@ vector<string> split(const string &s, char sep);
}
// strings::
#if 0
// context::
namespace context {
...
...
@@ -189,6 +194,7 @@ extern const error canceled;
extern const error deadlineExceeded;
} // context::
#endif
#if 0
interface(Context) {
...
...
@@ -213,6 +219,7 @@ public:
// ---- misc ----
#if 0
#include <unordered_map>
#include <unordered_set>
...
...
@@ -255,6 +262,7 @@ struct set : std::unordered_set<Key> {
return s.find(k) != s.end();
}
};
#endif
// xstrconv::
...
...
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