-
Notifications
You must be signed in to change notification settings - Fork 13.8k
std: implement hostname
#146937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std: implement hostname
#146937
Conversation
rustbot has assigned @Mark-Simulacrum. Use |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with nit fixed
} | ||
} | ||
// As `buf.capacity()` is always positive (as Rust allocations cannot | ||
// be larger than `isize::MAX` bytes), the only way `EINVAL` can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buf.capacity()
is a usize
, so saying it's "always positive" feels confusing to me. I'm not sure what relevance isize
has here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gethostname
documents that EINVAL
is returned if size
is negative (even though it is an unsigned integer). I've changed the comment to mention only isize::MAX
.
I've rephrased the comment and also changed the Windows version to use |
@bors r+ |
std: implement `hostname` Resolves rust-lang/libs-team#330 Tracking issue: rust-lang#135142 This is based on rust-lang#135141, but I've reimplemented the UNIX version, which now: * uses `sysconf(_SC_HOST_NAME_MAX)` as an initial buffer length * returns `OutOfMemory` if the `Vec` allocation fails * retries the operation if it detects that the name returned by `gethostname` was truncated Additionally, as part of the rebase, I had to move some WinSock abstractions (initialisation and error access) to `sys::pal` so that they can be accessed from `sys::net::hostname`. CC `@orowith2os` (and thank you for your work!)
Rollup of 6 pull requests Successful merges: - #143613 (Fix backtraces with `-C panic=abort` on linux; emit unwind tables by default) - #146937 (std: implement `hostname`) - #147040 (mbe: macro_check: Fix function comments referencing non-existent parameters) - #147131 (Use MirPatch in simplify_branches.) - #147133 (Remove one loop in `extract_cfg_from_attrs`) - #147150 (Emit allocator attributes for allocator shim) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - #146937 (std: implement `hostname`) - #147040 (mbe: macro_check: Fix function comments referencing non-existent parameters) - #147131 (Use MirPatch in simplify_branches.) - #147133 (Remove one loop in `extract_cfg_from_attrs`) - #147150 (Emit allocator attributes for allocator shim) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146937 - joboet:gethostname, r=Mark-Simulacrum std: implement `hostname` Resolves rust-lang/libs-team#330 Tracking issue: #135142 This is based on #135141, but I've reimplemented the UNIX version, which now: * uses `sysconf(_SC_HOST_NAME_MAX)` as an initial buffer length * returns `OutOfMemory` if the `Vec` allocation fails * retries the operation if it detects that the name returned by `gethostname` was truncated Additionally, as part of the rebase, I had to move some WinSock abstractions (initialisation and error access) to `sys::pal` so that they can be accessed from `sys::net::hostname`. CC ``@orowith2os`` (and thank you for your work!)
…boet Fix broken STD build for ESP-IDF PRs rust-lang#147162 and rust-lang#146937 did [broke](https://github.com/esp-rs/esp-idf-sys/actions/runs/18151791720/job/51663969786) the STD build for `target_os = "espidf"` because that target [does not have neither a `gethostname`, not a `libc::_SC_HOST_NAME_MAX` by default](espressif/esp-idf#14849). While there is a [3rd party component for this syscall](https://components.espressif.com/components/espressif/sock_utils/versions/0.2.2/readme) in the ESP-IDF component registry, I don't think we should use it, because it does not come with ESP-IDF by default. Therefore, the one-liner fix just re-routes ESP-IDF into the `unsupported` branch.
Resolves rust-lang/libs-team#330
Tracking issue: #135142
This is based on #135141, but I've reimplemented the UNIX version, which now:
sysconf(_SC_HOST_NAME_MAX)
as an initial buffer lengthOutOfMemory
if theVec
allocation failsgethostname
was truncatedAdditionally, as part of the rebase, I had to move some WinSock abstractions (initialisation and error access) to
sys::pal
so that they can be accessed fromsys::net::hostname
.CC @orowith2os (and thank you for your work!)