about summary refs log tree commit diff
path: root/library/std/src/sys/fs/unix.rs
AgeCommit message (Collapse)AuthorLines
2025-09-14On FreeBSD, use readdir instead of readdir_rAlan Somers-57/+63
readdir_r has the same problems on FreeBSD as it does on other platforms: it assumes a fixed NAME_MAX. And readdir has the same thread-safety guarantee as it does on other platforms: it's safe as long as only one thread tries to read from the directory stream at a given time. Furthermore, readdir_r is likely to be removed for FreeBSD 16, so we should stop using it now.
2025-09-07feat(std): emulate flock for solaris via fcntlWeihang Lo-0/+66
Upstream Solaris flock emulation to libstd from cargo. This is borrowed from https://github.com/rust-lang/cargo/blob/3b379fcc541b39321a7758552d37e5e0cc4277b9/src/cargo/util/flock.rs#L502-L536 which was implemented by an Oracle employee. The code has been in cargo since 2022-12. Python's `fcntl.flock` emulates like this as well: https://github.com/python/cpython/blob/c919d02edecfe9d75fe374756fb8aa1db8d95f55/Modules/fcntlmodule.c#L337-L400 We did the same thing in https://github.com/rust-lang/rust/blob/0d0f4eac8b98133e5da6d3604d86a8f3b5a67844/compiler/rustc_data_structures/src/flock/unix.rs#L13-L39
2025-09-04Rollup merge of #140459 - niklasf:feature/read-buf-at, r=tgross35Stuart Cook-0/+4
Add `read_buf` equivalents for positioned reads Adds the following items under the ~~`read_buf` (rust-lang/rust#78485)~~ `read_buf_at` (rust-lang/rust#140771) feature: - `std::os::unix::fs::FileExt::read_buf_at` - `std::os::unix::fs::FileExt::read_buf_exact_at` - `std::os::windows::fs::FileExt::seek_read_buf` try-job: `x86_64-msvc*` try-job: `test-various*` try-job: `dist-various*`
2025-09-03Add `read_buf` equivalents for positioned readsNiklas Fiekas-0/+4
Adds the following items under the `read_buf_at` feature: - `std::os::unix::fs::FileExt::read_buf_at` - `std::os::unix::fs::FileExt::read_buf_exact_at` - `std::os::windows::fs::FileExt::seek_read_buf`
2025-08-30std: clarify `OpenOptions` error for create without write accessVladimir Petrzhikovskii-3/+23
Previously, attempting to create/truncate a file without write/append access would result in platform-specific error messages: - Unix: "Invalid argument" - Windows: raw OS error code 87 These error codes look like system errors, which could waste hours of debugging for what is actually an API misuse issue.
2025-08-21Add flock support for cygwin王宇逸-0/+10
2025-08-19Rollup merge of #145511 - semarie:push-rnytptsoxrxn, r=joshtriplett许杰友 Jieyou Xu (Joe)-0/+10
Rust build fails on OpenBSD after using file_lock feature PR 130999 added the file_lock feature, but doesn't included OpenBSD in the supported targets (Tier 3 platform), leading to a compilation error ("try_lock() not supported"). Cc `@cberner` Related to rust-lang/rust#130999
2025-08-17Rust build fails on OpenBSD after using file_lock featureSebastien Marie-0/+10
PR 130999 added the file_lock feature, but doesn't included OpenBSD in the supported targets (Tier 3 platform), leading to a compilation error ("try_lock() not supported").
2025-08-16library: Migrate from `cfg_if` to `cfg_select`Josh Triplett-14/+20
Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro. This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does. Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation): ``` '<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e ``` This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-07-09Fix VxWorks build errorsB I Mohammed Abbas-1/+0
2025-06-05Optimize `Seek::stream_len` impl for `File`Tobias Bucher-0/+9
It uses the file metadata on Unix with a fallback for files incorrectly reported as zero-sized. It uses `GetFileSizeEx` on Windows. This reduces the number of syscalls needed for determining the file size of an open file from 3 to 1.
2025-05-14Fix settimes for vxworksB I Mohammed Abbas-2/+1
2025-05-03Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubileeMatthias Krüger-14/+25
Change signature of File::try_lock and File::try_lock_shared These methods now return Result<(), TryLockError> instead of Result<bool, Error> to make their use less errorprone These methods are unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/pull/130999 and this PR changes the signatures as discussed by libs-api: https://github.com/rust-lang/rust/issues/130994#issuecomment-2770838848
2025-05-01Change signature of File::try_lock and File::try_lock_sharedChristopher Berner-14/+25
These methods now return Result<(), TryLockError> instead of Result<bool, Error> to make their use less errorprone
2025-04-27use generic Atomic type where possibleChristopher Durham-2/+2
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-24Rollup merge of #139450 - NobodyXu:new-api/make-fifo, r=tgross35Matthias Krüger-0/+6
Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo` Tracking issue #139324
2025-04-23Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo`Jiahao XU-0/+6
Tracking issue #139324 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-04-18std: Use fstatat() on illumosPatrick Mooney-3/+6
2025-04-11cfi: Remove #[no_sanitize(cfi)] for extern weak functionsBastian Kersting-14/+0
Previously (https://github.com/rust-lang/rust/pull/115200, https://github.com/rust-lang/rust/pull/138002), we added `#[no_sanitize(cfi)]` to all code paths that call to a weakly linked function. In https://github.com/rust-lang/rust/pull/138349 we fixed the root cause for this issue, which means we can now remove the corresponding attributes.
2025-03-29Rollup merge of #138832 - ChrisDenton:with_native_path, r=joboetMatthias Krüger-100/+79
Start using `with_native_path` in `std::sys::fs` Ideally, each platform should use their own native path type internally. This will, for example, allow passing a `CStr` directly to `std::fs::File::open` and therefore avoid the need for allocating a new null-terminated C string. However, doing that for every function and platform all at once makes for a large PR that is way too prone to breaking. So this PR does some minimal refactoring which should help progress towards that goal. The changes are Unix-only and even then I avoided functions that require more changes so that this PR is just moving things around. r? joboet
2025-03-29Start using with_native_path in std::sys::fsChris Denton-100/+79
2025-03-26Change the syntax of the internal `weak!` macroMads Marquart-6/+10
Change the syntax to include parameter names and a trailing semicolon. Motivation: - Mirror the `syscall!` macro. - Allow rustfmt to format it (when wrapped in parentheses). - For better documentation (having the parameter names available in the source code is a bit nicer). - Allow future improvements to this macro where we can sometimes use the symbol directly when it's statically known to be available.
2025-03-17Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboetJacob Pratt-1/+10
Add std support to cygwin target
2025-03-10Fix code style王宇逸-1/+6
2025-03-10Initial STD support for Cygwin王宇逸-1/+5
Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
2025-03-10Add comments for #[no_sanitize(cfi)] in stdlibBastian Kersting-0/+2
2025-03-10Disable CFI for weakly linked syscallsBastian Kersting-0/+12
Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g. std::sys::random::getrandom, we can observe a CFI violation. This is the case for all consumers of the std::sys::pal::weak::weak macro, as it is defining weak functions which don't show up in LLVM IR metadata. CFI fails for all these functions. Similar to other such cases in https://github.com/rust-lang/rust/issues/115199, this change stops emitting the CFI typecheck for consumers of the macro via the \#[no_sanitize(cfi)] attribute.
2025-03-08Move fs into sysThalia Archibald-0/+2319