summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Batischev <eual.jp@gmail.com>2021-01-17 22:43:33 +0300
committerAlexander Batischev <eual.jp@gmail.com>2021-02-11 01:22:49 +0300
commit3e4d684dcdd1dff363a45c70c914204013810155 (patch)
tree7f9cdc41355aae4beef3fab66235f9e6e04e45f4
parent3c907ed65bee8b85d30361570e628dac2d2ae71a (diff)
downloadrust-libc-3e4d684dcdd1dff363a45c70c914204013810155.tar.gz
Add bindings for iconv calls
FreeBSD-likes all implement iconv: - DragonflyBSD: https://github.com/DragonFlyBSD/DragonFlyBSD/blob/bbb35c81f71fe2a0880a1f8bb77876ee98b63338/include/iconv.h - FreeBSD: https://github.com/freebsd/freebsd-src/blob/a6dc68c0e0f8a24ffaf0b4e78e58141ef7897047/include/iconv.h NetBSD-likes: - NetBSD: https://github.com/NetBSD/src/blob/81a39f60870b617d7fca299c126de6553d78cc5a/include/iconv.h - OpenBSD doesn't implement it macOS: apparently ships a conforming implementation as a separate library: https://stackoverflow.com/questions/57734434/libiconv-or-iconv-undefined-symbol-on-mac-osx/57734435#57734435 Linux: - glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=iconv/iconv.h;h=fdddf53d99c3046ef9c280db01a425c2f499043e;hb=HEAD - musl: https://git.musl-libc.org/cgit/musl/tree/include/iconv.h?id=455f96857f91d14e193219ca00969354a981c09c
-rw-r--r--build.rs7
-rwxr-xr-xlibc-test/build.rs12
-rw-r--r--src/unix/bsd/apple/mod.rs15
-rw-r--r--src/unix/bsd/freebsdlike/mod.rs15
-rw-r--r--src/unix/bsd/netbsdlike/netbsd/mod.rs15
-rw-r--r--src/unix/linux_like/linux/mod.rs15
6 files changed, 78 insertions, 1 deletions
diff --git a/build.rs b/build.rs
index 27cfb02401..ef43dfb788 100644
--- a/build.rs
+++ b/build.rs
@@ -10,6 +10,7 @@ fn main() {
let const_extern_fn_cargo_feature =
env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
let libc_ci = env::var("LIBC_CI").is_ok();
+ let target = env::var("TARGET").unwrap();
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
println!(
@@ -82,6 +83,12 @@ fn main() {
}
println!("cargo:rustc-cfg=libc_const_extern_fn");
}
+
+ // For unknown reason, libiconv can't be linked by adding #[link(name = iconv)] to
+ // a macOS-specific struct, so we do the linking here.
+ if target.contains("-apple-") {
+ println!("cargo:rustc-link-lib=iconv");
+ }
}
fn rustc_minor_nightly() -> Option<(u32, bool)> {
diff --git a/libc-test/build.rs b/libc-test/build.rs
index 01a34a6770..1519c012a5 100755
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -107,6 +107,7 @@ fn test_apple(target: &str) {
"fcntl.h",
"glob.h",
"grp.h",
+ "iconv.h",
"ifaddrs.h",
"langinfo.h",
"limits.h",
@@ -360,6 +361,7 @@ fn test_openbsd(target: &str) {
"pthread_np.h",
"sys/syscall.h",
"sys/shm.h",
+ "iconv.h",
}
cfg.skip_struct(move |ty| {
@@ -558,6 +560,7 @@ fn test_redox(target: &str) {
"errno.h",
"fcntl.h",
"grp.h",
+ "iconv.h",
"limits.h",
"locale.h",
"netdb.h",
@@ -618,6 +621,7 @@ fn test_solarish(target: &str) {
"fcntl.h",
"glob.h",
"grp.h",
+ "iconv.h",
"ifaddrs.h",
"langinfo.h",
"limits.h",
@@ -893,6 +897,7 @@ fn test_netbsd(target: &str) {
"sys/event.h",
"sys/quota.h",
"sys/shm.h",
+ "iconv.h",
}
cfg.type_name(move |ty, is_struct, is_union| {
@@ -1100,6 +1105,7 @@ fn test_dragonflybsd(target: &str) {
"utime.h",
"utmpx.h",
"wchar.h",
+ "iconv.h",
}
cfg.type_name(move |ty, is_struct, is_union| {
@@ -1329,6 +1335,7 @@ fn test_android(target: &str) {
"errno.h",
"fcntl.h",
"grp.h",
+ "iconv.h",
"ifaddrs.h",
"limits.h",
"locale.h",
@@ -1381,8 +1388,8 @@ fn test_android(target: &str) {
"sys/syscall.h",
"sys/sysinfo.h",
"sys/time.h",
- "sys/times.h",
"sys/timerfd.h",
+ "sys/times.h",
"sys/types.h",
"sys/ucontext.h",
"sys/uio.h",
@@ -1609,6 +1616,7 @@ fn test_freebsd(target: &str) {
"fcntl.h",
"glob.h",
"grp.h",
+ "iconv.h",
"ifaddrs.h",
"langinfo.h",
"libutil.h",
@@ -1915,6 +1923,7 @@ fn test_emscripten(target: &str) {
"fcntl.h",
"glob.h",
"grp.h",
+ "iconv.h",
"ifaddrs.h",
"langinfo.h",
"limits.h",
@@ -2279,6 +2288,7 @@ fn test_linux(target: &str) {
"fcntl.h",
"glob.h",
"grp.h",
+ "iconv.h",
"ifaddrs.h",
"langinfo.h",
"limits.h",
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index 6b52065ac5..7f321eab46 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -37,6 +37,8 @@ pub type sae_connid_t = u32;
pub type mach_port_t = ::c_uint;
+pub type iconv_t = *mut ::c_void;
+
deprecated_mach! {
pub type vm_prot_t = ::c_int;
pub type vm_size_t = ::uintptr_t;
@@ -3764,6 +3766,19 @@ extern "C" {
bufsize: ::c_int,
flags: ::c_int,
) -> ::c_int;
+
+ pub fn iconv_open(
+ tocode: *const ::c_char,
+ fromcode: *const ::c_char,
+ ) -> iconv_t;
+ pub fn iconv(
+ cd: iconv_t,
+ inbuf: *mut *mut ::c_char,
+ inbytesleft: *mut ::size_t,
+ outbuf: *mut *mut ::c_char,
+ outbytesleft: *mut ::size_t,
+ ) -> ::size_t;
+ pub fn iconv_close(cd: iconv_t) -> ::c_int;
}
cfg_if! {
diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs
index d126391f31..972a0471a7 100644
--- a/src/unix/bsd/freebsdlike/mod.rs
+++ b/src/unix/bsd/freebsdlike/mod.rs
@@ -32,6 +32,8 @@ pub type Elf64_Sxword = i64;
pub type Elf64_Word = u32;
pub type Elf64_Xword = u64;
+pub type iconv_t = *mut ::c_void;
+
cfg_if! {
if #[cfg(target_pointer_width = "64")] {
type Elf_Addr = Elf64_Addr;
@@ -1593,6 +1595,19 @@ extern "C" {
>,
data: *mut ::c_void,
) -> ::c_int;
+
+ pub fn iconv_open(
+ tocode: *const ::c_char,
+ fromcode: *const ::c_char,
+ ) -> iconv_t;
+ pub fn iconv(
+ cd: iconv_t,
+ inbuf: *mut *mut ::c_char,
+ inbytesleft: *mut ::size_t,
+ outbuf: *mut *mut ::c_char,
+ outbytesleft: *mut ::size_t,
+ ) -> ::size_t;
+ pub fn iconv_close(cd: iconv_t) -> ::c_int;
}
#[link(name = "rt")]
diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs
index 4b7dbafc14..7833138798 100644
--- a/src/unix/bsd/netbsdlike/netbsd/mod.rs
+++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs
@@ -29,6 +29,8 @@ pub type Elf64_Sxword = i64;
pub type Elf64_Word = u32;
pub type Elf64_Xword = u64;
+pub type iconv_t = *mut ::c_void;
+
cfg_if! {
if #[cfg(target_pointer_width = "64")] {
type Elf_Addr = Elf64_Addr;
@@ -2081,6 +2083,19 @@ extern "C" {
>,
data: *mut ::c_void,
) -> ::c_int;
+
+ pub fn iconv_open(
+ tocode: *const ::c_char,
+ fromcode: *const ::c_char,
+ ) -> iconv_t;
+ pub fn iconv(
+ cd: iconv_t,
+ inbuf: *mut *mut ::c_char,
+ inbytesleft: *mut ::size_t,
+ outbuf: *mut *mut ::c_char,
+ outbytesleft: *mut ::size_t,
+ ) -> ::size_t;
+ pub fn iconv_close(cd: iconv_t) -> ::c_int;
}
#[link(name = "util")]
diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs
index 60f78dfed2..886b8f05ad 100644
--- a/src/unix/linux_like/linux/mod.rs
+++ b/src/unix/linux_like/linux/mod.rs
@@ -40,6 +40,8 @@ pub type Elf64_Section = u16;
pub type canid_t = u32;
pub type can_err_mask_t = u32;
+pub type iconv_t = *mut ::c_void;
+
#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum fpos64_t {} // FIXME: fill this out with a struct
impl ::Copy for fpos64_t {}
@@ -3576,6 +3578,19 @@ extern "C" {
) -> ::size_t;
pub fn regfree(preg: *mut ::regex_t);
+
+ pub fn iconv_open(
+ tocode: *const ::c_char,
+ fromcode: *const ::c_char,
+ ) -> iconv_t;
+ pub fn iconv(
+ cd: iconv_t,
+ inbuf: *mut *mut ::c_char,
+ inbytesleft: *mut ::size_t,
+ outbuf: *mut *mut ::c_char,
+ outbytesleft: *mut ::size_t,
+ ) -> ::size_t;
+ pub fn iconv_close(cd: iconv_t) -> ::c_int;
}
cfg_if! {