Skip to content

Commit

Permalink
fix PATH_MAX with feature=term
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Mar 9, 2023
1 parent ebec3e1 commit c30a4ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ libc_bitflags!(
}
);

feature! {
#![feature = "fs"]

#[cfg(unix)]
pub const PATH_MAX: usize = libc::PATH_MAX as usize;

#[cfg(target_os = "wasi")]
pub const PATH_MAX: usize = 4096; // max is whatever the host system is... so guess posix?

feature! {
#![feature = "fs"]

// The conversion is not identical on all operating systems.
#[allow(clippy::useless_conversion)]
pub fn open<P: ?Sized + NixPath>(
Expand Down Expand Up @@ -318,7 +318,7 @@ fn inner_readlink<P: ?Sized + NixPath>(
dirfd: Option<RawFd>,
path: &P,
) -> Result<OsString> {
let mut v = Vec::with_capacity(PATH_MAX as usize);
let mut v = Vec::with_capacity(PATH_MAX);

{
// simple case: result is strictly less than `PATH_MAX`
Expand Down Expand Up @@ -371,7 +371,7 @@ fn inner_readlink<P: ?Sized + NixPath>(
} else {
// If lstat doesn't cooperate, or reports an error, be a little less
// precise.
(PATH_MAX as usize).max(128) << 1
PATH_MAX.max(128) << 1
}
};

Expand Down
5 changes: 3 additions & 2 deletions src/unistd.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Safe wrappers around functions found in libc "unistd.h" header
use crate::errno::{self, Errno};
#[cfg(any(feature = "fs", feature = "term"))]
use crate::fcntl::PATH_MAX;
#[cfg(not(target_os = "redox"))]
#[cfg(feature = "fs")]
use crate::fcntl::{at_rawfd, AtFlags};
#[cfg(not(target_os = "wasi"))]
#[cfg(feature = "fs")]
use crate::fcntl::{fcntl, FcntlArg::F_SETFD};
use crate::fcntl::{fcntl, FcntlArg::F_SETFD, FdFlag, OFlag};
#[cfg(feature = "fs")]
use crate::fcntl::{FdFlag, OFlag, PATH_MAX};
#[cfg(all(
feature = "fs",
any(
Expand Down

0 comments on commit c30a4ec

Please sign in to comment.