summaryrefslogtreecommitdiffstats
path: root/library/std/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/os')
-rw-r--r--library/std/src/os/android/raw.rs107
-rw-r--r--library/std/src/os/l4re/raw.rs1
-rw-r--r--library/std/src/os/linux/raw.rs4
-rw-r--r--library/std/src/os/raw/mod.rs5
-rw-r--r--library/std/src/os/unix/fs.rs40
-rw-r--r--library/std/src/os/unix/net/stream.rs1
-rw-r--r--library/std/src/os/unix/net/tests.rs18
7 files changed, 115 insertions, 61 deletions
diff --git a/library/std/src/os/android/raw.rs b/library/std/src/os/android/raw.rs
index a255d0320..175f8eac9 100644
--- a/library/std/src/os/android/raw.rs
+++ b/library/std/src/os/android/raw.rs
@@ -21,26 +21,26 @@ pub use self::arch::{blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, off_t,
#[cfg(any(target_arch = "arm", target_arch = "x86"))]
mod arch {
- use crate::os::raw::{c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong};
+ use crate::os::raw::{c_long, c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong};
use crate::os::unix::raw::{gid_t, uid_t};
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type dev_t = u64;
+ pub type dev_t = u32;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type mode_t = u32;
+ pub type mode_t = c_uint;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type blkcnt_t = u64;
+ pub type blkcnt_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type blksize_t = u64;
+ pub type blksize_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type ino_t = u64;
+ pub type ino_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type nlink_t = u64;
+ pub type nlink_t = u32;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type off_t = u64;
+ pub type off_t = i32;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type time_t = i64;
+ pub type time_t = c_long;
#[repr(C)]
#[derive(Clone)]
@@ -70,45 +70,47 @@ mod arch {
pub st_blksize: u32,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_blocks: c_ulonglong,
+
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_atime: c_ulong,
+ pub st_atime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_atime_nsec: c_ulong,
+ pub st_atime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_mtime: c_ulong,
+ pub st_mtime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_mtime_nsec: c_ulong,
+ pub st_mtime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_ctime: c_ulong,
+ pub st_ctime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_ctime_nsec: c_ulong,
+ pub st_ctime_nsec: c_long,
+
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_ino: c_ulonglong,
}
}
-#[cfg(target_arch = "aarch64")]
+#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
mod arch {
- use crate::os::raw::{c_uchar, c_ulong};
+ use crate::os::raw::{c_int, c_long, c_uint, c_ulong};
use crate::os::unix::raw::{gid_t, uid_t};
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type dev_t = u64;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type mode_t = u32;
+ pub type mode_t = c_uint;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type blkcnt_t = u64;
+ pub type blkcnt_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type blksize_t = u64;
+ pub type blksize_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type ino_t = u64;
+ pub type ino_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type nlink_t = u64;
+ pub type nlink_t = u32;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type off_t = u64;
+ pub type off_t = i64;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type time_t = i64;
+ pub type time_t = c_long;
#[repr(C)]
#[derive(Clone)]
@@ -117,9 +119,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_dev: dev_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub __pad0: [c_uchar; 4],
- #[stable(feature = "raw_ext", since = "1.1.0")]
- pub __st_ino: ino_t,
+ pub st_ino: ino_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_mode: mode_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -131,27 +131,33 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_rdev: dev_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub __pad3: [c_uchar; 4],
+ pub __pad1: c_ulong,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_size: off_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_blksize: blksize_t,
+ pub st_blksize: c_int,
+ #[stable(feature = "raw_ext", since = "1.1.0")]
+ pub __pad2: c_int,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_blocks: blkcnt_t,
+ pub st_blocks: c_long,
+
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_atime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_atime_nsec: c_ulong,
+ pub st_atime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_mtime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_mtime_nsec: c_ulong,
+ pub st_mtime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_ctime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_ctime_nsec: c_ulong,
+ pub st_ctime_nsec: c_long,
+
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_ino: ino_t,
+ pub __unused4: c_uint,
+ #[stable(feature = "raw_ext", since = "1.1.0")]
+ pub __unused5: c_uint,
}
}
@@ -163,20 +169,20 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type dev_t = u64;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type mode_t = u32;
+ pub type mode_t = c_uint;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type blkcnt_t = u64;
+ pub type blkcnt_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type blksize_t = u64;
+ pub type blksize_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type ino_t = u64;
+ pub type ino_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type nlink_t = u32;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type off_t = u64;
+ pub type off_t = i64;
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub type time_t = i64;
+ pub type time_t = c_long;
#[repr(C)]
#[derive(Clone)]
@@ -195,25 +201,30 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_gid: gid_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
+ pub __pad0: c_uint,
+ #[stable(feature = "raw_ext", since = "1.1.0")]
pub st_rdev: dev_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_size: i64,
+ pub st_size: off_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_blksize: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_blocks: c_long,
+
+ #[stable(feature = "raw_ext", since = "1.1.0")]
+ pub st_atime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_atime: c_ulong,
+ pub st_atime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_atime_nsec: c_ulong,
+ pub st_mtime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_mtime: c_ulong,
+ pub st_mtime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_mtime_nsec: c_ulong,
+ pub st_ctime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_ctime: c_ulong,
+ pub st_ctime_nsec: c_long,
+
#[stable(feature = "raw_ext", since = "1.1.0")]
- pub st_ctime_nsec: c_ulong,
- __unused: [c_long; 3],
+ pub __pad3: [c_long; 3],
}
}
diff --git a/library/std/src/os/l4re/raw.rs b/library/std/src/os/l4re/raw.rs
index b3f7439f8..12c029328 100644
--- a/library/std/src/os/l4re/raw.rs
+++ b/library/std/src/os/l4re/raw.rs
@@ -27,6 +27,7 @@ pub use self::arch::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
#[cfg(any(
target_arch = "x86",
target_arch = "m68k",
+ target_arch = "csky",
target_arch = "powerpc",
target_arch = "sparc",
target_arch = "arm",
diff --git a/library/std/src/os/linux/raw.rs b/library/std/src/os/linux/raw.rs
index c55ca8ba2..a568f9b26 100644
--- a/library/std/src/os/linux/raw.rs
+++ b/library/std/src/os/linux/raw.rs
@@ -27,6 +27,7 @@ pub use self::arch::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
#[cfg(any(
target_arch = "x86",
target_arch = "m68k",
+ target_arch = "csky",
target_arch = "powerpc",
target_arch = "sparc",
target_arch = "arm",
@@ -94,7 +95,7 @@ mod arch {
}
}
-#[cfg(target_arch = "mips")]
+#[cfg(any(target_arch = "mips", target_arch = "mips32r6"))]
mod arch {
use crate::os::raw::{c_long, c_ulong};
@@ -233,6 +234,7 @@ mod arch {
#[cfg(any(
target_arch = "loongarch64",
target_arch = "mips64",
+ target_arch = "mips64r6",
target_arch = "s390x",
target_arch = "sparc64",
target_arch = "riscv64",
diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs
index 19d0ffb2e..5b302e3c2 100644
--- a/library/std/src/os/raw/mod.rs
+++ b/library/std/src/os/raw/mod.rs
@@ -9,11 +9,6 @@ macro_rules! alias_core_ffi {
($($t:ident)*) => {$(
#[stable(feature = "raw_os", since = "1.1.0")]
#[doc = include_str!(concat!("../../../../core/src/ffi/", stringify!($t), ".md"))]
- // Make this type alias appear cfg-dependent so that Clippy does not suggest
- // replacing expressions like `0 as c_char` with `0_i8`/`0_u8`. This #[cfg(all())] can be
- // removed after the false positive in https://github.com/rust-lang/rust-clippy/issues/8093
- // is fixed.
- #[cfg(all())]
#[doc(cfg(all()))]
pub type $t = core::ffi::$t;
)*}
diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs
index 1e1c36931..029de8fbf 100644
--- a/library/std/src/os/unix/fs.rs
+++ b/library/std/src/os/unix/fs.rs
@@ -149,7 +149,36 @@ pub trait FileExt {
/// Note that similar to [`File::write`], it is not an error to return a
/// short write.
///
+ /// # Bug
+ /// On some systems, `write_at` utilises [`pwrite64`] to write to files.
+ /// However, this syscall has a [bug] where files opened with the `O_APPEND`
+ /// flag fail to respect the offset parameter, always appending to the end
+ /// of the file instead.
+ ///
+ /// It is possible to inadvertantly set this flag, like in the example below.
+ /// Therefore, it is important to be vigilant while changing options to mitigate
+ /// unexpected behaviour.
+ ///
+ /// ```no_run
+ /// use std::fs::File;
+ /// use std::io;
+ /// use std::os::unix::prelude::FileExt;
+ ///
+ /// fn main() -> io::Result<()> {
+ /// // Open a file with the append option (sets the `O_APPEND` flag)
+ /// let file = File::options().append(true).open("foo.txt")?;
+ ///
+ /// // We attempt to write at offset 10; instead appended to EOF
+ /// file.write_at(b"sushi", 10)?;
+ ///
+ /// // foo.txt is 5 bytes long instead of 15
+ /// Ok(())
+ /// }
+ /// ```
+ ///
/// [`File::write`]: fs::File::write
+ /// [`pwrite64`]: https://man7.org/linux/man-pages/man2/pwrite.2.html
+ /// [bug]: https://man7.org/linux/man-pages/man2/pwrite.2.html#BUGS
///
/// # Examples
///
@@ -159,7 +188,7 @@ pub trait FileExt {
/// use std::os::unix::prelude::FileExt;
///
/// fn main() -> io::Result<()> {
- /// let file = File::open("foo.txt")?;
+ /// let file = File::create("foo.txt")?;
///
/// // We now write at the offset 10.
/// file.write_at(b"sushi", 10)?;
@@ -971,7 +1000,6 @@ impl DirBuilderExt for fs::DirBuilder {
/// # Examples
///
/// ```no_run
-/// #![feature(unix_chown)]
/// use std::os::unix::fs;
///
/// fn main() -> std::io::Result<()> {
@@ -979,7 +1007,7 @@ impl DirBuilderExt for fs::DirBuilder {
/// Ok(())
/// }
/// ```
-#[unstable(feature = "unix_chown", issue = "88989")]
+#[stable(feature = "unix_chown", since = "1.73.0")]
pub fn chown<P: AsRef<Path>>(dir: P, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
sys::fs::chown(dir.as_ref(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX))
}
@@ -991,7 +1019,6 @@ pub fn chown<P: AsRef<Path>>(dir: P, uid: Option<u32>, gid: Option<u32>) -> io::
/// # Examples
///
/// ```no_run
-/// #![feature(unix_chown)]
/// use std::os::unix::fs;
///
/// fn main() -> std::io::Result<()> {
@@ -1000,7 +1027,7 @@ pub fn chown<P: AsRef<Path>>(dir: P, uid: Option<u32>, gid: Option<u32>) -> io::
/// Ok(())
/// }
/// ```
-#[unstable(feature = "unix_chown", issue = "88989")]
+#[stable(feature = "unix_chown", since = "1.73.0")]
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
sys::fs::fchown(fd.as_fd().as_raw_fd(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX))
}
@@ -1013,7 +1040,6 @@ pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<
/// # Examples
///
/// ```no_run
-/// #![feature(unix_chown)]
/// use std::os::unix::fs;
///
/// fn main() -> std::io::Result<()> {
@@ -1021,7 +1047,7 @@ pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<
/// Ok(())
/// }
/// ```
-#[unstable(feature = "unix_chown", issue = "88989")]
+#[stable(feature = "unix_chown", since = "1.73.0")]
pub fn lchown<P: AsRef<Path>>(dir: P, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
sys::fs::lchown(dir.as_ref(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX))
}
diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs
index e20170873..41290e001 100644
--- a/library/std/src/os/unix/net/stream.rs
+++ b/library/std/src/os/unix/net/stream.rs
@@ -712,6 +712,7 @@ impl<'a> io::Write for &'a UnixStream {
self.0.is_write_vectored()
}
+ #[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
diff --git a/library/std/src/os/unix/net/tests.rs b/library/std/src/os/unix/net/tests.rs
index 39f10c50d..3d4302e66 100644
--- a/library/std/src/os/unix/net/tests.rs
+++ b/library/std/src/os/unix/net/tests.rs
@@ -23,6 +23,7 @@ macro_rules! or_panic {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn basic() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
@@ -93,6 +94,7 @@ fn pair() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn try_clone() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
@@ -119,6 +121,7 @@ fn try_clone() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn iter() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
@@ -168,6 +171,7 @@ fn long_path() {
#[test]
#[cfg(not(target_os = "nto"))]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn timeouts() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
@@ -195,6 +199,7 @@ fn timeouts() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_read_timeout() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
@@ -214,6 +219,7 @@ fn test_read_timeout() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_read_with_timeout() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
@@ -241,6 +247,7 @@ fn test_read_with_timeout() {
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
// when passed zero Durations
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_stream_timeout_zero_duration() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
@@ -260,6 +267,7 @@ fn test_unix_stream_timeout_zero_duration() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
@@ -276,6 +284,7 @@ fn test_unix_datagram() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unnamed_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
@@ -293,6 +302,7 @@ fn test_unnamed_unix_datagram() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_connect_to_recv_addr() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
@@ -317,6 +327,7 @@ fn test_unix_datagram_connect_to_recv_addr() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_connect_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
@@ -343,6 +354,7 @@ fn test_connect_unix_datagram() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_recv() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
@@ -385,6 +397,7 @@ fn datagram_pair() {
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
// when passed zero Durations
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_timeout_zero_duration() {
let dir = tmpdir();
let path = dir.path().join("sock");
@@ -529,6 +542,7 @@ fn test_abstract_no_pathname_and_not_unnamed() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_stream_peek() {
let (txdone, rxdone) = crate::sync::mpsc::channel();
@@ -561,6 +575,7 @@ fn test_unix_stream_peek() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_peek() {
let dir = tmpdir();
let path1 = dir.path().join("sock");
@@ -585,6 +600,7 @@ fn test_unix_datagram_peek() {
}
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_peek_from() {
let dir = tmpdir();
let path1 = dir.path().join("sock");
@@ -648,6 +664,7 @@ fn test_send_vectored_fds_unix_stream() {
#[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))]
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_send_vectored_with_ancillary_to_unix_datagram() {
fn getpid() -> libc::pid_t {
unsafe { libc::getpid() }
@@ -715,6 +732,7 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() {
#[cfg(any(target_os = "android", target_os = "linux"))]
#[test]
+#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_send_vectored_with_ancillary_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");