Skip to content

Commit 6ea2fee

Browse files
committed
Add platform specific rule for strerror_r
1 parent 56a66e1 commit 6ea2fee

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

rules/cstring/src.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ void *f24(const void *a0, int a1, size_t a2) { return memrchr(a0, a1, a2); }
4141

4242
int f27(const char *a0, const char *a1) { return strcasecmp(a0, a1); }
4343

44+
#if defined(__linux__)
4445
char *f28(int errnum, char *buf, size_t buflen) {
4546
return strerror_r(errnum, buf, buflen);
4647
}
48+
#elif defined(__APPLE__)
49+
int f28(int errnum, char *buf, size_t buflen) {
50+
return strerror_r(errnum, buf, buflen);
51+
}
52+
#else
53+
#error "Unsupported platform for strerror_r"
54+
#endif

rules/cstring/tgt_unsafe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ unsafe fn f27(a0: *const u8, a1: *const u8) -> i32 {
138138
// (immutable) static string (in which case buf is unused)
139139
//
140140
// So it's not 100% correct to always return a1. But the Rust libc version only returns int.
141+
#[cfg(target_os = "linux")]
141142
unsafe fn f28(a0: i32, a1: *mut u8, a2: usize) -> *mut u8 {
142143
libc::strerror_r(a0, a1 as *mut i8, a2 as usize);
143144
a1
144145
}
146+
147+
#[cfg(target_os = "macos")]
148+
unsafe fn f28(a0: i32, a1: *mut u8, a2: usize) -> i32 {
149+
libc::strerror_r(a0, a1 as *mut i8, a2 as usize)
150+
}

0 commit comments

Comments
 (0)