Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace default_stat in std::path with a Default impl for libc::stat #9652

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 172 additions & 1 deletion src/libstd/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,13 @@ pub mod types {
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
use libc::types::os::arch::posix88::{mode_t, off_t};
use libc::types::os::arch::posix88::{uid_t};
use default::Default;

pub type nlink_t = u32;
pub type blksize_t = i32;
pub type blkcnt_t = i32;


#[deriving(Default)]
pub struct stat {
st_dev: dev_t,
__pad1: c_short,
Expand Down Expand Up @@ -332,6 +334,7 @@ pub mod types {
use libc::types::os::arch::c95::{c_uchar, c_uint, c_ulong, time_t};
use libc::types::os::arch::c99::{c_longlong, c_ulonglong};
use libc::types::os::arch::posix88::{uid_t, gid_t, ino_t};
use default::Default;

pub type nlink_t = u16;
pub type blksize_t = u32;
Expand All @@ -358,13 +361,39 @@ pub mod types {
st_ctime_nsec: c_ulong,
st_ino: c_ulonglong
}
impl Default for stat {
fn default() -> stat {
stat {
st_dev: 0,
__pad0: [0, ..4],
__st_ino: 0,
st_mode: 0,
st_nlink: 0,
st_uid: 0,
st_gid: 0,
st_rdev: 0,
__pad3: [0, ..4],
st_size: 0,
st_blksize: 0,
st_blocks: 0,
st_atime: 0,
st_atime_nsec: 0,
st_mtime: 0,
st_mtime_nsec: 0,
st_ctime: 0,
st_ctime_nsec: 0,
st_ino: 0
}
}
}
}
#[cfg(target_arch = "mips")]
pub mod posix01 {
use libc::types::os::arch::c95::{c_long, c_ulong, time_t};
use libc::types::os::arch::posix88::{gid_t, ino_t};
use libc::types::os::arch::posix88::{mode_t, off_t};
use libc::types::os::arch::posix88::{uid_t};
use default::Default;

pub type nlink_t = u32;
pub type blksize_t = i32;
Expand Down Expand Up @@ -392,6 +421,32 @@ pub mod types {
st_blocks: blkcnt_t,
st_pad5: [c_long, ..14],
}
impl Default for stat {
fn default() -> stat {
stat {
st_dev: 0,
st_pad1: [0, ..3],
st_ino: 0,
st_mode: 0,
st_nlink: 0,
st_uid: 0,
st_gid: 0,
st_rdev: 0,
st_pad2: [0, ..2],
st_size: 0,
st_pad3: 0,
st_atime: 0,
st_atime_nsec: 0,
st_mtime: 0,
st_mtime_nsec: 0,
st_ctime: 0,
st_ctime_nsec: 0,
st_blksize: 0,
st_blocks: 0,
st_pad5: [0, ..14],
}
}
}
}
pub mod posix08 {}
pub mod bsd44 {}
Expand Down Expand Up @@ -440,10 +495,12 @@ pub mod types {
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
use libc::types::os::arch::posix88::{mode_t, off_t};
use libc::types::os::arch::posix88::{uid_t};
use default::Default;

pub type nlink_t = u64;
pub type blksize_t = i64;
pub type blkcnt_t = i64;

pub struct stat {
st_dev: dev_t,
st_ino: ino_t,
Expand All @@ -464,6 +521,30 @@ pub mod types {
st_ctime_nsec: c_long,
__unused: [c_long, ..3],
}
impl Default for stat {
fn default() -> stat {
stat {
st_dev: 0,
st_ino: 0,
st_nlink: 0,
st_mode: 0,
st_uid: 0,
st_gid: 0,
__pad0: 0,
st_rdev: 0,
st_size: 0,
st_blksize: 0,
st_blocks: 0,
st_atime: 0,
st_atime_nsec: 0,
st_mtime: 0,
st_mtime_nsec: 0,
st_ctime: 0,
st_ctime_nsec: 0,
__unused: [0, 0, 0],
}
}
}
}
pub mod posix08 {
}
Expand Down Expand Up @@ -541,11 +622,13 @@ pub mod types {
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
use libc::types::os::arch::posix88::{mode_t, off_t};
use libc::types::os::arch::posix88::{uid_t};
use default::Default;

pub type nlink_t = u16;
pub type blksize_t = i64;
pub type blkcnt_t = i64;
pub type fflags_t = u32;

pub struct stat {
st_dev: dev_t,
st_ino: ino_t,
Expand All @@ -570,6 +653,34 @@ pub mod types {
st_birthtime_nsec: c_long,
__unused: [uint8_t, ..2],
}
impl Default for stat {
fn default() -> stat {
stat {
st_dev: 0,
st_ino: 0,
st_mode: 0,
st_nlink: 0,
st_uid: 0,
st_gid: 0,
st_rdev: 0,
st_atime: 0,
st_atime_nsec: 0,
st_mtime: 0,
st_mtime_nsec: 0,
st_ctime: 0,
st_ctime_nsec: 0,
st_size: 0,
st_blocks: 0,
st_blksize: 0,
st_flags: 0,
st_gen: 0,
st_lspare: 0,
st_birthtime: 0,
st_birthtime_nsec: 0,
__unused: [0, 0],
}
}
}
}
pub mod posix08 {
}
Expand All @@ -588,9 +699,11 @@ pub mod types {
use libc::types::os::arch::extra::{int64, time64_t};
use libc::types::os::arch::posix88::{dev_t, ino_t};
use libc::types::os::arch::posix88::mode_t;
use default::Default;

// Note: this is the struct called stat64 in win32. Not stat,
// nor stati64.
#[deriving(Default)]
pub struct stat {
st_dev: dev_t,
st_ino: ino_t,
Expand Down Expand Up @@ -1006,6 +1119,7 @@ pub mod types {
use libc::types::os::arch::c95::{c_long, time_t};
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t,
mode_t, off_t, uid_t};
use default::Default;

pub type nlink_t = u16;
pub type blksize_t = i64;
Expand Down Expand Up @@ -1035,6 +1149,34 @@ pub mod types {
st_lspare: int32_t,
st_qspare: [int64_t, ..2],
}
impl Default for stat {
fn default() -> stat {
stat {
st_dev: 0,
st_mode: 0,
st_nlink: 0,
st_ino: 0,
st_uid: 0,
st_gid: 0,
st_rdev: 0,
st_atime: 0,
st_atime_nsec: 0,
st_mtime: 0,
st_mtime_nsec: 0,
st_ctime: 0,
st_ctime_nsec: 0,
st_birthtime: 0,
st_birthtime_nsec: 0,
st_size: 0,
st_blocks: 0,
st_blksize: 0,
st_flags: 0,
st_gen: 0,
st_lspare: 0,
st_qspare: [0, 0],
}
}
}
}
pub mod posix08 {
}
Expand Down Expand Up @@ -1087,6 +1229,7 @@ pub mod types {
use libc::types::os::arch::c95::{c_long, time_t};
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
use libc::types::os::arch::posix88::{mode_t, off_t, uid_t};
use default::Default;

pub type nlink_t = u16;
pub type blksize_t = i64;
Expand Down Expand Up @@ -1116,6 +1259,34 @@ pub mod types {
st_lspare: int32_t,
st_qspare: [int64_t, ..2],
}
impl Default for stat {
fn default() -> stat {
stat {
st_dev: 0,
st_mode: 0,
st_nlink: 0,
st_ino: 0,
st_uid: 0,
st_gid: 0,
st_rdev: 0,
st_atime: 0,
st_atime_nsec: 0,
st_mtime: 0,
st_mtime_nsec: 0,
st_ctime: 0,
st_ctime_nsec: 0,
st_birthtime: 0,
st_birthtime_nsec: 0,
st_size: 0,
st_blocks: 0,
st_blksize: 0,
st_flags: 0,
st_gen: 0,
st_lspare: 0,
st_qspare: [0, 0],
}
}
}
}
pub mod posix08 {
}
Expand Down
Loading