Skip to content

Commit 2edbcf7

Browse files
committed
Standard library OS support for Apple WatchOS
1 parent b3aa499 commit 2edbcf7

File tree

5 files changed

+235
-0
lines changed

5 files changed

+235
-0
lines changed

Diff for: library/std/src/os/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ pub mod solaris;
145145
pub mod solid;
146146
#[cfg(target_os = "vxworks")]
147147
pub mod vxworks;
148+
#[cfg(target_os = "watchos")]
149+
pub(crate) mod watchos;
148150

149151
#[cfg(any(unix, target_os = "wasi", doc))]
150152
pub mod fd;

Diff for: library/std/src/os/unix/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ mod platform {
7373
pub use crate::os::solaris::*;
7474
#[cfg(target_os = "vxworks")]
7575
pub use crate::os::vxworks::*;
76+
#[cfg(target_os = "watchos")]
77+
pub use crate::os::watchos::*;
7678
}
7779

7880
pub mod ffi;

Diff for: library/std/src/os/watchos/fs.rs

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
3+
use crate::fs::Metadata;
4+
use crate::sys_common::AsInner;
5+
6+
#[allow(deprecated)]
7+
use crate::os::watchos::raw;
8+
9+
/// OS-specific extensions to [`fs::Metadata`].
10+
///
11+
/// [`fs::Metadata`]: crate::fs::Metadata
12+
#[stable(feature = "metadata_ext", since = "1.1.0")]
13+
pub trait MetadataExt {
14+
/// Gain a reference to the underlying `stat` structure which contains
15+
/// the raw information returned by the OS.
16+
///
17+
/// The contents of the returned `stat` are **not** consistent across
18+
/// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
19+
/// cross-Unix abstractions contained within the raw stat.
20+
#[stable(feature = "metadata_ext", since = "1.1.0")]
21+
#[deprecated(
22+
since = "1.8.0",
23+
note = "deprecated in favor of the accessor \
24+
methods of this trait"
25+
)]
26+
#[allow(deprecated)]
27+
fn as_raw_stat(&self) -> &raw::stat;
28+
29+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
30+
fn st_dev(&self) -> u64;
31+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
32+
fn st_ino(&self) -> u64;
33+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
34+
fn st_mode(&self) -> u32;
35+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
36+
fn st_nlink(&self) -> u64;
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_uid(&self) -> u32;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_gid(&self) -> u32;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_rdev(&self) -> u64;
43+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
44+
fn st_size(&self) -> u64;
45+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
46+
fn st_atime(&self) -> i64;
47+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
48+
fn st_atime_nsec(&self) -> i64;
49+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
50+
fn st_mtime(&self) -> i64;
51+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
52+
fn st_mtime_nsec(&self) -> i64;
53+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
54+
fn st_ctime(&self) -> i64;
55+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
56+
fn st_ctime_nsec(&self) -> i64;
57+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
58+
fn st_birthtime(&self) -> i64;
59+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
60+
fn st_birthtime_nsec(&self) -> i64;
61+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
62+
fn st_blksize(&self) -> u64;
63+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
64+
fn st_blocks(&self) -> u64;
65+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
66+
fn st_flags(&self) -> u32;
67+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
68+
fn st_gen(&self) -> u32;
69+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
70+
fn st_lspare(&self) -> u32;
71+
}
72+
73+
#[stable(feature = "metadata_ext", since = "1.1.0")]
74+
impl MetadataExt for Metadata {
75+
#[allow(deprecated)]
76+
fn as_raw_stat(&self) -> &raw::stat {
77+
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
78+
}
79+
fn st_dev(&self) -> u64 {
80+
self.as_inner().as_inner().st_dev as u64
81+
}
82+
fn st_ino(&self) -> u64 {
83+
self.as_inner().as_inner().st_ino as u64
84+
}
85+
fn st_mode(&self) -> u32 {
86+
self.as_inner().as_inner().st_mode as u32
87+
}
88+
fn st_nlink(&self) -> u64 {
89+
self.as_inner().as_inner().st_nlink as u64
90+
}
91+
fn st_uid(&self) -> u32 {
92+
self.as_inner().as_inner().st_uid as u32
93+
}
94+
fn st_gid(&self) -> u32 {
95+
self.as_inner().as_inner().st_gid as u32
96+
}
97+
fn st_rdev(&self) -> u64 {
98+
self.as_inner().as_inner().st_rdev as u64
99+
}
100+
fn st_size(&self) -> u64 {
101+
self.as_inner().as_inner().st_size as u64
102+
}
103+
fn st_atime(&self) -> i64 {
104+
self.as_inner().as_inner().st_atime as i64
105+
}
106+
fn st_atime_nsec(&self) -> i64 {
107+
self.as_inner().as_inner().st_atime_nsec as i64
108+
}
109+
fn st_mtime(&self) -> i64 {
110+
self.as_inner().as_inner().st_mtime as i64
111+
}
112+
fn st_mtime_nsec(&self) -> i64 {
113+
self.as_inner().as_inner().st_mtime_nsec as i64
114+
}
115+
fn st_ctime(&self) -> i64 {
116+
self.as_inner().as_inner().st_ctime as i64
117+
}
118+
fn st_ctime_nsec(&self) -> i64 {
119+
self.as_inner().as_inner().st_ctime_nsec as i64
120+
}
121+
fn st_birthtime(&self) -> i64 {
122+
self.as_inner().as_inner().st_birthtime as i64
123+
}
124+
fn st_birthtime_nsec(&self) -> i64 {
125+
self.as_inner().as_inner().st_birthtime_nsec as i64
126+
}
127+
fn st_blksize(&self) -> u64 {
128+
self.as_inner().as_inner().st_blksize as u64
129+
}
130+
fn st_blocks(&self) -> u64 {
131+
self.as_inner().as_inner().st_blocks as u64
132+
}
133+
fn st_gen(&self) -> u32 {
134+
self.as_inner().as_inner().st_gen as u32
135+
}
136+
fn st_flags(&self) -> u32 {
137+
self.as_inner().as_inner().st_flags as u32
138+
}
139+
fn st_lspare(&self) -> u32 {
140+
self.as_inner().as_inner().st_lspare as u32
141+
}
142+
}

Diff for: library/std/src/os/watchos/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! watchOS-specific definitions
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
5+
pub mod fs;
6+
pub mod raw;

Diff for: library/std/src/os/watchos/raw.rs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//! watchOS-specific raw type definitions
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
#![deprecated(
5+
since = "1.8.0",
6+
note = "these type aliases are no longer supported by \
7+
the standard library, the `libc` crate on \
8+
crates.io should be used instead for the correct \
9+
definitions"
10+
)]
11+
#![allow(deprecated)]
12+
13+
use crate::os::raw::c_long;
14+
15+
#[stable(feature = "raw_ext", since = "1.1.0")]
16+
pub type blkcnt_t = u64;
17+
#[stable(feature = "raw_ext", since = "1.1.0")]
18+
pub type blksize_t = u64;
19+
#[stable(feature = "raw_ext", since = "1.1.0")]
20+
pub type dev_t = u64;
21+
#[stable(feature = "raw_ext", since = "1.1.0")]
22+
pub type ino_t = u64;
23+
#[stable(feature = "raw_ext", since = "1.1.0")]
24+
pub type mode_t = u32;
25+
#[stable(feature = "raw_ext", since = "1.1.0")]
26+
pub type nlink_t = u64;
27+
#[stable(feature = "raw_ext", since = "1.1.0")]
28+
pub type off_t = u64;
29+
#[stable(feature = "raw_ext", since = "1.1.0")]
30+
pub type time_t = i64;
31+
32+
#[stable(feature = "pthread_t", since = "1.8.0")]
33+
pub type pthread_t = usize;
34+
35+
#[repr(C)]
36+
#[derive(Clone)]
37+
#[stable(feature = "raw_ext", since = "1.1.0")]
38+
pub struct stat {
39+
#[stable(feature = "raw_ext", since = "1.1.0")]
40+
pub st_dev: i32,
41+
#[stable(feature = "raw_ext", since = "1.1.0")]
42+
pub st_mode: u16,
43+
#[stable(feature = "raw_ext", since = "1.1.0")]
44+
pub st_nlink: u16,
45+
#[stable(feature = "raw_ext", since = "1.1.0")]
46+
pub st_ino: u64,
47+
#[stable(feature = "raw_ext", since = "1.1.0")]
48+
pub st_uid: u32,
49+
#[stable(feature = "raw_ext", since = "1.1.0")]
50+
pub st_gid: u32,
51+
#[stable(feature = "raw_ext", since = "1.1.0")]
52+
pub st_rdev: i32,
53+
#[stable(feature = "raw_ext", since = "1.1.0")]
54+
pub st_atime: c_long,
55+
#[stable(feature = "raw_ext", since = "1.1.0")]
56+
pub st_atime_nsec: c_long,
57+
#[stable(feature = "raw_ext", since = "1.1.0")]
58+
pub st_mtime: c_long,
59+
#[stable(feature = "raw_ext", since = "1.1.0")]
60+
pub st_mtime_nsec: c_long,
61+
#[stable(feature = "raw_ext", since = "1.1.0")]
62+
pub st_ctime: c_long,
63+
#[stable(feature = "raw_ext", since = "1.1.0")]
64+
pub st_ctime_nsec: c_long,
65+
#[stable(feature = "raw_ext", since = "1.1.0")]
66+
pub st_birthtime: c_long,
67+
#[stable(feature = "raw_ext", since = "1.1.0")]
68+
pub st_birthtime_nsec: c_long,
69+
#[stable(feature = "raw_ext", since = "1.1.0")]
70+
pub st_size: i64,
71+
#[stable(feature = "raw_ext", since = "1.1.0")]
72+
pub st_blocks: i64,
73+
#[stable(feature = "raw_ext", since = "1.1.0")]
74+
pub st_blksize: i32,
75+
#[stable(feature = "raw_ext", since = "1.1.0")]
76+
pub st_flags: u32,
77+
#[stable(feature = "raw_ext", since = "1.1.0")]
78+
pub st_gen: u32,
79+
#[stable(feature = "raw_ext", since = "1.1.0")]
80+
pub st_lspare: i32,
81+
#[stable(feature = "raw_ext", since = "1.1.0")]
82+
pub st_qspare: [i64; 2],
83+
}

0 commit comments

Comments
 (0)