Skip to content

Commit 2a2196d

Browse files
committed
Auto merge of #2037 - Minoru:feature/iconv, r=Amanieu
Add bindings for iconv calls
2 parents 3c907ed + 3e4d684 commit 2a2196d

File tree

6 files changed

+78
-1
lines changed

6 files changed

+78
-1
lines changed

build.rs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn main() {
1010
let const_extern_fn_cargo_feature =
1111
env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
1212
let libc_ci = env::var("LIBC_CI").is_ok();
13+
let target = env::var("TARGET").unwrap();
1314

1415
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
1516
println!(
@@ -82,6 +83,12 @@ fn main() {
8283
}
8384
println!("cargo:rustc-cfg=libc_const_extern_fn");
8485
}
86+
87+
// For unknown reason, libiconv can't be linked by adding #[link(name = iconv)] to
88+
// a macOS-specific struct, so we do the linking here.
89+
if target.contains("-apple-") {
90+
println!("cargo:rustc-link-lib=iconv");
91+
}
8592
}
8693

8794
fn rustc_minor_nightly() -> Option<(u32, bool)> {

libc-test/build.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ fn test_apple(target: &str) {
107107
"fcntl.h",
108108
"glob.h",
109109
"grp.h",
110+
"iconv.h",
110111
"ifaddrs.h",
111112
"langinfo.h",
112113
"limits.h",
@@ -360,6 +361,7 @@ fn test_openbsd(target: &str) {
360361
"pthread_np.h",
361362
"sys/syscall.h",
362363
"sys/shm.h",
364+
"iconv.h",
363365
}
364366

365367
cfg.skip_struct(move |ty| {
@@ -558,6 +560,7 @@ fn test_redox(target: &str) {
558560
"errno.h",
559561
"fcntl.h",
560562
"grp.h",
563+
"iconv.h",
561564
"limits.h",
562565
"locale.h",
563566
"netdb.h",
@@ -618,6 +621,7 @@ fn test_solarish(target: &str) {
618621
"fcntl.h",
619622
"glob.h",
620623
"grp.h",
624+
"iconv.h",
621625
"ifaddrs.h",
622626
"langinfo.h",
623627
"limits.h",
@@ -893,6 +897,7 @@ fn test_netbsd(target: &str) {
893897
"sys/event.h",
894898
"sys/quota.h",
895899
"sys/shm.h",
900+
"iconv.h",
896901
}
897902

898903
cfg.type_name(move |ty, is_struct, is_union| {
@@ -1100,6 +1105,7 @@ fn test_dragonflybsd(target: &str) {
11001105
"utime.h",
11011106
"utmpx.h",
11021107
"wchar.h",
1108+
"iconv.h",
11031109
}
11041110

11051111
cfg.type_name(move |ty, is_struct, is_union| {
@@ -1329,6 +1335,7 @@ fn test_android(target: &str) {
13291335
"errno.h",
13301336
"fcntl.h",
13311337
"grp.h",
1338+
"iconv.h",
13321339
"ifaddrs.h",
13331340
"limits.h",
13341341
"locale.h",
@@ -1381,8 +1388,8 @@ fn test_android(target: &str) {
13811388
"sys/syscall.h",
13821389
"sys/sysinfo.h",
13831390
"sys/time.h",
1384-
"sys/times.h",
13851391
"sys/timerfd.h",
1392+
"sys/times.h",
13861393
"sys/types.h",
13871394
"sys/ucontext.h",
13881395
"sys/uio.h",
@@ -1609,6 +1616,7 @@ fn test_freebsd(target: &str) {
16091616
"fcntl.h",
16101617
"glob.h",
16111618
"grp.h",
1619+
"iconv.h",
16121620
"ifaddrs.h",
16131621
"langinfo.h",
16141622
"libutil.h",
@@ -1915,6 +1923,7 @@ fn test_emscripten(target: &str) {
19151923
"fcntl.h",
19161924
"glob.h",
19171925
"grp.h",
1926+
"iconv.h",
19181927
"ifaddrs.h",
19191928
"langinfo.h",
19201929
"limits.h",
@@ -2279,6 +2288,7 @@ fn test_linux(target: &str) {
22792288
"fcntl.h",
22802289
"glob.h",
22812290
"grp.h",
2291+
"iconv.h",
22822292
"ifaddrs.h",
22832293
"langinfo.h",
22842294
"limits.h",

src/unix/bsd/apple/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub type sae_connid_t = u32;
3737

3838
pub type mach_port_t = ::c_uint;
3939

40+
pub type iconv_t = *mut ::c_void;
41+
4042
deprecated_mach! {
4143
pub type vm_prot_t = ::c_int;
4244
pub type vm_size_t = ::uintptr_t;
@@ -3764,6 +3766,19 @@ extern "C" {
37643766
bufsize: ::c_int,
37653767
flags: ::c_int,
37663768
) -> ::c_int;
3769+
3770+
pub fn iconv_open(
3771+
tocode: *const ::c_char,
3772+
fromcode: *const ::c_char,
3773+
) -> iconv_t;
3774+
pub fn iconv(
3775+
cd: iconv_t,
3776+
inbuf: *mut *mut ::c_char,
3777+
inbytesleft: *mut ::size_t,
3778+
outbuf: *mut *mut ::c_char,
3779+
outbytesleft: *mut ::size_t,
3780+
) -> ::size_t;
3781+
pub fn iconv_close(cd: iconv_t) -> ::c_int;
37673782
}
37683783

37693784
cfg_if! {

src/unix/bsd/freebsdlike/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub type Elf64_Sxword = i64;
3232
pub type Elf64_Word = u32;
3333
pub type Elf64_Xword = u64;
3434

35+
pub type iconv_t = *mut ::c_void;
36+
3537
cfg_if! {
3638
if #[cfg(target_pointer_width = "64")] {
3739
type Elf_Addr = Elf64_Addr;
@@ -1593,6 +1595,19 @@ extern "C" {
15931595
>,
15941596
data: *mut ::c_void,
15951597
) -> ::c_int;
1598+
1599+
pub fn iconv_open(
1600+
tocode: *const ::c_char,
1601+
fromcode: *const ::c_char,
1602+
) -> iconv_t;
1603+
pub fn iconv(
1604+
cd: iconv_t,
1605+
inbuf: *mut *mut ::c_char,
1606+
inbytesleft: *mut ::size_t,
1607+
outbuf: *mut *mut ::c_char,
1608+
outbytesleft: *mut ::size_t,
1609+
) -> ::size_t;
1610+
pub fn iconv_close(cd: iconv_t) -> ::c_int;
15961611
}
15971612

15981613
#[link(name = "rt")]

src/unix/bsd/netbsdlike/netbsd/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub type Elf64_Sxword = i64;
2929
pub type Elf64_Word = u32;
3030
pub type Elf64_Xword = u64;
3131

32+
pub type iconv_t = *mut ::c_void;
33+
3234
cfg_if! {
3335
if #[cfg(target_pointer_width = "64")] {
3436
type Elf_Addr = Elf64_Addr;
@@ -2081,6 +2083,19 @@ extern "C" {
20812083
>,
20822084
data: *mut ::c_void,
20832085
) -> ::c_int;
2086+
2087+
pub fn iconv_open(
2088+
tocode: *const ::c_char,
2089+
fromcode: *const ::c_char,
2090+
) -> iconv_t;
2091+
pub fn iconv(
2092+
cd: iconv_t,
2093+
inbuf: *mut *mut ::c_char,
2094+
inbytesleft: *mut ::size_t,
2095+
outbuf: *mut *mut ::c_char,
2096+
outbytesleft: *mut ::size_t,
2097+
) -> ::size_t;
2098+
pub fn iconv_close(cd: iconv_t) -> ::c_int;
20842099
}
20852100

20862101
#[link(name = "util")]

src/unix/linux_like/linux/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pub type Elf64_Section = u16;
4040
pub type canid_t = u32;
4141
pub type can_err_mask_t = u32;
4242

43+
pub type iconv_t = *mut ::c_void;
44+
4345
#[cfg_attr(feature = "extra_traits", derive(Debug))]
4446
pub enum fpos64_t {} // FIXME: fill this out with a struct
4547
impl ::Copy for fpos64_t {}
@@ -3576,6 +3578,19 @@ extern "C" {
35763578
) -> ::size_t;
35773579

35783580
pub fn regfree(preg: *mut ::regex_t);
3581+
3582+
pub fn iconv_open(
3583+
tocode: *const ::c_char,
3584+
fromcode: *const ::c_char,
3585+
) -> iconv_t;
3586+
pub fn iconv(
3587+
cd: iconv_t,
3588+
inbuf: *mut *mut ::c_char,
3589+
inbytesleft: *mut ::size_t,
3590+
outbuf: *mut *mut ::c_char,
3591+
outbytesleft: *mut ::size_t,
3592+
) -> ::size_t;
3593+
pub fn iconv_close(cd: iconv_t) -> ::c_int;
35793594
}
35803595

35813596
cfg_if! {

0 commit comments

Comments
 (0)