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
0ee34fe8
Unverified
Commit
0ee34fe8
authored
7 years ago
by
Jeremy Soller
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into sprintf
parents
75920d2c
639ea091
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/string/src/lib.rs
+8
-16
8 additions, 16 deletions
src/string/src/lib.rs
tests/.gitignore
+1
-0
1 addition, 0 deletions
tests/.gitignore
tests/Makefile
+2
-1
2 additions, 1 deletion
tests/Makefile
tests/string/strncmp.c
+13
-0
13 additions, 0 deletions
tests/string/strncmp.c
with
24 additions
and
17 deletions
src/string/src/lib.rs
+
8
−
16
View file @
0ee34fe8
...
...
@@ -156,25 +156,17 @@ pub unsafe extern "C" fn strncat(s1: *mut c_char, s2: *const c_char, n: usize) -
#[no_mangle]
pub
unsafe
extern
"C"
fn
strncmp
(
s1
:
*
const
c_char
,
s2
:
*
const
c_char
,
n
:
usize
)
->
c_int
{
let
s1
=
platform
::
c_str_n
(
s1
,
n
);
let
s2
=
platform
::
c_str_n
(
s2
,
n
);
let
min_len
=
n
.min
(
s1
.len
())
.min
(
s2
.len
());
for
i
in
0
..
min_len
{
let
val
=
s1
[
i
]
-
s2
[
i
];
if
val
!=
0
{
return
val
as
c_int
;
let
s1
=
core
::
slice
::
from_raw_parts
(
s1
as
*
const
c_uchar
,
n
);
let
s2
=
core
::
slice
::
from_raw_parts
(
s2
as
*
const
c_uchar
,
n
);
for
(
&
a
,
&
b
)
in
s1
.iter
()
.zip
(
s2
.iter
())
{
let
val
=
(
a
as
c_int
)
-
(
b
as
c_int
);
if
a
!=
b
||
a
==
0
{
return
val
;
}
}
// we can't just check for the NUL byte in the loop as c_str_n() removes it
if
s1
.len
()
>
s2
.len
()
{
s1
[
min_len
]
as
c_int
}
else
if
s1
.len
()
<
s2
.len
()
{
-
(
s2
[
min_len
]
as
c_int
)
}
else
{
0
}
0
}
#[no_mangle]
...
...
This diff is collapsed.
Click to expand it.
tests/.gitignore
+
1
−
0
View file @
0ee34fe8
...
...
@@ -28,5 +28,6 @@
/setid
/sprintf
/stdlib/strtol
/string/strncmp
/unlink
/write
This diff is collapsed.
Click to expand it.
tests/Makefile
+
2
−
1
View file @
0ee34fe8
...
...
@@ -22,7 +22,8 @@ BINS=\
setid
\
sleep
\
sprintf
\
stdlib/strtol
\
stdlib/strtol
\
string/strncmp
\
unlink
\
write
...
...
This diff is collapsed.
Click to expand it.
tests/string/strncmp.c
0 → 100644
+
13
−
0
View file @
0ee34fe8
#include
<string.h>
#include
<stdio.h>
int
main
(
int
argc
,
char
*
argv
[])
{
printf
(
"%d
\n
"
,
strncmp
(
"a"
,
"aa"
,
2
));
printf
(
"%d
\n
"
,
strncmp
(
"a"
,
"aä"
,
2
));
printf
(
"%d
\n
"
,
strncmp
(
"
\xFF
"
,
"
\xFE
"
,
2
));
printf
(
"%d
\n
"
,
strncmp
(
""
,
"
\xFF
"
,
1
));
printf
(
"%d
\n
"
,
strncmp
(
"a"
,
"c"
,
1
));
printf
(
"%d
\n
"
,
strncmp
(
"a"
,
"a"
,
2
));
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