diff options
| author | Ralf Jung <post@ralfj.de> | 2022-10-21 10:18:54 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-10-21 10:18:54 +0200 |
| commit | 9b57a2f55a76fa1e3d000932e0a708adb587990c (patch) | |
| tree | 53c592b83ed6929eb66beb179586d09409fc3088 /library/std/src/sys_common/net.rs | |
| parent | 53e357748675b387b6d25fe563b960cb7a7a0aea (diff) | |
| parent | b1ab3b738ac718da74cd4aa0bb7f362d0adbdf84 (diff) | |
| download | rust-9b57a2f55a76fa1e3d000932e0a708adb587990c.tar.gz rust-9b57a2f55a76fa1e3d000932e0a708adb587990c.zip | |
merge rustc history
Diffstat (limited to 'library/std/src/sys_common/net.rs')
| -rw-r--r-- | library/std/src/sys_common/net.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 3ad802afa8f..fad4a63331b 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -2,12 +2,13 @@ mod tests; use crate::cmp; -use crate::ffi::CString; +use crate::convert::{TryFrom, TryInto}; use crate::fmt; use crate::io::{self, ErrorKind, IoSlice, IoSliceMut}; use crate::mem; use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; use crate::ptr; +use crate::sys::common::small_c_string::run_with_cstr; use crate::sys::net::netc as c; use crate::sys::net::{cvt, cvt_gai, cvt_r, init, wrlen_t, Socket}; use crate::sys_common::{AsInner, FromInner, IntoInner}; @@ -197,14 +198,15 @@ impl<'a> TryFrom<(&'a str, u16)> for LookupHost { fn try_from((host, port): (&'a str, u16)) -> io::Result<LookupHost> { init(); - let c_host = CString::new(host)?; - let mut hints: c::addrinfo = unsafe { mem::zeroed() }; - hints.ai_socktype = c::SOCK_STREAM; - let mut res = ptr::null_mut(); - unsafe { - cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), &hints, &mut res)) - .map(|_| LookupHost { original: res, cur: res, port }) - } + run_with_cstr(host.as_bytes(), |c_host| { + let mut hints: c::addrinfo = unsafe { mem::zeroed() }; + hints.ai_socktype = c::SOCK_STREAM; + let mut res = ptr::null_mut(); + unsafe { + cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), &hints, &mut res)) + .map(|_| LookupHost { original: res, cur: res, port }) + } + }) } } |
