Skip to content

Adding stat support, and other misc cleanup #4008

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

Closed
wants to merge 8 commits into from
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
4 changes: 2 additions & 2 deletions src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub enum Either<T, U> {
Right(U)
}

pub fn either<T, U, V>(f_left: fn((&T)) -> V,
f_right: fn((&U)) -> V, value: &Either<T, U>) -> V {
pub fn either<T, U, V>(f_left: fn(&T) -> V,
f_right: fn(&U) -> V, value: &Either<T, U>) -> V {
/*!
* Applies a function based on the given either value
*
Expand Down
182 changes: 177 additions & 5 deletions src/libcore/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub use types::common::posix88::*;
pub use types::common::posix01::*;
pub use types::common::posix08::*;
pub use types::common::bsd44::*;
pub use types::os::common::posix01::*;
pub use types::os::arch::c95::*;
pub use types::os::arch::c99::*;
pub use types::os::arch::posix88::*;
Expand All @@ -69,12 +70,13 @@ pub use funcs::c95::stdio::*;
pub use funcs::c95::stdlib::*;
pub use funcs::c95::string::*;

pub use funcs::posix88::stat::*;
pub use funcs::posix88::stat_::*;
pub use funcs::posix88::stdio::*;
pub use funcs::posix88::fcntl::*;
pub use funcs::posix88::dirent::*;
pub use funcs::posix88::unistd::*;

pub use funcs::posix01::stat_::*;
pub use funcs::posix01::unistd::*;
pub use funcs::posix08::unistd::*;

Expand Down Expand Up @@ -122,6 +124,8 @@ pub use open, creat;
pub use access, chdir, close, dup, dup2, execv, execve, execvp, getcwd,
getpid, isatty, lseek, pipe, read, rmdir, unlink, write;

pub use fstat, lstat, stat;


mod types {

Expand Down Expand Up @@ -158,6 +162,10 @@ mod types {

#[cfg(target_os = "linux")]
pub mod os {
pub mod common {
pub mod posix01 {}
}

#[cfg(target_arch = "x86")]
pub mod arch {
pub mod c95 {
Expand Down Expand Up @@ -195,7 +203,33 @@ mod types {
pub type mode_t = u32;
pub type ssize_t = i32;
}
pub mod posix01 {}
pub mod posix01 {
pub type nlink_t = u32;
pub type blksize_t = i32;
pub type blkcnt_t = i32;
pub struct stat {
st_dev: dev_t,
__pad1: c_short,
st_ino: ino_t,
st_mode: mode_t,
st_nlink: nlink_t,
st_uid: uid_t,
st_gid: gid_t,
st_rdev: dev_t,
__pad2: c_short,
st_size: off_t,
st_blksize: blksize_t,
st_blocks: blkcnt_t,
st_atime: time_t,
st_atime_nsec: c_long,
st_mtime: time_t,
st_mtime_nsec: c_long,
st_ctime: time_t,
st_ctime_nsec: c_long,
__unused4: c_long,
__unused5: c_long,
}
}
pub mod posix08 {}
pub mod bsd44 {}
pub mod extra {}
Expand Down Expand Up @@ -239,6 +273,29 @@ mod types {
pub type ssize_t = i64;
}
pub mod posix01 {
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,
st_nlink: nlink_t,
st_mode: mode_t,
st_uid: uid_t,
st_gid: gid_t,
__pad0: c_int,
st_rdev: dev_t,
st_size: off_t,
st_blksize: blksize_t,
st_blocks: blkcnt_t,
st_atime: time_t,
st_atime_nsec: c_long,
st_mtime: time_t,
st_mtime_nsec: c_long,
st_ctime: time_t,
st_ctime_nsec: c_long,
__unused: [c_long * 3],
}
}
pub mod posix08 {
}
Expand All @@ -251,6 +308,10 @@ mod types {

#[cfg(target_os = "freebsd")]
pub mod os {
pub mod common {
pub mod posix01 {}
}

#[cfg(target_arch = "x86_64")]
pub mod arch {
pub mod c95 {
Expand Down Expand Up @@ -289,6 +350,34 @@ mod types {
pub type ssize_t = i64;
}
pub mod posix01 {
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,
st_mode: mode_t,
st_nlink: nlink_t,
st_uid: uid_t,
st_gid: gid_t,
st_rdev: dev_t,
st_atime: time_t,
st_atime_nsec: c_long,
st_mtime: time_t,
st_mtime_nsec: c_long,
st_ctime: time_t,
st_ctime_nsec: c_long,
st_size: off_t,
st_blocks: blkcnt_t,
st_blksize: blksize_t,
st_flags: fflags_t,
st_gen: uint32_t,
st_lspare: int32_t,
st_birthtime: time_t,
st_birthtime_nsec: c_long,
__unused: [uint8_t * 2],
}
}
pub mod posix08 {
}
Expand All @@ -301,6 +390,24 @@ mod types {

#[cfg(target_os = "win32")]
pub mod os {
pub mod common {
pub mod posix01 {
pub struct stat {
st_dev: dev_t,
st_ino: ino_t,
st_mode: mode_t,
st_nlink: c_short,
st_uid: c_short,
st_gid: c_short,
st_rdev: dev_t,
st_size: int64_t,
st_atime: time64_t,
st_mtime: time64_t,
st_c_time: time64_t,
}
}
}

#[cfg(target_arch = "x86")]
pub mod arch {
pub mod c95 {
Expand Down Expand Up @@ -378,6 +485,38 @@ mod types {

#[cfg(target_os = "macos")]
pub mod os {
pub mod common {
pub mod posix01 {
pub type nlink_t = u16;
pub type blksize_t = i64;
pub type blkcnt_t = i32;
pub struct stat {
st_dev: dev_t,
st_mode: mode_t,
st_nlink: nlink_t,
st_ino: ino_t,
st_uid: uid_t,
st_gid: gid_t,
st_rdev: dev_t,
st_atime: time_t,
st_atime_nsec: c_long,
st_mtime: time_t,
st_mtime_nsec: c_long,
st_ctime: time_t,
st_ctime_nsec: c_long,
st_birthtime: time_t,
st_birthtime_nsec: c_long,
st_size: off_t,
st_blocks: blkcnt_t,
st_blksize: blksize_t,
st_flags: uint32_t,
st_gen: uint32_t,
st_lspare: int32_t,
st_qspare: [int64_t * 2],
}
}
}

#[cfg(target_arch = "x86")]
pub mod arch {
pub mod c95 {
Expand Down Expand Up @@ -880,7 +1019,7 @@ pub mod funcs {
pub mod posix88 {
#[nolink]
#[abi = "cdecl"]
pub extern mod stat {
pub extern mod stat_ {
#[link_name = "_chmod"]
fn chmod(path: *c_char, mode: c_int) -> c_int;

Expand Down Expand Up @@ -990,11 +1129,28 @@ pub mod funcs {
pub mod posix88 {
#[nolink]
#[abi = "cdecl"]
pub extern mod stat {
pub extern mod stat_ {
fn chmod(path: *c_char, mode: mode_t) -> c_int;
fn fchmod(fd: c_int, mode: mode_t) -> c_int;

#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
fn fstat(fildes: c_int, buf: *mut stat) -> c_int;

#[cfg(target_os = "macos")]
#[link_name = "fstat64"]
fn fstat(fildes: c_int, buf: *mut stat) -> c_int;

fn mkdir(path: *c_char, mode: mode_t) -> c_int;
fn mkfifo(ath: *c_char, mode: mode_t) -> c_int;
fn mkfifo(path: *c_char, mode: mode_t) -> c_int;

#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
fn stat(path: *c_char, buf: *mut stat) -> c_int;

#[cfg(target_os = "macos")]
#[link_name = "stat64"]
fn stat(path: *c_char, buf: *mut stat) -> c_int;
}

#[nolink]
Expand Down Expand Up @@ -1079,6 +1235,18 @@ pub mod funcs {
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod posix01 {
#[nolink]
#[abi = "cdecl"]
pub extern mod stat_ {
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
fn lstat(path: *c_char, buf: *mut stat) -> c_int;

#[cfg(target_os = "macos")]
#[link_name = "lstat64"]
fn lstat(path: *c_char, buf: *mut stat) -> c_int;
}

#[nolink]
#[abi = "cdecl"]
pub extern mod unistd {
Expand Down Expand Up @@ -1106,6 +1274,10 @@ pub mod funcs {

#[cfg(target_os = "win32")]
pub mod posix01 {
#[nolink]
pub extern mod stat_ {
}

#[nolink]
pub extern mod unistd {
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,11 @@ pub fn tmpdir() -> Path {
}
}
/// Recursively walk a directory structure
pub fn walk_dir(p: &Path, f: fn((&Path)) -> bool) {
pub fn walk_dir(p: &Path, f: fn(&Path) -> bool) {

walk_dir_(p, f);

fn walk_dir_(p: &Path, f: fn((&Path)) -> bool) -> bool {
fn walk_dir_(p: &Path, f: fn(&Path) -> bool) -> bool {
let mut keepgoing = true;
do list_dir(p).each |q| {
let path = &p.push(*q);
Expand Down Expand Up @@ -595,7 +595,7 @@ pub fn list_dir(p: &Path) -> ~[~str] {
* This version prepends each entry with the directory.
*/
pub fn list_dir_path(p: &Path) -> ~[~Path] {
os::list_dir(p).map(|f| ~p.push(*f))
list_dir(p).map(|f| ~p.push(*f))
}

/// Removes a directory at the specified path
Expand Down
Loading