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
9f39456d
Commit
9f39456d
authored
7 years ago
by
Alex Lyon
Browse files
Options
Downloads
Patches
Plain Diff
string: implement strcat, strcmp, strcpy, and strdup
parent
114ee16c
No related branches found
No related tags found
1 merge request
!26
Implement several more string functions and add errno
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Cargo.lock
+1
-0
1 addition, 0 deletions
Cargo.lock
src/platform/src/lib.rs
+2
-11
2 additions, 11 deletions
src/platform/src/lib.rs
src/string/Cargo.toml
+1
-0
1 addition, 0 deletions
src/string/Cargo.toml
src/string/src/lib.rs
+23
-8
23 additions, 8 deletions
src/string/src/lib.rs
with
27 additions
and
19 deletions
Cargo.lock
+
1
−
0
View file @
9f39456d
...
@@ -454,6 +454,7 @@ version = "0.1.0"
...
@@ -454,6 +454,7 @@ version = "0.1.0"
dependencies = [
dependencies = [
"cbindgen 0.5.0",
"cbindgen 0.5.0",
"platform 0.1.0",
"platform 0.1.0",
"stdlib 0.1.0",
]
]
[[package]]
[[package]]
...
...
This diff is collapsed.
Click to expand it.
src/platform/src/lib.rs
+
2
−
11
View file @
9f39456d
...
@@ -32,18 +32,9 @@ use types::*;
...
@@ -32,18 +32,9 @@ use types::*;
pub
static
mut
errno
:
c_int
=
0
;
pub
static
mut
errno
:
c_int
=
0
;
pub
unsafe
fn
c_str
(
s
:
*
const
c_char
)
->
&
'static
[
u8
]
{
pub
unsafe
fn
c_str
(
s
:
*
const
c_char
)
->
&
'static
[
u8
]
{
use
core
::
slice
;
use
core
::
usize
;
let
mut
size
=
0
;
loop
{
if
*
s
.offset
(
size
)
==
0
{
break
;
}
size
+=
1
;
}
slice
::
from_raw_parts
(
s
as
*
const
u8
,
size
as
usize
)
c_str_n
(
s
,
usize
::
MAX
)
}
}
pub
unsafe
fn
c_str_n
(
s
:
*
const
c_char
,
n
:
usize
)
->
&
'static
[
u8
]
{
pub
unsafe
fn
c_str_n
(
s
:
*
const
c_char
,
n
:
usize
)
->
&
'static
[
u8
]
{
...
...
This diff is collapsed.
Click to expand it.
src/string/Cargo.toml
+
1
−
0
View file @
9f39456d
...
@@ -9,3 +9,4 @@ cbindgen = { path = "../../cbindgen" }
...
@@ -9,3 +9,4 @@ cbindgen = { path = "../../cbindgen" }
[dependencies]
[dependencies]
platform
=
{
path
=
"../platform"
}
platform
=
{
path
=
"../platform"
}
stdlib
=
{
path
=
"../stdlib"
}
This diff is collapsed.
Click to expand it.
src/string/src/lib.rs
+
23
−
8
View file @
9f39456d
...
@@ -3,9 +3,11 @@
...
@@ -3,9 +3,11 @@
#![no_std]
#![no_std]
extern
crate
platform
;
extern
crate
platform
;
extern
crate
stdlib
;
use
platform
::
types
::
*
;
use
platform
::
types
::
*
;
use
core
::
cmp
;
use
core
::
cmp
;
use
core
::
usize
;
#[no_mangle]
#[no_mangle]
pub
extern
"C"
fn
memccpy
(
s1
:
*
mut
c_void
,
s2
:
*
const
c_void
,
c
:
c_int
,
n
:
usize
)
->
*
mut
c_void
{
pub
extern
"C"
fn
memccpy
(
s1
:
*
mut
c_void
,
s2
:
*
const
c_void
,
c
:
c_int
,
n
:
usize
)
->
*
mut
c_void
{
...
@@ -54,8 +56,8 @@ pub extern "C" fn memchr(s: *const c_void, c: c_int, n: usize) -> *mut c_void {
...
@@ -54,8 +56,8 @@ pub extern "C" fn memchr(s: *const c_void, c: c_int, n: usize) -> *mut c_void {
// }
// }
#[no_mangle]
#[no_mangle]
pub
extern
"C"
fn
strcat
(
s1
:
*
mut
c_char
,
s2
:
*
const
c_char
)
->
*
mut
c_char
{
pub
unsafe
extern
"C"
fn
strcat
(
s1
:
*
mut
c_char
,
s2
:
*
const
c_char
)
->
*
mut
c_char
{
unimplemented!
();
strncat
(
s1
,
s2
,
usize
::
MAX
)
}
}
#[no_mangle]
#[no_mangle]
...
@@ -64,8 +66,8 @@ pub extern "C" fn strchr(s: *const c_char, c: c_int) -> *mut c_char {
...
@@ -64,8 +66,8 @@ pub extern "C" fn strchr(s: *const c_char, c: c_int) -> *mut c_char {
}
}
#[no_mangle]
#[no_mangle]
pub
extern
"C"
fn
strcmp
(
s1
:
*
const
c_char
,
s2
:
*
const
c_char
)
->
c_int
{
pub
unsafe
extern
"C"
fn
strcmp
(
s1
:
*
const
c_char
,
s2
:
*
const
c_char
)
->
c_int
{
unimplemented!
();
strncmp
(
s1
,
s2
,
usize
::
MAX
)
}
}
#[no_mangle]
#[no_mangle]
...
@@ -74,8 +76,8 @@ pub extern "C" fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int {
...
@@ -74,8 +76,8 @@ pub extern "C" fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int {
}
}
#[no_mangle]
#[no_mangle]
pub
extern
"C"
fn
strcpy
(
s1
:
*
mut
c_char
,
s2
:
*
const
c_char
)
->
*
mut
c_char
{
pub
unsafe
extern
"C"
fn
strcpy
(
s1
:
*
mut
c_char
,
s2
:
*
const
c_char
)
->
*
mut
c_char
{
unimplemented!
();
strncpy
(
s1
,
s2
,
usize
::
MAX
)
}
}
#[no_mangle]
#[no_mangle]
...
@@ -84,8 +86,21 @@ pub extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> c_ulong {
...
@@ -84,8 +86,21 @@ pub extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> c_ulong {
}
}
#[no_mangle]
#[no_mangle]
pub
extern
"C"
fn
strdup
(
s1
:
*
const
c_char
)
->
*
mut
c_char
{
pub
unsafe
extern
"C"
fn
strdup
(
s1
:
*
const
c_char
)
->
*
mut
c_char
{
unimplemented!
();
// the "+ 1" is to account for the NUL byte
let
len
=
strlen
(
s1
)
+
1
;
let
buffer
=
stdlib
::
malloc
(
len
)
as
*
mut
_
;
if
buffer
.is_null
()
{
// TODO: set errno
}
else
{
//memcpy(buffer, s1, len)
for
i
in
0
..
len
as
isize
{
*
buffer
.offset
(
i
)
=
*
s1
.offset
(
i
);
}
}
buffer
}
}
#[no_mangle]
#[no_mangle]
...
...
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