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
redox-os
relibc
Commits
5c4c49a9
Verified
Commit
5c4c49a9
authored
6 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Add getdelim and getline
parent
96cc56a0
No related branches found
No related tags found
No related merge requests found
Pipeline
#1912
passed with warnings
6 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/header/stdio/getdelim.rs
+45
-0
45 additions, 0 deletions
src/header/stdio/getdelim.rs
src/header/stdio/mod.rs
+3
-0
3 additions, 0 deletions
src/header/stdio/mod.rs
with
48 additions
and
0 deletions
src/header/stdio/getdelim.rs
0 → 100644
+
45
−
0
View file @
5c4c49a9
use
alloc
::
vec
::
Vec
;
use
core
::
ptr
;
use
header
::
stdio
::
FILE
;
use
header
::
stdlib
;
use
io
::
BufRead
;
use
platform
::
types
::
*
;
#[no_mangle]
pub
extern
"C"
fn
__getline
(
lineptr
:
*
mut
*
mut
c_char
,
n
:
*
mut
size_t
,
stream
:
*
mut
FILE
)
->
ssize_t
{
__getdelim
(
lineptr
,
n
,
b'\n'
as
c_int
,
stream
)
}
#[no_mangle]
pub
extern
"C"
fn
__getdelim
(
lineptr
:
*
mut
*
mut
c_char
,
n
:
*
mut
size_t
,
delim
:
c_int
,
stream
:
*
mut
FILE
)
->
ssize_t
{
let
lineptr
=
unsafe
{
&
mut
*
lineptr
};
let
n
=
unsafe
{
&
mut
*
n
};
let
delim
=
delim
as
u8
;
//TODO: More efficient algorithm using lineptr and n instead of this vec
let
mut
buf
=
Vec
::
new
();
let
count
=
{
let
mut
stream
=
unsafe
{
&
mut
*
stream
}
.lock
();
match
stream
.read_until
(
delim
,
&
mut
buf
)
{
Ok
(
ok
)
=>
ok
,
Err
(
err
)
=>
return
-
1
,
}
};
//TODO: Check errors and improve safety
unsafe
{
// Allocate lineptr to size of buf and set n to size of lineptr
*
n
=
count
+
1
;
*
lineptr
=
stdlib
::
realloc
(
*
lineptr
as
*
mut
c_void
,
*
n
)
as
*
mut
c_char
;
// Copy buf to lineptr
ptr
::
copy
(
buf
.as_ptr
(),
*
lineptr
as
*
mut
u8
,
count
);
// NUL terminate lineptr
*
lineptr
.offset
(
count
as
isize
)
=
0
;
// Return allocated size
*
n
as
ssize_t
}
}
This diff is collapsed.
Click to expand it.
src/header/stdio/mod.rs
+
3
−
0
View file @
5c4c49a9
...
@@ -27,6 +27,9 @@ mod constants;
...
@@ -27,6 +27,9 @@ mod constants;
pub
use
self
::
default
::
*
;
pub
use
self
::
default
::
*
;
mod
default
;
mod
default
;
pub
use
self
::
getdelim
::
*
;
mod
getdelim
;
mod
ext
;
mod
ext
;
mod
helpers
;
mod
helpers
;
mod
printf
;
mod
printf
;
...
...
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