mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-24 18:53:51 +08:00
05bad5eda1
Most of it is duplicated, hence untested. Functions like mbrtowc are not exposed by the libc crate, so declare them ourselves. Since we don't know the definition of C macros, add two big hacks to make this work: 1. Replace MB_LEN_MAX and mbstate_t with values (resp types) that should be large enough for any implementation. 2. Detect the definition of MB_CUR_MAX in the build script. This requires more changes for each new libc. We could also use this approach for 1. Additionally, this commit brings a small behavior change to read_unquoted_escape(): we cannot decode surrogate code points like \UDE01 into a Rust char, so use � (\UFFFD, replacement character) instead. Previously, we added such code points to a wcstring; looks like they were ignored when printed.
20 lines
646 B
Rust
20 lines
646 B
Rust
extern "C" {
|
|
pub fn wcrtomb(s: *mut libc::c_char, wc: libc::wchar_t, ps: *mut mbstate_t) -> usize;
|
|
pub fn mbrtowc(
|
|
pwc: *mut libc::wchar_t,
|
|
s: *const libc::c_char,
|
|
n: usize,
|
|
p: *mut mbstate_t,
|
|
) -> usize;
|
|
}
|
|
|
|
// HACK This should be mbstate_t from libc but that's not exposed. Since it's only written by
|
|
// libc, we define it as opaque type that should be large enough for all implementations.
|
|
pub type mbstate_t = [u64; 16];
|
|
pub fn zero_mbstate() -> mbstate_t {
|
|
[0; 16]
|
|
}
|
|
|
|
// HACK This should be the MB_LEN_MAX macro from libc but that's not easy to get.
|
|
pub const AT_LEAST_MB_LEN_MAX: usize = 32;
|