Skip to content

Commit 834343f

Browse files
committed
Add strerror_r rule
1 parent 949608a commit 834343f

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

rules/cstring/src.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ void *f24(const void *a0, int a1, size_t a2) { return memrchr(a0, a1, a2); }
4040
#endif
4141

4242
int f27(const char *a0, const char *a1) { return strcasecmp(a0, a1); }
43+
44+
char *f28(int errnum, char *buf, size_t buflen) {
45+
return strerror_r(errnum, buf, buflen);
46+
}

rules/cstring/tgt_unsafe.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,15 @@ unsafe fn f26(a0: *mut u8, a1: i32, a2: usize) -> *mut ::libc::c_void {
130130
unsafe fn f27(a0: *const u8, a1: *const u8) -> i32 {
131131
libc::strcasecmp(a0 as *const i8, a1 as *const i8)
132132
}
133+
134+
// From the man page:
135+
//
136+
// The GNU-specific strerror_r() returns a pointer to a string containing the error message. This
137+
// may be either a pointer to a string that the function stores in buf, or a pointer to some
138+
// (immutable) static string (in which case buf is unused)
139+
//
140+
// So it's not 100% correct to always return a1. But the Rust libc version only returns int.
141+
unsafe fn f28(a0: i32, a1: *mut u8, a2: usize) -> *mut u8 {
142+
libc::strerror_r(a0, a1 as *mut i8, a2 as usize);
143+
a1
144+
}

0 commit comments

Comments
 (0)