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
d62db7b1
Commit
d62db7b1
authored
5 years ago
by
Mateusz Mikuła
Committed by
Mateusz Mikuła
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add memrchr()
parent
15aa52a8
No related branches found
No related tags found
1 merge request
!214
Add memrchr()
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/header/string/mod.rs
+14
-0
14 additions, 0 deletions
src/header/string/mod.rs
tests/expected/string/mem.stdout
+1
-0
1 addition, 0 deletions
tests/expected/string/mem.stdout
tests/string/mem.c
+5
-0
5 additions, 0 deletions
tests/string/mem.c
with
20 additions
and
0 deletions
src/header/string/mod.rs
+
14
−
0
View file @
d62db7b1
...
...
@@ -107,6 +107,20 @@ pub unsafe extern "C" fn memmove(s1: *mut c_void, s2: *const c_void, n: size_t)
s1
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
memrchr
(
haystack
:
*
const
c_void
,
needle
:
c_int
,
len
:
size_t
,
)
->
*
mut
c_void
{
let
haystack
=
slice
::
from_raw_parts
(
haystack
as
*
const
u8
,
len
as
usize
);
match
memchr
::
memrchr
(
needle
as
u8
,
haystack
)
{
Some
(
index
)
=>
haystack
[
index
..
]
.as_ptr
()
as
*
mut
c_void
,
None
=>
ptr
::
null_mut
(),
}
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
memset
(
s
:
*
mut
c_void
,
c
:
c_int
,
n
:
size_t
)
->
*
mut
c_void
{
for
i
in
0
..
n
{
...
...
This diff is collapsed.
Click to expand it.
tests/expected/string/mem.stdout
+
1
−
0
View file @
d62db7b1
# mem #
Correct memchr
Correct memrchr
Correct memccpy
Correct memcmp
This diff is collapsed.
Click to expand it.
tests/string/mem.c
+
5
−
0
View file @
d62db7b1
...
...
@@ -14,6 +14,11 @@ int main(void) {
exit
(
EXIT_FAILURE
);
}
puts
(
"Correct memchr"
);
if
((
size_t
)
memrchr
((
void
*
)
arr
,
1
,
100
)
-
(
size_t
)
arr
!=
50
)
{
puts
(
"Incorrect memrchr"
);
exit
(
EXIT_FAILURE
);
}
puts
(
"Correct memrchr"
);
char
arr2
[
51
];
memset
(
arr2
,
0
,
51
);
// Compiler builtin, should work
memccpy
((
void
*
)
arr2
,
(
void
*
)
arr
,
1
,
100
);
...
...
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