Skip to content

Commit

Permalink
Add htonl, htons, ntohl, ntohs
Browse files Browse the repository at this point in the history
  • Loading branch information
Askar Safin committed Apr 30, 2024
1 parent 2fd2b60 commit 1feb354
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libc-test/semver/unix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ grantpt
group
hostent
hstrerror
htonl
htons
if_indextoname
if_nametoindex
in6_addr
Expand Down Expand Up @@ -651,6 +653,8 @@ munmap
nanosleep
nfds_t
nlink_t
ntohl
ntohs
off_t
open
opendir
Expand Down
17 changes: 17 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,23 @@ extern "C" {

}

safe_f! {
// It seems htonl, etc are macros on macOS. So we have to reimplement them. So let's
// reimplement them for all UNIX platforms
pub {const} fn htonl(hostlong: u32) -> u32 {
u32::to_be(hostlong)
}
pub {const} fn htons(hostshort: u16) -> u16 {
u16::to_be(hostshort)
}
pub {const} fn ntohl(netlong: u32) -> u32 {
u32::from_be(netlong)
}
pub {const} fn ntohs(netshort: u16) -> u16 {
u16::from_be(netshort)
}
}

cfg_if! {
if #[cfg(not(any(target_os = "emscripten",
target_os = "android",
Expand Down

0 comments on commit 1feb354

Please sign in to comment.