Skip to content

Commit f65db27

Browse files
committed
Write the errno description without Rust's suffix in refcount strerror_r
1 parent 6b23c59 commit f65db27

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎rules/cstring/tgt_refcount.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn f27(a0: Ptr<i8>, a1: Ptr<i8>) -> i32 {
181181

182182
#[cfg(target_os = "linux")]
183183
fn f28(a0: i32, a1: Ptr<i8>, a2: usize) -> Ptr<i8> {
184-
let __msg = std::io::Error::from_raw_os_error(a0).to_string();
184+
let __msg = nix::errno::Errno::from_raw(a0).desc();
185185
let __len = __msg.len().min(a2.saturating_sub(1));
186186
let mut __p = a1.clone();
187187
for __i in 0..__len {
@@ -196,7 +196,7 @@ fn f28(a0: i32, a1: Ptr<i8>, a2: usize) -> Ptr<i8> {
196196

197197
#[cfg(target_os = "macos")]
198198
fn f28(a0: i32, a1: Ptr<i8>, a2: usize) -> i32 {
199-
let __msg = std::io::Error::from_raw_os_error(a0).to_string();
199+
let __msg = nix::errno::Errno::from_raw(a0).desc();
200200
let __len = __msg.len().min(a2.saturating_sub(1));
201201
let mut __p = a1.clone();
202202
for __i in 0..__len {

‎tests/unit/string_h.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#undef _GNU_SOURCE
22
#define _GNU_SOURCE
33
#include <assert.h>
4+
#include <errno.h>
45
#include <string.h>
56
#include <strings.h>
67

@@ -153,6 +154,17 @@ static void test_strcasecmp(void) {
153154
assert(strcasecmp(p, q) == 0);
154155
}
155156

157+
static void test_strerror_r(void) {
158+
char buf[64];
159+
#if defined(__linux__)
160+
const char *msg = strerror_r(ENOENT, buf, sizeof buf);
161+
#else
162+
assert(strerror_r(ENOENT, buf, sizeof buf) == 0);
163+
const char *msg = buf;
164+
#endif
165+
assert(strcmp(msg, "No such file or directory") == 0);
166+
}
167+
156168
int main(void) {
157169
test_memcpy();
158170
test_memset();
@@ -169,5 +181,6 @@ int main(void) {
169181
test_strstr();
170182
test_strpbrk();
171183
test_strcasecmp();
184+
test_strerror_r();
172185
return 0;
173186
}

0 commit comments

Comments
 (0)