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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Tornax O7
relibc
Commits
601cb43f
Commit
601cb43f
authored
5 years ago
by
jD91mZM2
Browse files
Options
Downloads
Plain Diff
Merge branch 'strerror_r' into 'master'
Add POSIX strerror_r See merge request
!207
parents
78d52c6e
c68a0d56
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/header/string/mod.rs
+19
-0
19 additions, 0 deletions
src/header/string/mod.rs
tests/error.c
+11
-1
11 additions, 1 deletion
tests/error.c
tests/expected/error.stdout
+2
-0
2 additions, 0 deletions
tests/expected/error.stdout
with
32 additions
and
1 deletion
src/header/string/mod.rs
+
19
−
0
View file @
601cb43f
...
@@ -259,6 +259,25 @@ pub unsafe extern "C" fn strerror(errnum: c_int) -> *mut c_char {
...
@@ -259,6 +259,25 @@ pub unsafe extern "C" fn strerror(errnum: c_int) -> *mut c_char {
strerror_buf
.as_mut_ptr
()
as
*
mut
c_char
strerror_buf
.as_mut_ptr
()
as
*
mut
c_char
}
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
strerror_r
(
errnum
:
c_int
,
buf
:
*
mut
c_char
,
buflen
:
size_t
,
)
->
c_int
{
let
msg
=
strerror
(
errnum
);
let
len
=
strlen
(
msg
);
if
len
>=
buflen
{
memcpy
(
buf
as
*
mut
c_void
,
msg
as
*
const
c_void
,
buflen
-
1
);
*
buf
.add
(
buflen
-
1
)
=
0
;
return
ERANGE
as
c_int
;
}
memcpy
(
buf
as
*
mut
c_void
,
msg
as
*
const
c_void
,
len
+
1
);
0
}
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
strlen
(
s
:
*
const
c_char
)
->
size_t
{
pub
unsafe
extern
"C"
fn
strlen
(
s
:
*
const
c_char
)
->
size_t
{
strnlen
(
s
,
usize
::
MAX
)
strnlen
(
s
,
usize
::
MAX
)
...
...
This diff is collapsed.
Click to expand it.
tests/error.c
+
11
−
1
View file @
601cb43f
...
@@ -7,6 +7,16 @@
...
@@ -7,6 +7,16 @@
int
main
(
void
)
{
int
main
(
void
)
{
chdir
(
"nonexistent"
);
chdir
(
"nonexistent"
);
printf
(
"errno: %d = %s
\n
"
,
errno
,
strerror
(
errno
));
int
err
=
errno
;
printf
(
"errno: %d = %s
\n
"
,
err
,
strerror
(
errno
));
perror
(
"perror"
);
perror
(
"perror"
);
char
buf1
[
256
];
int
ret1
=
strerror_r
(
err
,
buf1
,
256
);
printf
(
"errno: %d = %s, return: %d
\n
"
,
err
,
buf1
,
ret1
);
char
buf2
[
3
];
int
ret2
=
strerror_r
(
err
,
buf2
,
3
);
printf
(
"errno: %d = %s, return: %d
\n
"
,
err
,
buf2
,
ret2
);
}
}
This diff is collapsed.
Click to expand it.
tests/expected/error.stdout
+
2
−
0
View file @
601cb43f
errno: 2 = No such file or directory
errno: 2 = No such file or directory
errno: 2 = No such file or directory, return: 0
errno: 2 = No, return: 34
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