Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Limkilde Svendsen
relibc
Commits
aff35892
Commit
aff35892
authored
6 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Add fs module
parent
7f14fcde
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/fs.rs
+88
-0
88 additions, 0 deletions
src/fs.rs
src/io.rs
+1
-0
1 addition, 0 deletions
src/io.rs
src/lib.rs
+2
-0
2 additions, 0 deletions
src/lib.rs
with
91 additions
and
0 deletions
src/fs.rs
0 → 100644
+
88
−
0
View file @
aff35892
use
c_str
::
CStr
;
use
header
::
fcntl
::
O_CREAT
;
use
header
::
unistd
::{
SEEK_SET
,
SEEK_CUR
,
SEEK_END
};
use
io
;
use
platform
;
use
platform
::{
Pal
,
Sys
};
use
platform
::
types
::
*
;
fn
last_os_error
()
->
io
::
Error
{
let
errno
=
unsafe
{
platform
::
errno
};
io
::
Error
::
from_raw_os_error
(
errno
)
}
pub
struct
File
(
c_int
);
impl
File
{
pub
fn
open
(
path
:
&
CStr
,
oflag
:
c_int
)
->
io
::
Result
<
Self
>
{
match
Sys
::
open
(
path
,
oflag
,
0
)
{
-
1
=>
Err
(
last_os_error
()),
ok
=>
Ok
(
File
(
ok
)),
}
}
pub
fn
create
(
path
:
&
CStr
,
oflag
:
c_int
,
mode
:
mode_t
)
->
io
::
Result
<
Self
>
{
match
Sys
::
open
(
path
,
oflag
|
O_CREAT
,
mode
)
{
-
1
=>
Err
(
last_os_error
()),
ok
=>
Ok
(
File
(
ok
)),
}
}
pub
fn
sync_all
(
&
self
)
->
io
::
Result
<
()
>
{
match
Sys
::
fsync
(
self
.0
)
{
-
1
=>
Err
(
last_os_error
()),
_ok
=>
Ok
(()),
}
}
pub
fn
set_len
(
&
self
,
size
:
u64
)
->
io
::
Result
<
()
>
{
match
Sys
::
ftruncate
(
self
.0
,
size
as
off_t
)
{
-
1
=>
Err
(
last_os_error
()),
_ok
=>
Ok
(()),
}
}
pub
fn
try_clone
(
&
self
)
->
io
::
Result
<
Self
>
{
match
Sys
::
dup
(
self
.0
)
{
-
1
=>
Err
(
last_os_error
()),
ok
=>
Ok
(
File
(
ok
)),
}
}
}
impl
io
::
Read
for
File
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
io
::
Result
<
usize
>
{
match
Sys
::
read
(
self
.0
,
buf
)
{
-
1
=>
Err
(
last_os_error
()),
ok
=>
Ok
(
ok
as
usize
),
}
}
}
impl
io
::
Write
for
File
{
fn
write
(
&
mut
self
,
buf
:
&
[
u8
])
->
io
::
Result
<
usize
>
{
match
Sys
::
write
(
self
.0
,
buf
)
{
-
1
=>
Err
(
last_os_error
()),
ok
=>
Ok
(
ok
as
usize
),
}
}
fn
flush
(
&
mut
self
)
->
io
::
Result
<
()
>
{
Ok
(())
}
}
impl
io
::
Seek
for
File
{
fn
seek
(
&
mut
self
,
pos
:
io
::
SeekFrom
)
->
io
::
Result
<
u64
>
{
let
(
offset
,
whence
)
=
match
pos
{
io
::
SeekFrom
::
Start
(
start
)
=>
(
start
as
off_t
,
SEEK_SET
),
io
::
SeekFrom
::
Current
(
current
)
=>
(
current
as
off_t
,
SEEK_CUR
),
io
::
SeekFrom
::
End
(
end
)
=>
(
end
as
off_t
,
SEEK_END
),
};
match
Sys
::
lseek
(
self
.0
,
offset
,
whence
)
{
-
1
=>
Err
(
last_os_error
()),
ok
=>
Ok
(
ok
as
u64
),
}
}
}
This diff is collapsed.
Click to expand it.
src/io.rs
0 → 100644
+
1
−
0
View file @
aff35892
pub
use
core_io
::
*
;
This diff is collapsed.
Click to expand it.
src/lib.rs
+
2
−
0
View file @
aff35892
...
@@ -37,7 +37,9 @@ extern crate spin;
...
@@ -37,7 +37,9 @@ extern crate spin;
#[macro_use]
#[macro_use]
mod
macros
;
mod
macros
;
pub
mod
c_str
;
pub
mod
c_str
;
pub
mod
fs
;
pub
mod
header
;
pub
mod
header
;
pub
mod
io
;
pub
mod
platform
;
pub
mod
platform
;
pub
mod
start
;
pub
mod
start
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment