about summary refs log tree commit diff
path: root/library/std/src/os/fd
AgeCommit message (Collapse)AuthorLines
2025-01-14remove unnecessary rustc_allowed_through_unstable_modulesRalf Jung-5/+0
2025-01-09Update a bunch of library types for MCP807Scott McMurray-20/+14
This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3: ``` library/core\src\ptr\non_null.rs 68:#[rustc_layout_scalar_valid_range_start(1)] library/core\src\num\niche_types.rs 19: #[rustc_layout_scalar_valid_range_start($low)] 20: #[rustc_layout_scalar_valid_range_end($high)] ``` Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.
2024-12-15Auto merge of #133223 - zachs18:uniquerc-impls, r=Noratriebbors-0/+16
`UniqueRc` trait impls UniqueRc tracking Issue: #112566 Stable traits: (i.e. impls behind only the `unique_rc_arc` feature gate) * Support the same formatting as `Rc`: * `fmt::Debug` and `fmt::Display` delegate to the pointee. * `fmt::Pointer` prints the address of the pointee. * Add explicit `!Send` and `!Sync` impls, to mirror `Rc`. * Borrowing traits: `Borrow`, `BorrowMut`, `AsRef`, `AsMut` * `Rc` does not implement `BorrowMut` and `AsMut`, but `UniqueRc` can. * Unconditional `Unpin`, like other heap-allocated types. * Comparison traits `(Partial)Ord` and `(Partial)Eq` delegate to the pointees. * `PartialEq for UniqueRc` does not do `Rc`'s specialization shortcut for pointer equality when `T: Eq`, since by definition two `UniqueRc`s cannot share an allocation. * `Hash` delegates to the pointee. * `AsRawFd`, `AsFd`, `AsHandle`, `AsSocket` delegate to the pointee like `Rc`. * Sidenote: The bounds on `T` for the existing `Pointer<T>` impls for specifically `AsRawFd` and `AsSocket` do not allow `T: ?Sized`. For the added `UniqueRc` impls I allowed `T: ?Sized` for all four traits, but I did not change the existing (stable) impls. Unstable traits: * `DispatchFromDyn`, allows using `UniqueRc<Self>` as a method receiver under `feature(arbitrary_self_types)`. * Existing `PinCoerceUnsized for UniqueRc` is generalized to allow non-`Global` allocators, like `Rc`. * `DerefPure`, allows using `UniqueRc` in deref-patterns under `feature(deref_patterns)`, like `Rc`. For documentation, `Rc` only has documentation on the comparison traits' methods, so I copied/adapted the documentation for those, and left the rest without impl-specific docs. ~~Edit: Marked as draft while I figure out `UnwindSafe`.~~ Edit: Ignoring `UnwindSafe` for this PR
2024-11-22library: update comment around close()Ralf Jung-10/+11
2024-11-19UniqueRc: platform-specific AsFd/Handle/etc impls to mirror RcZachary S-0/+16
2024-08-03Rollup merge of #127586 - zachs18:more-must-use, r=cuviperMatthias Krüger-0/+1
Add `#[must_use]` to some `into_raw*` functions. cc #121287 r? ``@cuviper`` Adds `#[must_use = "losing the pointer will leak memory"]`[^1] to `Box::into_raw(_with_allocator)`, `Vec::into_raw_parts(_with_alloc)`, `String::into_raw_parts`[^2], and `rc::{Rc, Weak}::into_raw_with_allocator` (Rc's normal `into_raw` and all of `Arc`'s `into_raw*`s are already `must_use`). Adds `#[must_use = "losing the raw <resource name may leak resources"]` to `IntoRawFd::into_raw_fd`, `IntoRawSocket::into_raw_socket`, and `IntoRawHandle::into_raw_handle`. [^1]: "*will* leak memory" may be too-strong wording (since `Box`/`Vec`/`String`/`rc::Weak` might not have a backing allocation), but I left it as-is for simplicity and consistency. [^2]: `String::into_raw_parts`'s `must_use` message is changed from the previous (possibly misleading) "`self` will be dropped if the result is not used".
2024-07-29Reformat `use` declarations.Nicholas Nethercote-7/+5
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-1/+1
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-24Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=AmanieuMatthias Krüger-4/+2
Replace some `mem::forget`'s with `ManuallyDrop` > but I would like to see a larger effort to replace all uses of `mem::forget`. _Originally posted by `@saethlin` in https://github.com/rust-lang/rust/issues/127584#issuecomment-2226087767_ So, r? `@saethlin` Sorry, I have finished writing all of this before I got your response.
2024-07-17Mention how you can go from `BorrowedFd` to `OwnedFd` and backTobias Bucher-0/+5
2024-07-17Make language around `ToOwned` for `BorrowedFd` more preciseTobias Bucher-3/+5
2024-07-15lib: replace some `mem::forget`'s with `ManuallyDrop`Pavel Grigorenko-4/+2
2024-07-10Add `must_use` to IntoRawFd/IntoRawSocket/IntoRawHandle's methods.Zachary S-0/+1
2024-07-07clarify `sys::unix::fd::FileDesc::drop` comment (#66876)Ashton Hunt-0/+5
2024-04-28put FD validity behind late debug_asserts checkingThe 8472-11/+3
uses the same machinery as assert_unsafe_precondition
2024-04-20Abort a process when FD ownership is violatedThe 8472-1/+14
When an EBADF happens then something else already touched an FD in ways it is not allowed to. At that point things can already be arbitrarily bad, e.g. clobbered mmaps. Recovery is not possible. All we can do is hasten the fire.
2024-04-11Factor some common `io::Error` constantsBenoît du Garreau-4/+1
2024-03-09Rollup merge of #114655 - nbdd0121:io-safety, r=dtolnayGuillaume Boisseau-5/+5
Make `impl<Fd: AsFd>` impl take `?Sized` `@rustbot` labels: +T-libs-api +needs-fcp
2024-02-04Document various I/O handle conversionsRyan Lowe-0/+6
2024-01-28Make `impl<Fd: AsFd>` impl take `?Sized`Gary Guo-5/+5
2023-10-17Updated libc and doc for Vita targetNikolay Arhipov-3/+3
2023-08-14typosRalf Jung-1/+1
2023-08-14sync the various FromRawFd trait docs, and remove 'valid'Ralf Jung-1/+1
2023-08-13add more explicit I/O safety documentationRalf Jung-5/+12
2023-04-28replace version placeholdersPietro Albini-1/+1
2023-04-10Stabilize IsTerminalJosh Triplett-1/+1
closes: https://github.com/rust-lang/rust/issues/98070
2023-04-02Fix typo in std/src/os/fd/owned.rsTaiki Endo-1/+1
2023-03-15Bump version placeholdersMark Rousskov-2/+2
2023-02-24avoid the usage of libc during the creation of documentationStefan Lankes-9/+7
2023-02-24remove code duplicationsStefan Lankes-9/+24
2023-01-26Implement `AsFd` and `AsRawFd` for `Rc`Ian Douglas Scott-0/+16
Fixes https://github.com/rust-lang/rust/issues/105931.
2023-01-15Rollup merge of #106867 - sunfishcode:sunfishcode/std-os-fd-stable-version, ↵Matthias Krüger-3/+3
r=m-ou-se Fix the stability attributes for `std::os::fd`. As `@bjorn3` pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized. [here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-14Fix the stability attributes for `std::os::fd`.Dan Gohman-3/+3
As @bjorn3 pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized. [here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-14Remove various double spaces in source comments.André Vennberg-1/+1
2022-10-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+17
The UNIX and WASI implementations use `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and their locked counterparts on all platforms. On UNIX and WASI, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on https://github.com/rust-lang/rust/pull/91121 Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-10Consolidate AsFd instances for stdio types into `library/std/src/os/fd/owned.rs`Josh Triplett-0/+52
2022-09-29Rollup merge of #98368 - sunfishcode:sunfishcode/std-os-fd, r=joshtriplettYuki Okushi-18/+19
Make `std::os::fd` public. `std::os::fd` defines types like `OwnedFd` and `RawFd` and is common between Unix and non-Unix platforms that share a basic file-descriptor concept. Rust currently uses this internally to simplify its own code, but it would be useful for external users in the same way, so make it public. This means that `OwnedFd` etc. will all appear in three places, for example on unix platforms: - `std::os::fd::OwnedFd` - `std::os::unix::io::OwnedFd` - `std::os::unix::prelude::OwnedFd` r? `````@joshtriplett`````
2022-09-04Don't duplicate file descriptors into stdio fdsbeetrees-1/+2
2022-09-02Fix compilation of the doc tests on Windows.Dan Gohman-0/+4
2022-08-29Re-introduce `unstable` attributes.Dan Gohman-2/+2
Add `#[unstable(feature = "os_fd", issue = "98699")]` to the new `pub use` declarations.
2022-08-29Clarify that the `fd` module is supported on Unix and WASI.Dan Gohman-3/+2
2022-08-29Make `std::os::fd` public.Dan Gohman-18/+16
`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common between Unix and non-Unix platforms that share a basic file-descriptor concept. Rust currently uses this internally to simplify its own code, but it would be useful for external users in the same way, so make it public. This means that `OwnedFd` etc. will all appear in three places, for example on unix platforms: - `std::os::fd::OwnedFd` - `std::os::unix::io::OwnedFd` - `std::os::unix::prelude::OwnedFd`
2022-08-12Adjust cfgsMark Rousskov-4/+4
2022-07-27Allow using stable os::fd::raw items through unstable os::wasi modulebstrie-0/+4
This fixes a regression from stable to nightly. Closes #99502.
2022-07-20Fix the stable version of `AsFd for Arc<T>` and `Box<T>`Josh Stone-2/+2
These merged in #97437 for 1.64.0, apart from the main `io_safety` feature that stabilized in 1.63.0.
2022-07-06Fix typo in file descriptor docsFlorian Spieß-1/+1
2022-06-21`impl<T: AsFd> AsFd for {Arc,Box}<T>`Joshua Nelson-3/+33
2022-06-21`impl<T: AsRawFd> for {Arc,Box}<T>`Joshua Nelson-0/+32
This allows implementing traits that require a raw FD on Arc and Box. Previously, you'd have to add the function to the trait itself: ```rust trait MyTrait { fn as_raw_fd(&self) -> RawFd; } impl<T: MyTrait> MyTrait for Arc<T> { fn as_raw_fd(&self) -> RawFd { (**self).as_raw_fd() } } ```
2022-06-15Revise the documentation for `try_clone`.Dan Gohman-2/+4
On Unix, describe these in terms of the underlying "file description". On Windows, describe them in terms of the underlying "object".
2022-06-15Add `BorrowedFd::try_clone_to_owned`.Dan Gohman-3/+12
And `BorrowedHandle::try_clone_to_owned` and `BorrowedSocket::try_clone_to_owned` on Windows.