diff --git a/cpp2rust/compat/arpa/inet.h b/cpp2rust/compat/arpa/inet.h index e1d7fc107d..a09ef1a745 100644 --- a/cpp2rust/compat/arpa/inet.h +++ b/cpp2rust/compat/arpa/inet.h @@ -8,10 +8,16 @@ #undef htonl #undef htons +#ifdef __cplusplus +extern "C" { +#endif uint32_t cpp2rust_ntohl(uint32_t x); uint16_t cpp2rust_ntohs(uint16_t x); uint32_t cpp2rust_htonl(uint32_t x); uint16_t cpp2rust_htons(uint16_t x); +#ifdef __cplusplus +} +#endif #define ntohl(x) cpp2rust_ntohl(x) #define ntohs(x) cpp2rust_ntohs(x) diff --git a/cpp2rust/compat/errno.h b/cpp2rust/compat/errno.h index d6b34c3040..f0f774a688 100644 --- a/cpp2rust/compat/errno.h +++ b/cpp2rust/compat/errno.h @@ -5,6 +5,12 @@ #undef errno +#ifdef __cplusplus +extern "C" { +#endif int *cpp2rust_errno(void); +#ifdef __cplusplus +} +#endif #define errno (*cpp2rust_errno()) diff --git a/cpp2rust/compat/sys/select.h b/cpp2rust/compat/sys/select.h index 2a15d77cd6..d651f8c31e 100644 --- a/cpp2rust/compat/sys/select.h +++ b/cpp2rust/compat/sys/select.h @@ -8,10 +8,16 @@ #undef FD_ISSET #undef FD_ZERO +#ifdef __cplusplus +extern "C" { +#endif void cpp2rust_fd_set(int fd, fd_set *set); void cpp2rust_fd_clr(int fd, fd_set *set); int cpp2rust_fd_isset(int fd, const fd_set *set); void cpp2rust_fd_zero(fd_set *set); +#ifdef __cplusplus +} +#endif #define FD_SET(fd, set) cpp2rust_fd_set(fd, set) #define FD_CLR(fd, set) cpp2rust_fd_clr(fd, set) diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 2ffa46a344..879e340278 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -208,6 +208,19 @@ fn main_0() -> i32 { ((sizes.as_pointer() as Ptr).to_end()).reinterpret_cast::(); assert!((((sizes_end).clone() - (sizes.as_pointer() as Ptr::)) as i64 == 4_i64)); assert!((((sizes_end.offset(-((1) as isize))).read()) == 4_usize)); + let set: Value = Rc::new(RefCell::new(Default::default())); + (set.as_pointer()).with_mut(|__s| __s.zero()); + (set.as_pointer()).with_mut(|__s| __s.set(3)); + assert!( + (if (set.as_pointer()).with(|__s| __s.isset(3)) { + 1 + } else { + 0 + } != 0) + ); + libcc2rs::cpp2rust_errno().write(42); + assert!(((libcc2rs::cpp2rust_errno().read()) == 42)); + assert!((u32::from_be(u32::to_be(7_u32)) == 7_u32)); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 6ac0235f76..60fbb85cf0 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -197,6 +197,13 @@ unsafe fn main_0() -> i32 { == (4_i64)) ); assert!(((*(sizes_end.offset(-((1) as isize)))) == (4_usize))); + let mut set: ::libc::fd_set = std::mem::zeroed::<::libc::fd_set>(); + libc::FD_ZERO((&mut set as *mut ::libc::fd_set)); + libc::FD_SET(3, (&mut set as *mut ::libc::fd_set)); + assert!((libc::FD_ISSET(3, (&mut set as *mut ::libc::fd_set).cast_const()) as i32 != 0)); + (*libcc2rs::cpp2rust_errno_unsafe()) = 42; + assert!(((*libcc2rs::cpp2rust_errno_unsafe()) == (42))); + assert!(((u32::from_be(u32::to_be(7_u32))) == (7_u32))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/size_t_ssize_t.cpp b/tests/unit/size_t_ssize_t.cpp index 9c46ed2947..f1606d8af4 100644 --- a/tests/unit/size_t_ssize_t.cpp +++ b/tests/unit/size_t_ssize_t.cpp @@ -1,8 +1,11 @@ #include +#include #include #include #include +#include #include +#include #include #include @@ -113,5 +116,15 @@ int main() { const size_t *sizes_end = std::end(sizes); assert(sizes_end - sizes == 4); assert(*(sizes_end - 1) == 4); + + fd_set set; + FD_ZERO(&set); + FD_SET(3, &set); + assert(FD_ISSET(3, &set)); + + errno = 42; + assert(errno == 42); + + assert(ntohl(htonl(7)) == 7); return 0; }