From 1115f15e1cba09c60a9a1fe006941c562e91d348 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 17 Nov 2021 03:18:15 +0900 Subject: windows: Map `ERROR_INVALID_NAME` as `InvalidInput` --- library/std/src/sys/windows/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'library/std/src') diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index c70f254cf39..4ec9437700e 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -71,7 +71,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { c::ERROR_FILE_NOT_FOUND => return NotFound, c::ERROR_PATH_NOT_FOUND => return NotFound, c::ERROR_NO_DATA => return BrokenPipe, - c::ERROR_INVALID_PARAMETER => return InvalidInput, + c::ERROR_INVALID_PARAMETER | c::ERROR_INVALID_NAME => return InvalidInput, c::ERROR_NOT_ENOUGH_MEMORY | c::ERROR_OUTOFMEMORY => return OutOfMemory, c::ERROR_SEM_TIMEOUT | c::WAIT_TIMEOUT -- cgit 1.4.1-3-g733a5 From 755e475c8b518e4ad9ba79adead4ea8c8a268c22 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 31 Jan 2022 17:24:10 +0900 Subject: Rename `FilenameTooLong` to `FilenameInvalid` --- library/std/src/io/error.rs | 4 ++-- library/std/src/sys/unix/mod.rs | 2 +- library/std/src/sys/windows/mod.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'library/std/src') diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 4b55324a242..c55f3c19ab6 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -301,7 +301,7 @@ pub enum ErrorKind { /// The limit might be from the underlying filesystem or API, or an administratively imposed /// resource limit. #[unstable(feature = "io_error_more", issue = "86442")] - FilenameTooLong, + FilenameInvalid, /// Program argument list too long. /// /// When trying to run an external program, a system or process limit on the size of the @@ -382,7 +382,7 @@ impl ErrorKind { DirectoryNotEmpty => "directory not empty", ExecutableFileBusy => "executable file busy", FileTooLarge => "file too large", - FilenameTooLong => "filename too long", + FilenameInvalid => "filename too long", FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", FilesystemQuotaExceeded => "filesystem quota exceeded", HostUnreachable => "host unreachable", diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 6382354eb6e..863b6c7c5a7 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -159,7 +159,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::ENOSPC => StorageFull, libc::ENOSYS => Unsupported, libc::EMLINK => TooManyLinks, - libc::ENAMETOOLONG => FilenameTooLong, + libc::ENAMETOOLONG => FilenameInvalid, libc::ENETDOWN => NetworkDown, libc::ENETUNREACH => NetworkUnreachable, libc::ENOTCONN => NotConnected, diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 4ec9437700e..57a25a0f30a 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -104,7 +104,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { c::ERROR_POSSIBLE_DEADLOCK => return Deadlock, c::ERROR_NOT_SAME_DEVICE => return CrossesDevices, c::ERROR_TOO_MANY_LINKS => return TooManyLinks, - c::ERROR_FILENAME_EXCED_RANGE => return FilenameTooLong, + c::ERROR_FILENAME_EXCED_RANGE => return FilenameInvalid, _ => {} } -- cgit 1.4.1-3-g733a5 From cc9407924decf5212177769ff4740665047517d9 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 31 Jan 2022 17:28:05 +0900 Subject: Map `ERROR_INVALID_NAME` to `FilenameInvalid` --- library/std/src/sys/windows/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'library/std/src') diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 57a25a0f30a..6d97bf42f6f 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -71,7 +71,8 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { c::ERROR_FILE_NOT_FOUND => return NotFound, c::ERROR_PATH_NOT_FOUND => return NotFound, c::ERROR_NO_DATA => return BrokenPipe, - c::ERROR_INVALID_PARAMETER | c::ERROR_INVALID_NAME => return InvalidInput, + c::ERROR_INVALID_NAME => return FilenameInvalid, + c::ERROR_INVALID_PARAMETER => return InvalidInput, c::ERROR_NOT_ENOUGH_MEMORY | c::ERROR_OUTOFMEMORY => return OutOfMemory, c::ERROR_SEM_TIMEOUT | c::WAIT_TIMEOUT -- cgit 1.4.1-3-g733a5 From 861f3c70a27d007ed8113fe776aa393d8e25faa0 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 31 Jan 2022 09:17:34 -0800 Subject: Fix description of FilenameInvalid Co-authored-by: Mara Bos --- library/std/src/io/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'library/std/src') diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index c55f3c19ab6..90766d4acef 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -382,7 +382,7 @@ impl ErrorKind { DirectoryNotEmpty => "directory not empty", ExecutableFileBusy => "executable file busy", FileTooLarge => "file too large", - FilenameInvalid => "filename too long", + FilenameInvalid => "filename invalid", FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", FilesystemQuotaExceeded => "filesystem quota exceeded", HostUnreachable => "host unreachable", -- cgit 1.4.1-3-g733a5 From a898b31662aee14c9aaa46f39377724c7ae590b5 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 10 Feb 2022 23:49:27 +0900 Subject: Rename to `InvalidFilename` --- library/std/src/io/error.rs | 9 ++++----- library/std/src/io/error/repr_bitpacked.rs | 2 +- library/std/src/sys/unix/mod.rs | 2 +- library/std/src/sys/windows/mod.rs | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) (limited to 'library/std/src') diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 90766d4acef..1aa6d657889 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -296,12 +296,11 @@ pub enum ErrorKind { /// The filesystem does not support making so many hardlinks to the same file. #[unstable(feature = "io_error_more", issue = "86442")] TooManyLinks, - /// Filename too long. + /// A filename was invalid. /// - /// The limit might be from the underlying filesystem or API, or an administratively imposed - /// resource limit. + /// This error can also cause if it exceeded the filename length limit. #[unstable(feature = "io_error_more", issue = "86442")] - FilenameInvalid, + InvalidFilename, /// Program argument list too long. /// /// When trying to run an external program, a system or process limit on the size of the @@ -382,12 +381,12 @@ impl ErrorKind { DirectoryNotEmpty => "directory not empty", ExecutableFileBusy => "executable file busy", FileTooLarge => "file too large", - FilenameInvalid => "filename invalid", FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", FilesystemQuotaExceeded => "filesystem quota exceeded", HostUnreachable => "host unreachable", Interrupted => "operation interrupted", InvalidData => "invalid data", + InvalidFilename => "invalid filename", InvalidInput => "invalid input parameter", IsADirectory => "is a directory", NetworkDown => "network down", diff --git a/library/std/src/io/error/repr_bitpacked.rs b/library/std/src/io/error/repr_bitpacked.rs index f317368e8e5..4301e941b3d 100644 --- a/library/std/src/io/error/repr_bitpacked.rs +++ b/library/std/src/io/error/repr_bitpacked.rs @@ -315,7 +315,7 @@ fn kind_from_prim(ek: u32) -> Option { Deadlock, CrossesDevices, TooManyLinks, - FilenameTooLong, + InvalidFilename, ArgumentListTooLong, Interrupted, Other, diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 863b6c7c5a7..605cc499b3c 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -159,7 +159,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::ENOSPC => StorageFull, libc::ENOSYS => Unsupported, libc::EMLINK => TooManyLinks, - libc::ENAMETOOLONG => FilenameInvalid, + libc::ENAMETOOLONG => InvalidFilename, libc::ENETDOWN => NetworkDown, libc::ENETUNREACH => NetworkUnreachable, libc::ENOTCONN => NotConnected, diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 6d97bf42f6f..dc288176346 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -71,7 +71,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { c::ERROR_FILE_NOT_FOUND => return NotFound, c::ERROR_PATH_NOT_FOUND => return NotFound, c::ERROR_NO_DATA => return BrokenPipe, - c::ERROR_INVALID_NAME => return FilenameInvalid, + c::ERROR_INVALID_NAME => return InvalidFilename, c::ERROR_INVALID_PARAMETER => return InvalidInput, c::ERROR_NOT_ENOUGH_MEMORY | c::ERROR_OUTOFMEMORY => return OutOfMemory, c::ERROR_SEM_TIMEOUT @@ -105,7 +105,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { c::ERROR_POSSIBLE_DEADLOCK => return Deadlock, c::ERROR_NOT_SAME_DEVICE => return CrossesDevices, c::ERROR_TOO_MANY_LINKS => return TooManyLinks, - c::ERROR_FILENAME_EXCED_RANGE => return FilenameInvalid, + c::ERROR_FILENAME_EXCED_RANGE => return InvalidFilename, _ => {} } -- cgit 1.4.1-3-g733a5 From 1f98ef7793dde6c3a3c216d55ae5858da7e0c34e Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 10 Feb 2022 18:26:12 -0800 Subject: Implement `AsFd` for `&T` and `&mut T`. Add implementations of `AsFd` for `&T` and `&mut T`, so that users can write code like this: ```rust pub fn fchown(fd: F, uid: Option, gid: Option) -> io::Result<()> { ``` with `fd: F` rather than `fd: &F`. And similar for `AsHandle` and `AsSocket` on Windows. Also, adjust the `fchown` example to pass the file by reference. The code can work either way now, but passing by reference is more likely to be what users will want to do. This is an alternative to #93869, and is a simpler way to achieve the same goals: users don't need to pass borrowed-`BorrowedFd` arguments, and it prevents a pitfall in the case where users write `fd: F` instead of `fd: &F`. --- library/std/src/os/fd/owned.rs | 16 ++++++++++++++++ library/std/src/os/unix/fs.rs | 2 +- library/std/src/os/windows/io/handle.rs | 16 ++++++++++++++++ library/std/src/os/windows/io/socket.rs | 16 ++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) (limited to 'library/std/src') diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index b53c3e79b0f..71c660e7186 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -200,6 +200,22 @@ pub trait AsFd { fn as_fd(&self) -> BorrowedFd<'_>; } +#[unstable(feature = "io_safety", issue = "87074")] +impl AsFd for &T { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + T::as_fd(self) + } +} + +#[unstable(feature = "io_safety", issue = "87074")] +impl AsFd for &mut T { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + T::as_fd(self) + } +} + #[unstable(feature = "io_safety", issue = "87074")] impl AsFd for BorrowedFd<'_> { #[inline] diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs index db7edcd0574..75d65e6d5fc 100644 --- a/library/std/src/os/unix/fs.rs +++ b/library/std/src/os/unix/fs.rs @@ -966,7 +966,7 @@ pub fn chown>(dir: P, uid: Option, gid: Option) -> io:: /// /// fn main() -> std::io::Result<()> { /// let f = std::fs::File::open("/file")?; -/// fs::fchown(f, Some(0), Some(0))?; +/// fs::fchown(&f, Some(0), Some(0))?; /// Ok(()) /// } /// ``` diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index e37ce633a12..8df6c54a414 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -316,6 +316,22 @@ pub trait AsHandle { fn as_handle(&self) -> BorrowedHandle<'_>; } +#[unstable(feature = "io_safety", issue = "87074")] +impl AsHandle for &T { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + T::as_handle(self) + } +} + +#[unstable(feature = "io_safety", issue = "87074")] +impl AsHandle for &mut T { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + T::as_handle(self) + } +} + impl AsHandle for BorrowedHandle<'_> { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index d3a5b6dcc76..2f13eb77a1b 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -210,6 +210,22 @@ pub trait AsSocket { fn as_socket(&self) -> BorrowedSocket<'_>; } +#[unstable(feature = "io_safety", issue = "87074")] +impl AsSocket for &T { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + T::as_socket(self) + } +} + +#[unstable(feature = "io_safety", issue = "87074")] +impl AsSocket for &mut T { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + T::as_socket(self) + } +} + impl AsSocket for BorrowedSocket<'_> { #[inline] fn as_socket(&self) -> BorrowedSocket<'_> { -- cgit 1.4.1-3-g733a5 From 22a24c98d3429f9e98e4ce5d096f58620d753458 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 3 Feb 2022 23:19:36 +0100 Subject: Add missing platform-specific information on current_dir and set_current_dir --- library/std/src/env.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'library/std/src') diff --git a/library/std/src/env.rs b/library/std/src/env.rs index c06928647d3..5ed9fa9d6f0 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -23,6 +23,11 @@ use crate::sys::os as os_imp; /// Returns the current working directory as a [`PathBuf`]. /// +/// # Platform-specific behavior +/// +/// This function currently corresponds to the `getcwd` function on Unix +/// and the `GetCurrentDirectoryW` function on Windows. +/// /// # Errors /// /// Returns an [`Err`] if the current working directory value is invalid. @@ -49,6 +54,11 @@ pub fn current_dir() -> io::Result { /// Changes the current working directory to the specified path. /// +/// # Platform-specific behavior +/// +/// This function currently corresponds to the `chdir` function on Unix +/// and the `SetCurrentDirectoryW` function on Windows. +/// /// Returns an [`Err`] if the operation fails. /// /// # Examples -- cgit 1.4.1-3-g733a5