Skip to content

Commit

Permalink
Raise MSRV to 1.69.0 (#2144)
Browse files Browse the repository at this point in the history
* Raise MSRV to 1.69.0

This allows us to use the very useful CStr::from_bytes_until_nul

* Respond to review comments

* Switch the name of the Fuchsia CI target

x86_64-fuchsia -> x86_64-unknown-fuchsia
  • Loading branch information
asomers committed Oct 2, 2023
1 parent 591e2ed commit 2f4861f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
12 changes: 6 additions & 6 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
TOOL: cargo
MSRV: 1.65.0
MSRV: 1.69.0
ZFLAGS:

# Tests that don't require executing the build binaries
Expand Down Expand Up @@ -146,7 +146,7 @@ task:
matrix:
- name: Linux aarch64
arm_container:
image: rust:1.65.0
image: rust:1.69.0
cpu: 1
depends_on:
- FreeBSD 14 amd64 & i686
Expand All @@ -160,13 +160,13 @@ task:
TARGET: aarch64-unknown-linux-gnu
- name: Linux x86_64
container:
image: rust:1.65.0
image: rust:1.69.0
cpu: 1
env:
TARGET: x86_64-unknown-linux-gnu
- name: Linux x86_64 musl
container:
image: rust:1.65.0
image: rust:1.69.0
cpu: 1
depends_on:
- FreeBSD 14 amd64 & i686
Expand Down Expand Up @@ -199,7 +199,7 @@ task:
# Tasks for cross-compiling, but no testing
task:
container:
image: rust:1.65.0
image: rust:1.69.0
cpu: 1
depends_on:
- FreeBSD 14 amd64 & i686
Expand Down Expand Up @@ -235,7 +235,7 @@ task:
TARGET: arm-unknown-linux-musleabi
- name: Fuchsia x86_64
env:
TARGET: x86_64-fuchsia
TARGET: x86_64-unknown-fuchsia
- name: Illumos
env:
TARGET: x86_64-unknown-illumos
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Changed

- The MSRV is now 1.69
([#2144](https://github.com/nix-rust/nix/pull/2144))

- The following APIs now take an implementation of `AsFd` rather than a
`RawFd`:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The following targets are supported by `nix`:

## Minimum Supported Rust Version (MSRV)

nix is supported on Rust 1.65 and higher. Its MSRV will not be
nix is supported on Rust 1.69 and higher. Its MSRV will not be
changed in the future without bumping the major or minor version.

## Contributing
Expand Down
11 changes: 4 additions & 7 deletions src/mount/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,10 @@ impl<'a> Nmount<'a> {
match Errno::result(res) {
Ok(_) => Ok(()),
Err(error) => {
let errmsg = match errmsg.iter().position(|&x| x == 0) {
None => None,
Some(0) => None,
Some(n) => {
let sl = &errmsg[0..n + 1];
Some(CStr::from_bytes_with_nul(sl).unwrap())
}
let errmsg = if errmsg[0] == 0 {
None
} else {
CStr::from_bytes_until_nul(&errmsg[..]).ok()
};
Err(NmountError::new(error, errmsg))
}
Expand Down
9 changes: 5 additions & 4 deletions src/sys/prctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ pub fn get_name() -> Result<CString> {

let res = unsafe { libc::prctl(libc::PR_GET_NAME, &buf, 0, 0, 0) };

let len = buf.iter().position(|&c| c == 0).unwrap_or(buf.len());
let name = CStr::from_bytes_with_nul(&buf[..=len]).map_err(|_| Errno::EINVAL)?;

Errno::result(res).map(|_| name.to_owned())
Errno::result(res).and_then(|_| {
CStr::from_bytes_until_nul(&buf)
.map(CStr::to_owned)
.map_err(|_| Errno::EINVAL)
})
}

/// Sets the timer slack value for the calling thread. Timer slack is used by the kernel to group
Expand Down
17 changes: 7 additions & 10 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ use libc::{
uid_t, PATH_MAX,
};
use std::convert::Infallible;
use std::ffi::{CStr, OsString};
#[cfg(not(target_os = "redox"))]
use std::ffi::{CString, OsStr};
#[cfg(not(target_os = "redox"))]
use std::os::unix::ffi::OsStrExt;
use std::os::unix::ffi::OsStringExt;
use std::os::unix::io::RawFd;
use std::os::unix::io::{AsFd, AsRawFd, OwnedFd};
use std::ffi::CString;
use std::ffi::{CStr, OsStr, OsString};
use std::os::unix::ffi::{OsStrExt, OsStringExt};
use std::os::unix::io::{AsFd, AsRawFd, OwnedFd, RawFd};
use std::path::PathBuf;
use std::{fmt, mem, ptr};

Expand Down Expand Up @@ -3928,9 +3925,9 @@ pub fn ttyname<F: AsFd>(fd: F) -> Result<PathBuf> {
return Err(Errno::from_i32(ret));
}

let nul = buf.iter().position(|c| *c == b'\0').unwrap();
buf.truncate(nul);
Ok(OsString::from_vec(buf).into())
CStr::from_bytes_until_nul(&buf[..])
.map(|s| OsStr::from_bytes(s.to_bytes()).into())
.map_err(|_| Errno::EINVAL)
}
}

Expand Down

0 comments on commit 2f4861f

Please sign in to comment.