Skip to content

Commit 90fd72a

Browse files
committed
Auto merge of rust-lang#109882 - ecnelises:aix_std, r=workingjubilee
Support AIX in Rust standard library Also thanks to contributions from `@bzEq` .
2 parents 093b9d5 + 14d29be commit 90fd72a

File tree

14 files changed

+462
-3
lines changed

14 files changed

+462
-3
lines changed

library/std/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fn main() {
4242
|| target.contains("solid")
4343
|| target.contains("nintendo-3ds")
4444
|| target.contains("vita")
45+
|| target.contains("aix")
4546
|| target.contains("nto")
4647
|| target.contains("xous")
4748
|| target.contains("hurd")

library/std/src/os/aix/fs.rs

+348
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,348 @@
1+
//! AIX specific extensions to primitives in the [`std::fs`] module.
2+
//!
3+
//! [`std::fs`]: crate::fs
4+
5+
#![stable(feature = "metadata_ext", since = "1.1.0")]
6+
7+
use crate::fs::Metadata;
8+
use crate::sys_common::AsInner;
9+
10+
/// OS-specific extensions to [`fs::Metadata`].
11+
///
12+
/// [`fs::Metadata`]: crate::fs::Metadata
13+
#[stable(feature = "metadata_ext", since = "1.1.0")]
14+
pub trait MetadataExt {
15+
/// Returns the device ID on which this file resides.
16+
///
17+
/// # Examples
18+
///
19+
/// ```no_run
20+
/// use std::fs;
21+
/// use std::io;
22+
/// use std::os::aix::fs::MetadataExt;
23+
///
24+
/// fn main() -> io::Result<()> {
25+
/// let meta = fs::metadata("some_file")?;
26+
/// println!("{}", meta.st_dev());
27+
/// Ok(())
28+
/// }
29+
/// ```
30+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
31+
fn st_dev(&self) -> u64;
32+
/// Returns the inode number.
33+
///
34+
/// # Examples
35+
///
36+
/// ```no_run
37+
/// use std::fs;
38+
/// use std::io;
39+
/// use std::os::aix::fs::MetadataExt;
40+
///
41+
/// fn main() -> io::Result<()> {
42+
/// let meta = fs::metadata("some_file")?;
43+
/// println!("{}", meta.st_ino());
44+
/// Ok(())
45+
/// }
46+
/// ```
47+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
48+
fn st_ino(&self) -> u64;
49+
/// Returns the file type and mode.
50+
///
51+
/// # Examples
52+
///
53+
/// ```no_run
54+
/// use std::fs;
55+
/// use std::io;
56+
/// use std::os::aix::fs::MetadataExt;
57+
///
58+
/// fn main() -> io::Result<()> {
59+
/// let meta = fs::metadata("some_file")?;
60+
/// println!("{}", meta.st_mode());
61+
/// Ok(())
62+
/// }
63+
/// ```
64+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
65+
fn st_mode(&self) -> u32;
66+
/// Returns the number of hard links to file.
67+
///
68+
/// # Examples
69+
///
70+
/// ```no_run
71+
/// use std::fs;
72+
/// use std::io;
73+
/// use std::os::aix::fs::MetadataExt;
74+
///
75+
/// fn main() -> io::Result<()> {
76+
/// let meta = fs::metadata("some_file")?;
77+
/// println!("{}", meta.st_nlink());
78+
/// Ok(())
79+
/// }
80+
/// ```
81+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
82+
fn st_nlink(&self) -> u64;
83+
/// Returns the user ID of the file owner.
84+
///
85+
/// # Examples
86+
///
87+
/// ```no_run
88+
/// use std::fs;
89+
/// use std::io;
90+
/// use std::os::aix::fs::MetadataExt;
91+
///
92+
/// fn main() -> io::Result<()> {
93+
/// let meta = fs::metadata("some_file")?;
94+
/// println!("{}", meta.st_uid());
95+
/// Ok(())
96+
/// }
97+
/// ```
98+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
99+
fn st_uid(&self) -> u32;
100+
/// Returns the group ID of the file owner.
101+
///
102+
/// # Examples
103+
///
104+
/// ```no_run
105+
/// use std::fs;
106+
/// use std::io;
107+
/// use std::os::aix::fs::MetadataExt;
108+
///
109+
/// fn main() -> io::Result<()> {
110+
/// let meta = fs::metadata("some_file")?;
111+
/// println!("{}", meta.st_gid());
112+
/// Ok(())
113+
/// }
114+
/// ```
115+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
116+
fn st_gid(&self) -> u32;
117+
/// Returns the device ID that this file represents. Only relevant for special file.
118+
///
119+
/// # Examples
120+
///
121+
/// ```no_run
122+
/// use std::fs;
123+
/// use std::io;
124+
/// use std::os::aix::fs::MetadataExt;
125+
///
126+
/// fn main() -> io::Result<()> {
127+
/// let meta = fs::metadata("some_file")?;
128+
/// println!("{}", meta.st_rdev());
129+
/// Ok(())
130+
/// }
131+
/// ```
132+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
133+
fn st_rdev(&self) -> u64;
134+
/// Returns the size of the file (if it is a regular file or a symbolic link) in bytes.
135+
///
136+
/// The size of a symbolic link is the length of the pathname it contains,
137+
/// without a terminating null byte.
138+
///
139+
/// # Examples
140+
///
141+
/// ```no_run
142+
/// use std::fs;
143+
/// use std::io;
144+
/// use std::os::aix::fs::MetadataExt;
145+
///
146+
/// fn main() -> io::Result<()> {
147+
/// let meta = fs::metadata("some_file")?;
148+
/// println!("{}", meta.st_size());
149+
/// Ok(())
150+
/// }
151+
/// ```
152+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
153+
fn st_size(&self) -> u64;
154+
/// Returns the last access time of the file, in seconds since Unix Epoch.
155+
///
156+
/// # Examples
157+
///
158+
/// ```no_run
159+
/// use std::fs;
160+
/// use std::io;
161+
/// use std::os::aix::fs::MetadataExt;
162+
///
163+
/// fn main() -> io::Result<()> {
164+
/// let meta = fs::metadata("some_file")?;
165+
/// println!("{}", meta.st_atime());
166+
/// Ok(())
167+
/// }
168+
/// ```
169+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
170+
fn st_atime(&self) -> i64;
171+
/// Returns the last access time of the file, in nanoseconds since [`st_atime`].
172+
///
173+
/// [`st_atime`]: Self::st_atime
174+
///
175+
/// # Examples
176+
///
177+
/// ```no_run
178+
/// use std::fs;
179+
/// use std::io;
180+
/// use std::os::aix::fs::MetadataExt;
181+
///
182+
/// fn main() -> io::Result<()> {
183+
/// let meta = fs::metadata("some_file")?;
184+
/// println!("{}", meta.st_atime_nsec());
185+
/// Ok(())
186+
/// }
187+
/// ```
188+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
189+
fn st_atime_nsec(&self) -> i64;
190+
/// Returns the last modification time of the file, in seconds since Unix Epoch.
191+
///
192+
/// # Examples
193+
///
194+
/// ```no_run
195+
/// use std::fs;
196+
/// use std::io;
197+
/// use std::os::aix::fs::MetadataExt;
198+
///
199+
/// fn main() -> io::Result<()> {
200+
/// let meta = fs::metadata("some_file")?;
201+
/// println!("{}", meta.st_mtime());
202+
/// Ok(())
203+
/// }
204+
/// ```
205+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
206+
fn st_mtime(&self) -> i64;
207+
/// Returns the last modification time of the file, in nanoseconds since [`st_mtime`].
208+
///
209+
/// [`st_mtime`]: Self::st_mtime
210+
///
211+
/// # Examples
212+
///
213+
/// ```no_run
214+
/// use std::fs;
215+
/// use std::io;
216+
/// use std::os::aix::fs::MetadataExt;
217+
///
218+
/// fn main() -> io::Result<()> {
219+
/// let meta = fs::metadata("some_file")?;
220+
/// println!("{}", meta.st_mtime_nsec());
221+
/// Ok(())
222+
/// }
223+
/// ```
224+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
225+
fn st_mtime_nsec(&self) -> i64;
226+
/// Returns the last status change time of the file, in seconds since Unix Epoch.
227+
///
228+
/// # Examples
229+
///
230+
/// ```no_run
231+
/// use std::fs;
232+
/// use std::io;
233+
/// use std::os::aix::fs::MetadataExt;
234+
///
235+
/// fn main() -> io::Result<()> {
236+
/// let meta = fs::metadata("some_file")?;
237+
/// println!("{}", meta.st_ctime());
238+
/// Ok(())
239+
/// }
240+
/// ```
241+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
242+
fn st_ctime(&self) -> i64;
243+
/// Returns the last status change time of the file, in nanoseconds since [`st_ctime`].
244+
///
245+
/// [`st_ctime`]: Self::st_ctime
246+
///
247+
/// # Examples
248+
///
249+
/// ```no_run
250+
/// use std::fs;
251+
/// use std::io;
252+
/// use std::os::aix::fs::MetadataExt;
253+
///
254+
/// fn main() -> io::Result<()> {
255+
/// let meta = fs::metadata("some_file")?;
256+
/// println!("{}", meta.st_ctime_nsec());
257+
/// Ok(())
258+
/// }
259+
/// ```
260+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
261+
fn st_ctime_nsec(&self) -> i64;
262+
/// Returns the "preferred" block size for efficient filesystem I/O.
263+
///
264+
/// # Examples
265+
///
266+
/// ```no_run
267+
/// use std::fs;
268+
/// use std::io;
269+
/// use std::os::aix::fs::MetadataExt;
270+
///
271+
/// fn main() -> io::Result<()> {
272+
/// let meta = fs::metadata("some_file")?;
273+
/// println!("{}", meta.st_blksize());
274+
/// Ok(())
275+
/// }
276+
/// ```
277+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
278+
fn st_blksize(&self) -> u64;
279+
/// Returns the number of blocks allocated to the file, 512-byte units.
280+
///
281+
/// # Examples
282+
///
283+
/// ```no_run
284+
/// use std::fs;
285+
/// use std::io;
286+
/// use std::os::aix::fs::MetadataExt;
287+
///
288+
/// fn main() -> io::Result<()> {
289+
/// let meta = fs::metadata("some_file")?;
290+
/// println!("{}", meta.st_blocks());
291+
/// Ok(())
292+
/// }
293+
/// ```
294+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
295+
fn st_blocks(&self) -> u64;
296+
}
297+
298+
#[stable(feature = "metadata_ext", since = "1.1.0")]
299+
impl MetadataExt for Metadata {
300+
fn st_dev(&self) -> u64 {
301+
self.as_inner().as_inner().st_dev as u64
302+
}
303+
fn st_ino(&self) -> u64 {
304+
self.as_inner().as_inner().st_ino as u64
305+
}
306+
fn st_mode(&self) -> u32 {
307+
self.as_inner().as_inner().st_mode as u32
308+
}
309+
fn st_nlink(&self) -> u64 {
310+
self.as_inner().as_inner().st_nlink as u64
311+
}
312+
fn st_uid(&self) -> u32 {
313+
self.as_inner().as_inner().st_uid as u32
314+
}
315+
fn st_gid(&self) -> u32 {
316+
self.as_inner().as_inner().st_gid as u32
317+
}
318+
fn st_rdev(&self) -> u64 {
319+
self.as_inner().as_inner().st_rdev as u64
320+
}
321+
fn st_size(&self) -> u64 {
322+
self.as_inner().as_inner().st_size as u64
323+
}
324+
fn st_atime(&self) -> i64 {
325+
self.as_inner().as_inner().st_atime.tv_sec as i64
326+
}
327+
fn st_atime_nsec(&self) -> i64 {
328+
self.as_inner().as_inner().st_atime.tv_nsec as i64
329+
}
330+
fn st_mtime(&self) -> i64 {
331+
self.as_inner().as_inner().st_mtime.tv_sec as i64
332+
}
333+
fn st_mtime_nsec(&self) -> i64 {
334+
self.as_inner().as_inner().st_mtime.tv_nsec as i64
335+
}
336+
fn st_ctime(&self) -> i64 {
337+
self.as_inner().as_inner().st_ctime.tv_sec as i64
338+
}
339+
fn st_ctime_nsec(&self) -> i64 {
340+
self.as_inner().as_inner().st_ctime.tv_nsec as i64
341+
}
342+
fn st_blksize(&self) -> u64 {
343+
self.as_inner().as_inner().st_blksize as u64
344+
}
345+
fn st_blocks(&self) -> u64 {
346+
self.as_inner().as_inner().st_blocks as u64
347+
}
348+
}

library/std/src/os/aix/mod.rs

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

library/std/src/os/aix/raw.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! AIX specific raw type definitions.
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
5+
#[stable(feature = "pthread_t", since = "1.8.0")]
6+
pub use libc::pthread_t;
7+
8+
#[stable(feature = "raw_ext", since = "1.1.0")]
9+
pub use libc::{blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, off_t, stat, time_t};

library/std/src/os/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pub mod wasi;
9797
pub mod windows;
9898

9999
// Others.
100+
#[cfg(target_os = "aix")]
101+
pub mod aix;
100102
#[cfg(target_os = "android")]
101103
pub mod android;
102104
#[cfg(target_os = "dragonfly")]

library/std/src/os/unix/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ use crate::os::linux as platform;
3737

3838
#[cfg(not(doc))]
3939
mod platform {
40+
#[cfg(target_os = "aix")]
41+
pub use crate::os::aix::*;
4042
#[cfg(target_os = "android")]
4143
pub use crate::os::android::*;
4244
#[cfg(target_os = "dragonfly")]

library/std/src/sys/unix/args.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl DoubleEndedIterator for Args {
7070
target_os = "redox",
7171
target_os = "vxworks",
7272
target_os = "horizon",
73+
target_os = "aix",
7374
target_os = "nto",
7475
target_os = "hurd",
7576
))]

0 commit comments

Comments
 (0)