lambda-fairy / rust-errno

:boom: Cross-platform interface to the `errno` variable
https://docs.rs/errno
Apache License 2.0
65 stars 40 forks source link

Use libc::strerror_r instead of our own definition #85

Closed taiki-e closed 1 year ago

taiki-e commented 1 year ago

We already depend on libc to use strlen, and libc provides strerror_r for all unix/wasi platforms we support.

(As for errno_location, it seems that libc does not provide a corresponding one for some platforms yet.)

taiki-e commented 1 year ago

for all unix/wasi platforms we support.

FYI, the following is a script I used to check this.

#!/bin/bash

targets=(
    # src/windows.rs
    x86_64-pc-windows-msvc
    x86_64-pc-windows-gnu
    # src/wasi.rs
    wasm32-wasi
    # src/unix.rs
    aarch64-apple-ios
    i686-unknown-hurd-gnu
    powerpc64-ibm-aix
    riscv32imc-esp-espidf
    x86_64-apple-darwin
    x86_64-linux-android
    x86_64-pc-nto-qnx710
    x86_64-pc-solaris
    x86_64-unknown-dragonfly
    x86_64-unknown-freebsd
    x86_64-unknown-haiku
    x86_64-unknown-hermit
    x86_64-unknown-illumos
    x86_64-unknown-linux-gnu
    x86_64-unknown-linux-musl
    x86_64-unknown-netbsd
    x86_64-unknown-openbsd
    x86_64-unknown-redox
)

# Use -Z build-std for tier 3 targets.
rustup component add rust-src

for target in "${targets[@]}"; do
    if rustup target add "${target}" &>/dev/null; then
        cargo build --no-default-features --target "${target}"
    else
        cargo build --no-default-features -Z build-std=core --target "${target}"
    fi
done
sunfishcode commented 1 year ago

It does appear that the libc crate version has the needed __xpg_strerror_r attribute, so this looks good.