Skip to content

Commit c92e910

Browse files
committed
Auto merge of #31810 - gandro:netbsd-fix-stat, r=alexcrichton
Some struct members have a slighty different name on NetBSD. This has been fixed in the libc crate, but not in libstd, breaking the NetBSD build. Related C struct definition: http://nxr.netbsd.org/xref/src/sys/sys/stat.h?r=1.68#59 This also removes the broken `st_spare()` from MetadataExt, since it is private field reserved for future use. @dhuseby In case this conflicts with any of your pending patches, feel free to intervene - I'm happy to withdraw this PR. r? @alexcrichton
2 parents f93a62b + 028106c commit c92e910

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/libstd/os/netbsd/fs.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ pub trait MetadataExt {
7474
fn st_flags(&self) -> u32;
7575
#[stable(feature = "metadata_ext2", since = "1.8.0")]
7676
fn st_gen(&self) -> u32;
77-
#[stable(feature = "metadata_ext2", since = "1.8.0")]
78-
fn st_spare(&self) -> u32;
7977
}
8078

8179
#[stable(feature = "metadata_ext", since = "1.1.0")]
@@ -115,25 +113,25 @@ impl MetadataExt for Metadata {
115113
self.as_inner().as_inner().st_atime as i64
116114
}
117115
fn st_atime_nsec(&self) -> i64 {
118-
self.as_inner().as_inner().st_atime_nsec as i64
116+
self.as_inner().as_inner().st_atimensec as i64
119117
}
120118
fn st_mtime(&self) -> i64 {
121119
self.as_inner().as_inner().st_mtime as i64
122120
}
123121
fn st_mtime_nsec(&self) -> i64 {
124-
self.as_inner().as_inner().st_mtime_nsec as i64
122+
self.as_inner().as_inner().st_mtimensec as i64
125123
}
126124
fn st_ctime(&self) -> i64 {
127125
self.as_inner().as_inner().st_ctime as i64
128126
}
129127
fn st_ctime_nsec(&self) -> i64 {
130-
self.as_inner().as_inner().st_ctime_nsec as i64
128+
self.as_inner().as_inner().st_ctimensec as i64
131129
}
132130
fn st_birthtime(&self) -> i64 {
133131
self.as_inner().as_inner().st_birthtime as i64
134132
}
135133
fn st_birthtime_nsec(&self) -> i64 {
136-
self.as_inner().as_inner().st_birthtime_nsec as i64
134+
self.as_inner().as_inner().st_birthtimensec as i64
137135
}
138136
fn st_blksize(&self) -> u64 {
139137
self.as_inner().as_inner().st_blksize as u64
@@ -147,8 +145,5 @@ impl MetadataExt for Metadata {
147145
fn st_flags(&self) -> u32 {
148146
self.as_inner().as_inner().st_flags as u32
149147
}
150-
fn st_spare(&self) -> u32 {
151-
self.as_inner().as_inner().st_spare as u32
152-
}
153148
}
154149

src/libstd/sys/unix/fs.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,31 @@ impl FileAttr {
119119
}
120120
}
121121

122-
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
122+
#[cfg(target_os = "netbsd")]
123+
impl FileAttr {
124+
pub fn modified(&self) -> io::Result<SystemTime> {
125+
Ok(SystemTime::from(libc::timespec {
126+
tv_sec: self.stat.st_mtime as libc::time_t,
127+
tv_nsec: self.stat.st_mtimensec as libc::c_long,
128+
}))
129+
}
130+
131+
pub fn accessed(&self) -> io::Result<SystemTime> {
132+
Ok(SystemTime::from(libc::timespec {
133+
tv_sec: self.stat.st_atime as libc::time_t,
134+
tv_nsec: self.stat.st_atimensec as libc::c_long,
135+
}))
136+
}
137+
138+
pub fn created(&self) -> io::Result<SystemTime> {
139+
Ok(SystemTime::from(libc::timespec {
140+
tv_sec: self.stat.st_birthtime as libc::time_t,
141+
tv_nsec: self.stat.st_birthtimensec as libc::c_long,
142+
}))
143+
}
144+
}
145+
146+
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "netbsd")))]
123147
impl FileAttr {
124148
pub fn modified(&self) -> io::Result<SystemTime> {
125149
Ok(SystemTime::from(libc::timespec {

0 commit comments

Comments
 (0)