Skip to content

Commit e6c1d7f

Browse files
committed
unistd: add docs for gethostname and tweak API
Although the underlying C API does take a pointer to a set of characters, it is a requirement of almost every operating system that these bytes not contain a premature NUL character or other special characters. In other words, you want a `&str`. Changing this to make the API make a bit more sense. Signed-off-by: Paul Osborne <osbpau@gmail.com>
1 parent 2f220fc commit e6c1d7f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3434
accessible with the new method `events()` of `EpollEvent`. Instances of
3535
`EpollEvent` can be constructed using the new method `new()` of EpollEvent.
3636
([#410](https://github.com/nix-rust/nix/pull/410))
37+
- `sethostname` now takes a `&str` instead of a `&[u8]` as this provides an API
38+
that makes more sense in normal, correct usage of the API.
3739

3840
### Fixed
3941
- Fixed using kqueue with `EVFILT_USER` on FreeBSD

src/unistd.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,14 @@ pub fn daemon(nochdir: bool, noclose: bool) -> Result<()> {
450450
Errno::result(res).map(drop)
451451
}
452452

453-
pub fn sethostname(name: &[u8]) -> Result<()> {
453+
/// Set the system host name (see
454+
/// [gethostname(2)](http://man7.org/linux/man-pages/man2/gethostname.2.html)).
455+
///
456+
/// Given a name, attempt to update the system host name to the given string.
457+
/// On some systems, the host name is limited to as few as 64 bytes. An error
458+
/// will be return if the name is not valid or the current process does not have
459+
/// permissions to update the host name.
460+
pub fn sethostname(name: &str) -> Result<()> {
454461
// Handle some differences in type of the len arg across platforms.
455462
cfg_if! {
456463
if #[cfg(any(target_os = "dragonfly",

0 commit comments

Comments
 (0)