Skip to content

unix: add HOST_NAME_MAX - #5531

Open
Yasser-Ameur wants to merge 2 commits into
rust-lang:mainfrom
Yasser-Ameur:fix/host-name-max
Open

Yasser-Ameur wants to merge 2 commits into
rust-lang:mainfrom
Yasser-Ameur:fix/host-name-max

Conversation

@Yasser-Ameur

@Yasser-Ameur Yasser-Ameur commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Adds HOST_NAME_MAX where the platform's own limits header defines it: 64 for glibc and uclibc-ng, 255 for musl, Android, OpenBSD, Haiku, Redox, Emscripten, WASI and Cygwin. Not added for FreeBSD, NetBSD, DragonFly, Apple, illumos and Hurd, whose headers leave it undefined on purpose (sysconf only). Header sources for each value are in the commit message.

ctest passes for x86_64-unknown-linux-gnu and x86_64-unknown-linux-musl, with the constant present in the generated test source for both.

Closes #5511

POSIX requires HOST_NAME_MAX in <limits.h> for use with gethostname, and it
was missing everywhere except Fuchsia. Added it per family, glibc and uclibc
at 64 and the musl-derived and BSD-ish libcs at 255, skipping FreeBSD, NetBSD,
DragonFly, Apple, Solaris/illumos and Hurd, which deliberately leave it
undefined for sysconf instead.

glibc 64: https://github.com/bminor/glibc/blob/04e750e75b73957cf1c791535a3f4319534a52fc/sysdeps/unix/sysv/linux/bits/local_lim.h#L93
uclibc-ng 64: https://github.com/kraj/uclibc-ng/blob/f6f9f40cb17ae95610c4fe36f6ee77cfbcf05df1/libc/sysdeps/linux/common/bits/local_lim.h#L93
musl 255: https://git.musl-libc.org/cgit/musl/tree/include/limits.h?id=5e9972eaef08ccf55dabe254ac829a30329793d3#n56
android bionic 255: https://github.com/aosp-mirror/platform_bionic/blob/731631f300090436d7f5df80d50b6275c8c60a93/libc/include/bits/posix_limits.h#L135
openbsd 255: https://github.com/openbsd/src/blob/78e3ccc2aa1724882faaab7fa2366e535f039976/sys/sys/syslimits.h#L76
haiku 255: https://github.com/haiku/haiku/blob/89141b6857474342330f6205850b59435165187b/headers/posix/limits.h#L35
redox 255: https://github.com/redox-os/relibc/blob/381772ec81fced6d055f0f0ba6fa92c7f3256fbb/src/header/limits/mod.rs#L145
emscripten 255: https://github.com/emscripten-core/emscripten/blob/06e8b0d84d8b409b1b5ee59832948877bda6137e/system/lib/libc/musl/include/limits.h#L63
wasi 255: https://github.com/WebAssembly/wasi-libc/blob/06513b9ae0c1b14ca3010924939c007ed27628a1/libc-top-half/musl/include/limits.h#L56
cygwin 255: https://github.com/cygwin/cygwin/blob/00208dc31e790b8c130f32c4a0528c781fc07328/winsup/cygwin/include/cygwin/limits.h#L22
@rustbot

rustbot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in an OpenBSD module

cc @semarie

Some changes occurred in a NetBSD-like module

cc @semarie

Some changes occurred in an Android module

cc @maurer

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants lgtm, just some cleanup requests

View changes since this review

Comment on lines 1220 to 1227
pub const _SC_GETGR_R_SIZE_MAX: c_int = 100;
pub const _SC_GETPW_R_SIZE_MAX: c_int = 101;
pub const _SC_LOGIN_NAME_MAX: c_int = 102;
/// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines)
/// for details.
pub const HOST_NAME_MAX: c_int = 255;
pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 103;
pub const _SC_TRACE_NAME_MAX: c_int = 104;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to either side of the existing _SC group

Comment thread src/wasi/mod.rs
Comment on lines 525 to 529
pub const _SC_HOST_NAME_MAX: c_int = 180;
/// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines)
/// for details.
pub const HOST_NAME_MAX: c_int = 255;
pub const _SC_TRACE: c_int = 181;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Comment thread src/unix/redox/mod.rs Outdated
Comment on lines +448 to +449
/// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines)
/// for details.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can drop these comments, this isn't quite as volatile as other _MAX constants that change every time we get a new one

Comment thread libc-test/semver/linux-gnu.txt Outdated
GLOB_TILDE
GLOB_TILDE_CHECK
HOSTFS_SUPER_MAGIC
HOST_NAME_MAX

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in linux.txt rather than linux-gnu and linux-musl since it's present on all environments

@rustbot

rustbot commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

…emver entry

Review cleanups: the OpenBSD and WASI constants sit after their _SC groups
instead of inside them, the volatility comments are dropped since this value
does not change between releases, and the semver entry lives in linux.txt
rather than in both linux-gnu.txt and linux-musl.txt.
@Yasser-Ameur

Copy link
Copy Markdown
Contributor Author

Done: OpenBSD and WASI moved after their _SC groups, the comments dropped everywhere, and the semver entry moved to linux.txt.

@rustbot ready

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squash please then LGTM

View changes since this review

@tgross35

Copy link
Copy Markdown
Member

@rustbot author for squash

@rustbot rustbot added S-waiting-on-author stable-nominated This PR should be considered for cherry-pick to libc's stable release branch and removed S-waiting-on-review labels Sep 17, 2026

@xtqqczze xtqqczze left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked the source links, LGTM

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing HOST_NAME_MAX constant

4 participants