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
26d62967
Verified
Commit
26d62967
authored
6 years ago
by
jD91mZM2
Browse files
Options
Downloads
Patches
Plain Diff
Implement strcasestr
parent
9d56ce42
No related branches found
No related tags found
No related merge requests found
Pipeline
#1442
failed
6 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/header/string/mod.rs
+22
-12
22 additions, 12 deletions
src/header/string/mod.rs
tests/expected/string/strstr.stdout
+2
-0
2 additions, 0 deletions
tests/expected/string/strstr.stdout
tests/string/strstr.c
+5
-11
5 additions, 11 deletions
tests/string/strstr.c
with
29 additions
and
23 deletions
src/header/string/mod.rs
+
22
−
12
View file @
26d62967
...
@@ -348,25 +348,35 @@ pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> size_t
...
@@ -348,25 +348,35 @@ pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> size_t
inner_strspn
(
s1
,
s2
,
true
)
inner_strspn
(
s1
,
s2
,
true
)
}
}
#[no_mangle]
unsafe
fn
inner_strstr
(
mut
haystack
:
*
const
c_char
,
mut
needle
:
*
const
c_char
,
mask
:
c_char
)
->
*
mut
c_char
{
pub
unsafe
extern
"C"
fn
strstr
(
s1
:
*
const
c_char
,
s2
:
*
const
c_char
)
->
*
mut
c_char
{
while
*
haystack
!=
0
{
let
mut
i
=
0
;
let
mut
i
=
0
;
while
*
s1
.offset
(
i
)
!=
0
{
loop
{
let
mut
j
=
0
;
if
*
needle
.offset
(
i
)
==
0
{
while
*
s2
.offset
(
j
)
!=
0
&&
*
s1
.offset
(
j
+
i
)
!=
0
{
// We reached the end of the needle, everything matches this far
if
*
s2
.offset
(
j
)
!=
*
s1
.offset
(
j
+
i
)
{
return
haystack
as
*
mut
c_char
;
break
;
}
}
j
+=
1
;
if
*
haystack
.offset
(
i
)
&
mask
!=
*
needle
.offset
(
i
)
&
mask
{
if
*
s2
.offset
(
j
)
==
0
{
break
;
return
s1
.offset
(
i
)
as
*
mut
c_char
;
}
}
i
+=
1
;
}
}
i
+=
1
;
haystack
=
haystack
.offset
(
1
);
}
}
ptr
::
null_mut
()
ptr
::
null_mut
()
}
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
strstr
(
haystack
:
*
const
c_char
,
needle
:
*
const
c_char
)
->
*
mut
c_char
{
inner_strstr
(
haystack
,
needle
,
!
0
)
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
strcasestr
(
haystack
:
*
const
c_char
,
needle
:
*
const
c_char
)
->
*
mut
c_char
{
inner_strstr
(
haystack
,
needle
,
!
32
)
}
#[no_mangle]
#[no_mangle]
pub
extern
"C"
fn
strtok
(
s1
:
*
mut
c_char
,
delimiter
:
*
const
c_char
)
->
*
mut
c_char
{
pub
extern
"C"
fn
strtok
(
s1
:
*
mut
c_char
,
delimiter
:
*
const
c_char
)
->
*
mut
c_char
{
static
mut
HAYSTACK
:
*
mut
c_char
=
ptr
::
null_mut
();
static
mut
HAYSTACK
:
*
mut
c_char
=
ptr
::
null_mut
();
...
...
This diff is collapsed.
Click to expand it.
tests/expected/string/strstr.stdout
+
2
−
0
View file @
26d62967
rust
rust
libc we trust
libc we trust
NULL
NULL
NULL
RUST
This diff is collapsed.
Click to expand it.
tests/string/strstr.c
+
5
−
11
View file @
26d62967
...
@@ -2,17 +2,11 @@
...
@@ -2,17 +2,11 @@
#include
<stdio.h>
#include
<stdio.h>
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
// should be "rust"
printf
(
"%s
\n
"
,
strstr
(
"In relibc we trust"
,
"rust"
));
char
*
res1
=
strstr
(
"In relibc we trust"
,
"rust"
);
printf
(
"%s
\n
"
,
strstr
(
"In relibc we trust"
,
"libc"
));
printf
(
"%s
\n
"
,
(
res1
)
?
res1
:
"NULL"
);
printf
(
"%s
\n
"
,
strstr
(
"In relibc we trust"
,
"bugs"
));
printf
(
"%s
\n
"
,
strstr
(
"IN RELIBC WE TRUST"
,
"rust"
));
// should be "libc we trust"
printf
(
"%s
\n
"
,
strcasestr
(
"IN RELIBC WE TRUST"
,
"rust"
));
char
*
res2
=
strstr
(
"In relibc we trust"
,
"libc"
);
printf
(
"%s
\n
"
,
(
res2
)
?
res2
:
"NULL"
);
// should be "NULL"
char
*
res3
=
strstr
(
"In relibc we trust"
,
"bugs"
);
printf
(
"%s
\n
"
,
(
res3
)
?
res3
:
"NULL"
);
return
0
;
return
0
;
}
}
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