diff options
Diffstat (limited to 'src/libstd')
54 files changed, 2274 insertions, 724 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 38f79079b29..8cabdc41a05 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -45,7 +45,7 @@ pub trait AsciiExt { #[stable(feature = "rust1", since = "1.0.0")] type Owned; - /// Checks if within the ASCII range. + /// Checks if the value is within the ASCII range. /// /// # Examples /// @@ -55,8 +55,8 @@ pub trait AsciiExt { /// let ascii = 'a'; /// let utf8 = '❤'; /// - /// assert_eq!(true, ascii.is_ascii()); - /// assert_eq!(false, utf8.is_ascii()) + /// assert!(ascii.is_ascii()); + /// assert!(!utf8.is_ascii()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn is_ascii(&self) -> bool; @@ -114,9 +114,9 @@ pub trait AsciiExt { /// let ascii3 = 'A'; /// let ascii4 = 'z'; /// - /// assert_eq!(true, ascii1.eq_ignore_ascii_case(&ascii2)); - /// assert_eq!(true, ascii1.eq_ignore_ascii_case(&ascii3)); - /// assert_eq!(false, ascii1.eq_ignore_ascii_case(&ascii4)); + /// assert!(ascii1.eq_ignore_ascii_case(&ascii2)); + /// assert!(ascii1.eq_ignore_ascii_case(&ascii3)); + /// assert!(!ascii1.eq_ignore_ascii_case(&ascii4)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn eq_ignore_ascii_case(&self, other: &Self) -> bool; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 586fafc2b4a..7220690469c 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1157,9 +1157,10 @@ impl<K, V, S> HashMap<K, V, S> /// /// If the map did not have this key present, `None` is returned. /// - /// If the map did have this key present, the key is not updated, the - /// value is updated and the old value is returned. - /// See the [module-level documentation] for more. + /// If the map did have this key present, the value is updated, and the old + /// value is returned. The key is not updated, though; this matters for + /// types that can be `==` without being identical. See the [module-level + /// documentation] for more. /// /// [module-level documentation]: index.html#insert-and-complex-keys /// diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 316c7595266..97cab94b67b 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -12,6 +12,7 @@ use alloc::heap::{allocate, deallocate, EMPTY}; use cmp; use hash::{Hash, Hasher, BuildHasher}; +use intrinsics::needs_drop; use marker; use mem::{align_of, size_of}; use mem; @@ -1009,7 +1010,9 @@ impl<K, V> Drop for RawTable<K, V> { // dropping empty tables such as on resize. // Also avoid double drop of elements that have been already moved out. unsafe { - for _ in self.rev_move_buckets() {} + if needs_drop::<(K, V)>() { // avoid linear runtime for types that don't need drop + for _ in self.rev_move_buckets() {} + } } let hashes_size = self.capacity * size_of::<u64>(); diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 417261cf4c3..06c14157606 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -397,12 +397,15 @@ //! } //! //! let mut map = BTreeMap::new(); -//! map.insert(Foo { a: 1, b: "baz" }, ()); +//! map.insert(Foo { a: 1, b: "baz" }, 99); //! //! // We already have a Foo with an a of 1, so this will be updating the value. -//! map.insert(Foo { a: 1, b: "xyz" }, ()); +//! map.insert(Foo { a: 1, b: "xyz" }, 100); //! -//! // ... but the key hasn't changed. b is still "baz", not "xyz" +//! // The value has been updated... +//! assert_eq!(map.values().next().unwrap(), &100); +//! +//! // ...but the key hasn't changed. b is still "baz", not "xyz". //! assert_eq!(map.keys().next().unwrap().b, "baz"); //! ``` diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index d42b9489180..badbba21d55 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -2152,6 +2152,26 @@ mod tests { } #[test] + fn read_link() { + if cfg!(windows) { + // directory symlink + assert_eq!(check!(fs::read_link(r"C:\Users\All Users")).to_str().unwrap(), + r"C:\ProgramData"); + // junction + assert_eq!(check!(fs::read_link(r"C:\Users\Default User")).to_str().unwrap(), + r"C:\Users\Default"); + // junction with special permissions + assert_eq!(check!(fs::read_link(r"C:\Documents and Settings\")).to_str().unwrap(), + r"C:\Users"); + } + let tmpdir = tmpdir(); + let link = tmpdir.join("link"); + if !got_symlink_permission(&tmpdir) { return }; + check!(symlink_file(&"foo", &link)); + assert_eq!(check!(fs::read_link(&link)).to_str().unwrap(), "foo"); + } + + #[test] fn readlink_not_symlink() { let tmpdir = tmpdir(); match fs::read_link(tmpdir.path()) { diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index b7afd12d8e5..d241cd032ed 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -269,9 +269,10 @@ pub mod builtin { /// This macro takes any number of comma-separated identifiers, and /// concatenates them all into one, yielding an expression which is a new /// identifier. Note that hygiene makes it such that this macro cannot - /// capture local variables, and macros are only allowed in item, - /// statement or expression position, meaning this macro may be difficult to - /// use in some situations. + /// capture local variables. Also, as a general rule, macros are only + /// allowed in item, statement or expression position. That means while + /// you may use this macro for referring to existing variables, functions or + /// modules etc, you cannot define a new one with it. /// /// # Examples /// @@ -283,6 +284,8 @@ pub mod builtin { /// /// let f = concat_idents!(foo, bar); /// println!("{}", f()); + /// + /// // fn concat_idents!(new, fun, name) { } // not usable in this way! /// # } /// ``` #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/os/android/fs.rs b/src/libstd/os/android/fs.rs new file mode 100644 index 00000000000..a51b4655985 --- /dev/null +++ b/src/libstd/os/android/fs.rs @@ -0,0 +1,129 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::android::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } +} + diff --git a/src/libstd/os/android/mod.rs b/src/libstd/os/android/mod.rs index 15380dc350e..7cc37769c1e 100644 --- a/src/libstd/os/android/mod.rs +++ b/src/libstd/os/android/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/android/raw.rs b/src/libstd/os/android/raw.rs index e58ba03ec67..ce6e810592c 100644 --- a/src/libstd/os/android/raw.rs +++ b/src/libstd/os/android/raw.rs @@ -11,6 +11,12 @@ //! Android-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; @@ -26,22 +32,22 @@ mod arch { use os::unix::raw::{uid_t, gid_t}; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type dev_t = u32; + pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type mode_t = u16; + pub type mode_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type blkcnt_t = u32; + pub type blkcnt_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type blksize_t = u32; + pub type blksize_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type ino_t = u32; + pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type nlink_t = u16; + pub type nlink_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type off_t = i32; + pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type time_t = i32; + pub type time_t = i64; #[repr(C)] #[derive(Clone)] @@ -52,7 +58,7 @@ mod arch { #[stable(feature = "raw_ext", since = "1.1.0")] pub __pad0: [c_uchar; 4], #[stable(feature = "raw_ext", since = "1.1.0")] - pub __st_ino: ino_t, + pub __st_ino: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mode: c_uint, #[stable(feature = "raw_ext", since = "1.1.0")] @@ -68,19 +74,19 @@ mod arch { #[stable(feature = "raw_ext", since = "1.1.0")] pub st_size: c_longlong, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_blocks: c_ulonglong, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: c_ulong, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_ulong, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: c_ulong, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_ulong, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: c_ulong, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_ulong, #[stable(feature = "raw_ext", since = "1.1.0")] @@ -103,13 +109,13 @@ mod arch { #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type blksize_t = u32; + pub type blksize_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type nlink_t = u32; + pub type nlink_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] - pub type off_t = i64; + pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; diff --git a/src/libstd/os/bitrig/fs.rs b/src/libstd/os/bitrig/fs.rs new file mode 100644 index 00000000000..e4f1c9432f3 --- /dev/null +++ b/src/libstd/os/bitrig/fs.rs @@ -0,0 +1,149 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::bitrig::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_flags(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gen(&self) -> u32; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_birthtime(&self) -> i64 { + self.as_inner().as_inner().st_birthtime as i64 + } + fn st_birthtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } + fn st_gen(&self) -> u32 { + self.as_inner().as_inner().st_gen as u32 + } + fn st_flags(&self) -> u32 { + self.as_inner().as_inner().st_flags as u32 + } +} + diff --git a/src/libstd/os/bitrig/mod.rs b/src/libstd/os/bitrig/mod.rs index 126eab92fe3..fb58818a5ba 100644 --- a/src/libstd/os/bitrig/mod.rs +++ b/src/libstd/os/bitrig/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/bitrig/raw.rs b/src/libstd/os/bitrig/raw.rs index 81de8810cba..3fc3c5937f4 100644 --- a/src/libstd/os/bitrig/raw.rs +++ b/src/libstd/os/bitrig/raw.rs @@ -11,18 +11,24 @@ //! Bitrig-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; use os::unix::raw::{uid_t, gid_t}; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = i32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; @@ -32,43 +38,43 @@ use os::unix::raw::{uid_t, gid_t}; #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_dev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime_nsec: c_long, + pub st_atime_nsec: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime_nsec: c_long, + pub st_mtime_nsec: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime_nsec: c_long, + pub st_ctime_nsec: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_flags: fflags_t, + pub st_flags: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_gen: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime: time_t, + pub st_birthtime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime_nsec: c_long, + pub st_birthtime_nsec: i64, } diff --git a/src/libstd/os/dragonfly/fs.rs b/src/libstd/os/dragonfly/fs.rs new file mode 100644 index 00000000000..eb09800a18c --- /dev/null +++ b/src/libstd/os/dragonfly/fs.rs @@ -0,0 +1,154 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::dragonfly::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_flags(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gen(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_lspare(&self) -> u32; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_birthtime(&self) -> i64 { + self.as_inner().as_inner().st_birthtime as i64 + } + fn st_birthtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } + fn st_gen(&self) -> u32 { + self.as_inner().as_inner().st_gen as u32 + } + fn st_flags(&self) -> u32 { + self.as_inner().as_inner().st_flags as u32 + } + fn st_lspare(&self) -> u32 { + self.as_inner().as_inner().st_lspare as u32 + } +} + diff --git a/src/libstd/os/dragonfly/mod.rs b/src/libstd/os/dragonfly/mod.rs index b48604fa83f..645561823fc 100644 --- a/src/libstd/os/dragonfly/mod.rs +++ b/src/libstd/os/dragonfly/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/dragonfly/raw.rs b/src/libstd/os/dragonfly/raw.rs index 581aebebc03..83e0be0d158 100644 --- a/src/libstd/os/dragonfly/raw.rs +++ b/src/libstd/os/dragonfly/raw.rs @@ -11,18 +11,23 @@ //! Dragonfly-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; -use os::unix::raw::{uid_t, gid_t}; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; @@ -32,47 +37,45 @@ use os::unix::raw::{uid_t, gid_t}; #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_dev: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_ino: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_mode: u16, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_nlink: u16, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_padding1: u16, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_rdev: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_flags: fflags_t, + pub st_flags: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_gen: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_lspare: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_qspare1: i64, + pub st_birthtime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_qspare2: i64, + pub st_birthtime_nsec: c_long, } diff --git a/src/libstd/os/freebsd/fs.rs b/src/libstd/os/freebsd/fs.rs new file mode 100644 index 00000000000..2f17d2f7409 --- /dev/null +++ b/src/libstd/os/freebsd/fs.rs @@ -0,0 +1,154 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::freebsd::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_flags(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gen(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_lspare(&self) -> u32; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_birthtime(&self) -> i64 { + self.as_inner().as_inner().st_birthtime as i64 + } + fn st_birthtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } + fn st_gen(&self) -> u32 { + self.as_inner().as_inner().st_gen as u32 + } + fn st_flags(&self) -> u32 { + self.as_inner().as_inner().st_flags as u32 + } + fn st_lspare(&self) -> u32 { + self.as_inner().as_inner().st_lspare as u32 + } +} + diff --git a/src/libstd/os/freebsd/mod.rs b/src/libstd/os/freebsd/mod.rs index b1d61f8ae12..ce7b91ea41c 100644 --- a/src/libstd/os/freebsd/mod.rs +++ b/src/libstd/os/freebsd/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/freebsd/raw.rs b/src/libstd/os/freebsd/raw.rs index a1e39721bcf..989eef63d82 100644 --- a/src/libstd/os/freebsd/raw.rs +++ b/src/libstd/os/freebsd/raw.rs @@ -11,135 +11,74 @@ //! FreeBSD-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; +use os::raw::c_long; + +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; -#[doc(inline)] +#[repr(C)] +#[derive(Clone)] #[stable(feature = "raw_ext", since = "1.1.0")] -pub use self::arch::{stat, time_t}; - -#[cfg(target_arch = "x86")] -mod arch { - use super::{off_t, dev_t, ino_t, mode_t, nlink_t, blksize_t, blkcnt_t, fflags_t}; - use os::raw::c_long; - use os::unix::raw::{uid_t, gid_t}; - - #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32; - - #[repr(C)] - #[derive(Clone)] - #[stable(feature = "raw_ext", since = "1.1.0")] - pub struct stat { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime_nsec: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime_nsec: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime_nsec: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_flags: fflags_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gen: u32, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_lspare: i32, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime_nsec: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub __unused: [u8; 8], - } -} - -#[cfg(target_arch = "x86_64")] -mod arch { - use super::{off_t, dev_t, ino_t, mode_t, nlink_t, blksize_t, blkcnt_t, fflags_t}; - use os::raw::c_long; - use os::unix::raw::{uid_t, gid_t}; - - #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; - - #[repr(C)] - #[derive(Clone)] - #[stable(feature = "raw_ext", since = "1.1.0")] - pub struct stat { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime_nsec: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime_nsec: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime_nsec: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_flags: fflags_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gen: u32, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_lspare: i32, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime_nsec: c_long, - } +pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u16, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u16, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_flags: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gen: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_lspare: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_birthtime: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_birthtime_nsec: c_long, + #[cfg(target_arch = "x86")] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __unused: [u8; 8], } - diff --git a/src/libstd/os/ios/fs.rs b/src/libstd/os/ios/fs.rs new file mode 100644 index 00000000000..275daf3d3a0 --- /dev/null +++ b/src/libstd/os/ios/fs.rs @@ -0,0 +1,154 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::ios::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_flags(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gen(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_lspare(&self) -> u32; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_birthtime(&self) -> i64 { + self.as_inner().as_inner().st_birthtime as i64 + } + fn st_birthtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } + fn st_gen(&self) -> u32 { + self.as_inner().as_inner().st_gen as u32 + } + fn st_flags(&self) -> u32 { + self.as_inner().as_inner().st_flags as u32 + } + fn st_lspare(&self) -> u32 { + self.as_inner().as_inner().st_lspare as u32 + } +} + diff --git a/src/libstd/os/ios/mod.rs b/src/libstd/os/ios/mod.rs index 07fba4b182b..4cad23389d0 100644 --- a/src/libstd/os/ios/mod.rs +++ b/src/libstd/os/ios/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/ios/raw.rs b/src/libstd/os/ios/raw.rs index 20fe833a980..5a2de14b28b 100644 --- a/src/libstd/os/ios/raw.rs +++ b/src/libstd/os/ios/raw.rs @@ -11,18 +11,23 @@ //! iOS-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; -use os::unix::raw::{uid_t, gid_t}; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = i32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; @@ -31,41 +36,41 @@ use os::unix::raw::{uid_t, gid_t}; #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_dev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u16, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u16, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime: time_t, + pub st_birthtime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_birthtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_flags: u32, #[stable(feature = "raw_ext", since = "1.1.0")] diff --git a/src/libstd/os/linux/fs.rs b/src/libstd/os/linux/fs.rs new file mode 100644 index 00000000000..11c41816cec --- /dev/null +++ b/src/libstd/os/linux/fs.rs @@ -0,0 +1,128 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::linux::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat64 + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } +} diff --git a/src/libstd/os/linux/mod.rs b/src/libstd/os/linux/mod.rs index ea0b00c9998..8ec44b9fae4 100644 --- a/src/libstd/os/linux/mod.rs +++ b/src/libstd/os/linux/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/linux/raw.rs b/src/libstd/os/linux/raw.rs index 10d37f9f597..4113966841b 100644 --- a/src/libstd/os/linux/raw.rs +++ b/src/libstd/os/linux/raw.rs @@ -11,6 +11,12 @@ //! Linux-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_ulong; @@ -29,92 +35,79 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t}; target_arch = "arm", target_arch = "asmjs"))] mod arch { - use super::{dev_t, mode_t}; - use os::raw::{c_long, c_short}; - use os::unix::raw::{gid_t, uid_t}; + use os::raw::{c_long, c_short, c_uint}; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; - - #[stable(feature = "raw_ext", since = "1.1.0")] - #[cfg(not(any(target_env = "musl", target_arch = "asmjs")))] - pub type ino_t = u32; - #[stable(feature = "raw_ext", since = "1.1.0")] - #[cfg(any(target_env = "musl", target_arch = "asmjs"))] - pub type ino_t = u64; - - #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[repr(C)] #[derive(Clone)] #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_dev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] pub __pad1: c_short, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub __st_ino: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub __pad2: c_short, + pub __pad2: c_uint, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub __unused4: c_long, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub __unused5: c_long, + pub st_ino: u64, } } #[cfg(target_arch = "mips")] mod arch { - use super::mode_t; use os::raw::{c_long, c_ulong}; - use os::unix::raw::{gid_t, uid_t}; #[cfg(target_env = "musl")] #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; #[cfg(not(target_env = "musl"))] - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; #[cfg(target_env = "musl")] #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[cfg(not(target_env = "musl"))] - #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; #[cfg(target_env = "musl")] - #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[cfg(not(target_env = "musl"))] - #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[repr(C)] #[derive(Clone)] @@ -125,39 +118,37 @@ mod arch { #[stable(feature = "raw_ext", since = "1.1.0")] pub st_pad1: [c_long; 3], #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_rdev: c_ulong, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_pad2: [c_long; 2], #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, - #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_pad3: c_long, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_pad5: [c_long; 14], } @@ -165,15 +156,13 @@ mod arch { #[cfg(target_arch = "aarch64")] mod arch { - use super::{dev_t, mode_t}; use os::raw::{c_long, c_int}; - use os::unix::raw::{gid_t, uid_t}; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[repr(C)] @@ -181,39 +170,39 @@ mod arch { #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_dev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub __pad1: dev_t, + pub __pad1: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub __pad2: c_int, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] @@ -223,15 +212,13 @@ mod arch { #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64"))] mod arch { - use super::{dev_t, mode_t}; use os::raw::{c_long, c_int}; - use os::unix::raw::{gid_t, uid_t}; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; - #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[repr(C)] @@ -239,37 +226,37 @@ mod arch { #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_dev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub __pad0: c_int, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] diff --git a/src/libstd/os/macos/fs.rs b/src/libstd/os/macos/fs.rs new file mode 100644 index 00000000000..12b44901d03 --- /dev/null +++ b/src/libstd/os/macos/fs.rs @@ -0,0 +1,160 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::macos::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_flags(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gen(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_lspare(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_qspare(&self) -> [u64; 2]; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_birthtime(&self) -> i64 { + self.as_inner().as_inner().st_birthtime as i64 + } + fn st_birthtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } + fn st_gen(&self) -> u32 { + self.as_inner().as_inner().st_gen as u32 + } + fn st_flags(&self) -> u32 { + self.as_inner().as_inner().st_flags as u32 + } + fn st_lspare(&self) -> u32 { + self.as_inner().as_inner().st_lspare as u32 + } + fn st_qspare(&self) -> [u64; 2] { + let qspare = self.as_inner().as_inner().st_qspare; + [qspare[0] as u64, qspare[1] as u64] + } +} + diff --git a/src/libstd/os/macos/mod.rs b/src/libstd/os/macos/mod.rs index 703b64ceb24..4e995358fd8 100644 --- a/src/libstd/os/macos/mod.rs +++ b/src/libstd/os/macos/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/macos/raw.rs b/src/libstd/os/macos/raw.rs index 1407132b9c9..2148670ccbd 100644 --- a/src/libstd/os/macos/raw.rs +++ b/src/libstd/os/macos/raw.rs @@ -11,18 +11,23 @@ //! MacOS-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; -use os::unix::raw::{uid_t, gid_t}; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = i32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u16; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; @@ -31,41 +36,41 @@ use os::unix::raw::{uid_t, gid_t}; #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_dev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u16, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u16, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime: time_t, + pub st_birthtime: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_birthtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_flags: u32, #[stable(feature = "raw_ext", since = "1.1.0")] diff --git a/src/libstd/os/nacl/fs.rs b/src/libstd/os/nacl/fs.rs new file mode 100644 index 00000000000..3e0fb44b01e --- /dev/null +++ b/src/libstd/os/nacl/fs.rs @@ -0,0 +1,128 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::nacl::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat64 + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } +} diff --git a/src/libstd/os/nacl/mod.rs b/src/libstd/os/nacl/mod.rs index b87ee4beb2c..7dfa2eabe3e 100644 --- a/src/libstd/os/nacl/mod.rs +++ b/src/libstd/os/nacl/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/nacl/raw.rs b/src/libstd/os/nacl/raw.rs index 7258a14aaf4..9a10fbcc30b 100644 --- a/src/libstd/os/nacl/raw.rs +++ b/src/libstd/os/nacl/raw.rs @@ -11,18 +11,24 @@ //! Nacl-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] -#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type pid_t = i32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type uid_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type gid_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; diff --git a/src/libstd/os/netbsd/fs.rs b/src/libstd/os/netbsd/fs.rs new file mode 100644 index 00000000000..f11e23138b0 --- /dev/null +++ b/src/libstd/os/netbsd/fs.rs @@ -0,0 +1,154 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::netbsd::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_flags(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gen(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_spare(&self) -> u32; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_birthtime(&self) -> i64 { + self.as_inner().as_inner().st_birthtime as i64 + } + fn st_birthtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } + fn st_gen(&self) -> u32 { + self.as_inner().as_inner().st_gen as u32 + } + fn st_flags(&self) -> u32 { + self.as_inner().as_inner().st_flags as u32 + } + fn st_spare(&self) -> u32 { + self.as_inner().as_inner().st_spare as u32 + } +} + diff --git a/src/libstd/os/netbsd/mod.rs b/src/libstd/os/netbsd/mod.rs index ff6f76ba1d5..06efbd83707 100644 --- a/src/libstd/os/netbsd/mod.rs +++ b/src/libstd/os/netbsd/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/netbsd/raw.rs b/src/libstd/os/netbsd/raw.rs index 9ca58924955..7eb3f6d47d1 100644 --- a/src/libstd/os/netbsd/raw.rs +++ b/src/libstd/os/netbsd/raw.rs @@ -11,18 +11,24 @@ //! NetBSD-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; use os::unix::raw::{uid_t, gid_t}; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; @@ -32,43 +38,43 @@ use os::unix::raw::{uid_t, gid_t}; #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_dev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_mode: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime: time_t, + pub st_birthtime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_birthtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_flags: fflags_t, + pub st_flags: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_gen: u32, st_spare: [u32; 2], diff --git a/src/libstd/os/openbsd/fs.rs b/src/libstd/os/openbsd/fs.rs new file mode 100644 index 00000000000..cc812fcf12c --- /dev/null +++ b/src/libstd/os/openbsd/fs.rs @@ -0,0 +1,149 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::openbsd::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_birthtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_flags(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gen(&self) -> u32; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_birthtime(&self) -> i64 { + self.as_inner().as_inner().st_birthtime as i64 + } + fn st_birthtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } + fn st_gen(&self) -> u32 { + self.as_inner().as_inner().st_gen as u32 + } + fn st_flags(&self) -> u32 { + self.as_inner().as_inner().st_flags as u32 + } +} + diff --git a/src/libstd/os/openbsd/mod.rs b/src/libstd/os/openbsd/mod.rs index ff6f76ba1d5..06efbd83707 100644 --- a/src/libstd/os/openbsd/mod.rs +++ b/src/libstd/os/openbsd/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/openbsd/raw.rs b/src/libstd/os/openbsd/raw.rs index b4d49395303..0e9a2128bc2 100644 --- a/src/libstd/os/openbsd/raw.rs +++ b/src/libstd/os/openbsd/raw.rs @@ -11,18 +11,23 @@ //! OpenBSD-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; -use os::unix::raw::{uid_t, gid_t}; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = i32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; @@ -32,43 +37,43 @@ use os::unix::raw::{uid_t, gid_t}; #[stable(feature = "raw_ext", since = "1.1.0")] pub struct stat { #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mode: mode_t, + pub st_mode: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_dev: dev_t, + pub st_dev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ino: ino_t, + pub st_ino: u64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_nlink: nlink_t, + pub st_nlink: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_uid: uid_t, + pub st_uid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_gid: gid_t, + pub st_gid: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_rdev: dev_t, + pub st_rdev: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_atime: time_t, + pub st_atime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_mtime: time_t, + pub st_mtime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_ctime: time_t, + pub st_ctime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: c_long, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_size: off_t, + pub st_size: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blocks: blkcnt_t, + pub st_blocks: i64, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_blksize: blksize_t, + pub st_blksize: i32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_flags: fflags_t, + pub st_flags: u32, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_gen: u32, #[stable(feature = "raw_ext", since = "1.1.0")] - pub st_birthtime: time_t, + pub st_birthtime: i64, #[stable(feature = "raw_ext", since = "1.1.0")] pub st_birthtime_nsec: c_long, } diff --git a/src/libstd/os/raw.rs b/src/libstd/os/raw.rs index 4200e105cea..55d8ad17460 100644 --- a/src/libstd/os/raw.rs +++ b/src/libstd/os/raw.rs @@ -81,36 +81,10 @@ mod tests { )*} } - macro_rules! ok_size { - ($($t:ident)*) => {$( - assert!(mem::size_of::<libc::$t>() == mem::size_of::<raw::$t>(), - "{} is wrong", stringify!($t)); - )*} - } - #[test] fn same() { use os::raw; ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_float c_double); } - - #[cfg(all(unix, not(target_os = "android")))] - #[test] - fn unix() { - { - use os::unix::raw; - ok!(uid_t gid_t dev_t ino_t mode_t nlink_t off_t blksize_t blkcnt_t); - } - { - use sys::platform::raw; - ok_size!(stat); - } - } - - #[cfg(windows)] - #[test] - fn windows() { - use os::windows::raw; - } } diff --git a/src/libstd/os/solaris/fs.rs b/src/libstd/os/solaris/fs.rs new file mode 100644 index 00000000000..1c043af735a --- /dev/null +++ b/src/libstd/os/solaris/fs.rs @@ -0,0 +1,128 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::solaris::raw; + +/// OS-specific extension methods for `fs::Metadata` +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned `stat` are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime_nsec(&self) -> i64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat64 + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_nsec as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } +} diff --git a/src/libstd/os/solaris/mod.rs b/src/libstd/os/solaris/mod.rs index f265233bd54..1e0166947bf 100644 --- a/src/libstd/os/solaris/mod.rs +++ b/src/libstd/os/solaris/mod.rs @@ -13,9 +13,4 @@ #![stable(feature = "raw_ext", since = "1.1.0")] pub mod raw; - -#[stable(feature = "raw_ext", since = "1.1.0")] -pub mod fs { - #[stable(feature = "raw_ext", since = "1.1.0")] - pub use sys::fs::MetadataExt; -} +pub mod fs; diff --git a/src/libstd/os/solaris/raw.rs b/src/libstd/os/solaris/raw.rs index cf46ae4a360..6a75b36bd6b 100644 --- a/src/libstd/os/solaris/raw.rs +++ b/src/libstd/os/solaris/raw.rs @@ -11,18 +11,24 @@ //! Solaris-specific raw type definitions #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] use os::raw::c_long; use os::unix::raw::{uid_t, gid_t}; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; #[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 83df54f1830..69a1b57a0c5 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -193,6 +193,12 @@ impl<T> AssertRecoverSafe<T> { pub fn new(t: T) -> AssertRecoverSafe<T> { AssertRecoverSafe(t) } + + /// Consumes the `AssertRecoverSafe`, returning the wrapped value. + #[unstable(feature = "recover", reason = "awaiting feedback", issue = "27719")] + pub fn into_inner(self) -> T { + self.0 + } } impl<T> Deref for AssertRecoverSafe<T> { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 10ecaed3aef..3798fb76ad6 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1582,8 +1582,10 @@ impl Path { /// Returns a path that, when joined onto `base`, yields `self`. /// + /// # Errors + /// /// If `base` is not a prefix of `self` (i.e. `starts_with` - /// returns false), then `relative_from` returns `None`. + /// returns `false`), returns `Err`. #[stable(since = "1.7.0", feature = "path_strip_prefix")] pub fn strip_prefix<'a, P: ?Sized>(&'a self, base: &'a P) -> Result<&'a Path, StripPrefixError> diff --git a/src/libstd/prelude/mod.rs b/src/libstd/prelude/mod.rs index a0db471dece..ebd299efa78 100644 --- a/src/libstd/prelude/mod.rs +++ b/src/libstd/prelude/mod.rs @@ -55,7 +55,7 @@ //! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`]}. The marker //! traits indicate fundamental properties of types. //! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}. Various -//! operations for both destuctors and overloading `()`. +//! operations for both destructors and overloading `()`. //! * [`std::mem`]::[`drop`], a convenience function for explicitly dropping a //! value. //! * [`std::boxed`]::[`Box`], a way to allocate values on the heap. diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index ad93fe0094a..b840e51873e 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -50,18 +50,21 @@ mod prim_bool { } /// [`String`]: string/struct.String.html /// /// As always, remember that a human intuition for 'character' may not map to -/// Unicode's definitions. For example, emoji symbols such as '❤️' are more than -/// one byte; ❤️ in particular is six: +/// Unicode's definitions. For example, emoji symbols such as '❤️' can be more +/// than one Unicode code point; this ❤️ in particular is two: /// /// ``` /// let s = String::from("❤️"); /// -/// // six bytes times one byte for each element -/// assert_eq!(6, s.len() * std::mem::size_of::<u8>()); +/// // we get two chars out of a single ❤️ +/// let mut iter = s.chars(); +/// assert_eq!(Some('\u{2764}'), iter.next()); +/// assert_eq!(Some('\u{fe0f}'), iter.next()); +/// assert_eq!(None, iter.next()); /// ``` /// -/// This also means it won't fit into a `char`, and so trying to create a -/// literal with `let heart = '❤️';` gives an error: +/// This means it won't fit into a `char`. Trying to create a literal with +/// `let heart = '❤️';` gives an error: /// /// ```text /// error: character literal may only contain one codepoint: '❤ @@ -69,8 +72,8 @@ mod prim_bool { } /// ^~ /// ``` /// -/// Another implication of this is that if you want to do per-`char`acter -/// processing, it can end up using a lot more memory: +/// Another implication of the 4-byte fixed size of a `char`, is that +/// per-`char`acter processing can end up using a lot more memory: /// /// ``` /// let s = String::from("love: ❤️"); @@ -79,19 +82,6 @@ mod prim_bool { } /// assert_eq!(12, s.len() * std::mem::size_of::<u8>()); /// assert_eq!(32, v.len() * std::mem::size_of::<char>()); /// ``` -/// -/// Or may give you results you may not expect: -/// -/// ``` -/// let s = String::from("❤️"); -/// -/// let mut iter = s.chars(); -/// -/// // we get two chars out of a single ❤️ -/// assert_eq!(Some('\u{2764}'), iter.next()); -/// assert_eq!(Some('\u{fe0f}'), iter.next()); -/// assert_eq!(None, iter.next()); -/// ``` mod prim_char { } #[doc(primitive = "unit")] diff --git a/src/libstd/sys/common/poison.rs b/src/libstd/sys/common/poison.rs index 2cfa04c843b..d858c002755 100644 --- a/src/libstd/sys/common/poison.rs +++ b/src/libstd/sys/common/poison.rs @@ -111,7 +111,7 @@ impl<T> fmt::Display for PoisonError<T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Send + Reflect> Error for PoisonError<T> { +impl<T: Reflect> Error for PoisonError<T> { fn description(&self) -> &str { "poisoned lock: another task failed inside" } @@ -158,14 +158,17 @@ impl<T> fmt::Debug for TryLockError<T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Send + Reflect> fmt::Display for TryLockError<T> { +impl<T> fmt::Display for TryLockError<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.description().fmt(f) + match *self { + TryLockError::Poisoned(..) => "poisoned lock: another task failed inside", + TryLockError::WouldBlock => "try_lock failed because the operation would block" + }.fmt(f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Send + Reflect> Error for TryLockError<T> { +impl<T: Reflect> Error for TryLockError<T> { fn description(&self) -> &str { match *self { TryLockError::Poisoned(ref p) => p.description(), diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 2a3117864d0..bdde25648ed 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -15,69 +15,88 @@ use fs::{self, Permissions, OpenOptions}; use io; use libc; -use os::raw::c_long; +#[allow(deprecated)] use os::unix::raw; use path::Path; -use sys::fs::MetadataExt as UnixMetadataExt; use sys; use sys_common::{FromInner, AsInner, AsInnerMut}; +use sys::platform::fs::MetadataExt as UnixMetadataExt; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const USER_READ: raw::mode_t = 0o400; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const USER_WRITE: raw::mode_t = 0o200; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const USER_EXECUTE: raw::mode_t = 0o100; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const USER_RWX: raw::mode_t = 0o700; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const GROUP_READ: raw::mode_t = 0o040; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const GROUP_WRITE: raw::mode_t = 0o020; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const GROUP_EXECUTE: raw::mode_t = 0o010; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const GROUP_RWX: raw::mode_t = 0o070; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const OTHER_READ: raw::mode_t = 0o004; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const OTHER_WRITE: raw::mode_t = 0o002; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const OTHER_EXECUTE: raw::mode_t = 0o001; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const OTHER_RWX: raw::mode_t = 0o007; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const ALL_READ: raw::mode_t = 0o444; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const ALL_WRITE: raw::mode_t = 0o222; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const ALL_EXECUTE: raw::mode_t = 0o111; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const ALL_RWX: raw::mode_t = 0o777; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const SETUID: raw::mode_t = 0o4000; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const SETGID: raw::mode_t = 0o2000; #[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] #[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] +#[allow(deprecated)] pub const STICKY_BIT: raw::mode_t = 0o1000; /// Unix-specific extensions to `Permissions` @@ -86,28 +105,30 @@ pub trait PermissionsExt { /// Returns the underlying raw `mode_t` bits that are the standard Unix /// permissions for this file. #[stable(feature = "fs_ext", since = "1.1.0")] - fn mode(&self) -> raw::mode_t; + fn mode(&self) -> u32; - /// Sets the underlying raw `mode_t` bits for this set of permissions. + /// Sets the underlying raw bits for this set of permissions. #[stable(feature = "fs_ext", since = "1.1.0")] - fn set_mode(&mut self, mode: raw::mode_t); + fn set_mode(&mut self, mode: u32); /// Creates a new instance of `Permissions` from the given set of Unix /// permission bits. #[stable(feature = "fs_ext", since = "1.1.0")] - fn from_mode(mode: raw::mode_t) -> Self; + fn from_mode(mode: u32) -> Self; } #[stable(feature = "fs_ext", since = "1.1.0")] impl PermissionsExt for Permissions { - fn mode(&self) -> raw::mode_t { self.as_inner().mode() } + fn mode(&self) -> u32 { + self.as_inner().mode() + } - fn set_mode(&mut self, mode: raw::mode_t) { - *self = FromInner::from_inner(FromInner::from_inner(mode)); + fn set_mode(&mut self, mode: u32) { + *self = Permissions::from_inner(FromInner::from_inner(mode)); } - fn from_mode(mode: raw::mode_t) -> Permissions { - FromInner::from_inner(FromInner::from_inner(mode)) + fn from_mode(mode: u32) -> Permissions { + Permissions::from_inner(FromInner::from_inner(mode)) } } @@ -122,7 +143,7 @@ pub trait OpenOptionsExt { /// The operating system masks out bits with the systems `umask`, to produce /// the final permissions. #[stable(feature = "fs_ext", since = "1.1.0")] - fn mode(&mut self, mode: raw::mode_t) -> &mut Self; + fn mode(&mut self, mode: u32) -> &mut Self; /// Pass custom flags to the `flags` agument of `open`. /// @@ -154,7 +175,7 @@ pub trait OpenOptionsExt { #[stable(feature = "fs_ext", since = "1.1.0")] impl OpenOptionsExt for OpenOptions { - fn mode(&mut self, mode: raw::mode_t) -> &mut OpenOptions { + fn mode(&mut self, mode: u32) -> &mut OpenOptions { self.as_inner_mut().mode(mode); self } @@ -173,62 +194,57 @@ impl OpenOptionsExt for OpenOptions { #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { #[stable(feature = "metadata_ext", since = "1.1.0")] - fn dev(&self) -> raw::dev_t; + fn dev(&self) -> u64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn ino(&self) -> raw::ino_t; + fn ino(&self) -> u64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn mode(&self) -> raw::mode_t; + fn mode(&self) -> u32; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn nlink(&self) -> raw::nlink_t; + fn nlink(&self) -> u64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn uid(&self) -> raw::uid_t; + fn uid(&self) -> u32; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn gid(&self) -> raw::gid_t; + fn gid(&self) -> u32; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn rdev(&self) -> raw::dev_t; + fn rdev(&self) -> u64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn size(&self) -> raw::off_t; + fn size(&self) -> u64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn atime(&self) -> raw::time_t; + fn atime(&self) -> i64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn atime_nsec(&self) -> c_long; + fn atime_nsec(&self) -> i64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn mtime(&self) -> raw::time_t; + fn mtime(&self) -> i64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn mtime_nsec(&self) -> c_long; + fn mtime_nsec(&self) -> i64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn ctime(&self) -> raw::time_t; + fn ctime(&self) -> i64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn ctime_nsec(&self) -> c_long; + fn ctime_nsec(&self) -> i64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn blksize(&self) -> raw::blksize_t; + fn blksize(&self) -> u64; #[stable(feature = "metadata_ext", since = "1.1.0")] - fn blocks(&self) -> raw::blkcnt_t; + fn blocks(&self) -> u64; } #[stable(feature = "metadata_ext", since = "1.1.0")] impl MetadataExt for fs::Metadata { - fn dev(&self) -> raw::dev_t { self.as_raw_stat().st_dev as raw::dev_t } - fn ino(&self) -> raw::ino_t { self.as_raw_stat().st_ino as raw::ino_t } - fn mode(&self) -> raw::mode_t { self.as_raw_stat().st_mode as raw::mode_t } - fn nlink(&self) -> raw::nlink_t { self.as_raw_stat().st_nlink as raw::nlink_t } - fn uid(&self) -> raw::uid_t { self.as_raw_stat().st_uid as raw::uid_t } - fn gid(&self) -> raw::gid_t { self.as_raw_stat().st_gid as raw::gid_t } - fn rdev(&self) -> raw::dev_t { self.as_raw_stat().st_rdev as raw::dev_t } - fn size(&self) -> raw::off_t { self.as_raw_stat().st_size as raw::off_t } - fn atime(&self) -> raw::time_t { self.as_raw_stat().st_atime } - fn atime_nsec(&self) -> c_long { self.as_raw_stat().st_atime_nsec as c_long } - fn mtime(&self) -> raw::time_t { self.as_raw_stat().st_mtime } - fn mtime_nsec(&self) -> c_long { self.as_raw_stat().st_mtime_nsec as c_long } - fn ctime(&self) -> raw::time_t { self.as_raw_stat().st_ctime } - fn ctime_nsec(&self) -> c_long { self.as_raw_stat().st_ctime_nsec as c_long } - - fn blksize(&self) -> raw::blksize_t { - self.as_raw_stat().st_blksize as raw::blksize_t - } - fn blocks(&self) -> raw::blkcnt_t { - self.as_raw_stat().st_blocks as raw::blkcnt_t - } + fn dev(&self) -> u64 { self.st_dev() } + fn ino(&self) -> u64 { self.st_ino() } + fn mode(&self) -> u32 { self.st_mode() } + fn nlink(&self) -> u64 { self.st_nlink() } + fn uid(&self) -> u32 { self.st_uid() } + fn gid(&self) -> u32 { self.st_gid() } + fn rdev(&self) -> u64 { self.st_rdev() } + fn size(&self) -> u64 { self.st_size() } + fn atime(&self) -> i64 { self.st_atime() } + fn atime_nsec(&self) -> i64 { self.st_atime_nsec() } + fn mtime(&self) -> i64 { self.st_mtime() } + fn mtime_nsec(&self) -> i64 { self.st_mtime_nsec() } + fn ctime(&self) -> i64 { self.st_ctime() } + fn ctime_nsec(&self) -> i64 { self.st_ctime_nsec() } + fn blksize(&self) -> u64 { self.st_blksize() } + fn blocks(&self) -> u64 { self.st_blocks() } } /// Add special unix types (block/char device, fifo and socket) @@ -262,12 +278,12 @@ pub trait DirEntryExt { /// Returns the underlying `d_ino` field in the contained `dirent` /// structure. #[stable(feature = "dir_entry_ext", since = "1.1.0")] - fn ino(&self) -> raw::ino_t; + fn ino(&self) -> u64; } #[stable(feature = "dir_entry_ext", since = "1.1.0")] impl DirEntryExt for fs::DirEntry { - fn ino(&self) -> raw::ino_t { self.as_inner().ino() } + fn ino(&self) -> u64 { self.as_inner().ino() } } /// Creates a new symbolic link on the filesystem. @@ -305,12 +321,12 @@ pub trait DirBuilderExt { /// Sets the mode to create new directories with. This option defaults to /// 0o777. #[stable(feature = "dir_builder", since = "1.6.0")] - fn mode(&mut self, mode: raw::mode_t) -> &mut Self; + fn mode(&mut self, mode: u32) -> &mut Self; } #[stable(feature = "dir_builder", since = "1.6.0")] impl DirBuilderExt for fs::DirBuilder { - fn mode(&mut self, mode: raw::mode_t) -> &mut fs::DirBuilder { + fn mode(&mut self, mode: u32) -> &mut fs::DirBuilder { self.as_inner_mut().set_mode(mode); self } diff --git a/src/libstd/sys/unix/ext/process.rs b/src/libstd/sys/unix/ext/process.rs index fa19a2620ba..8cc291d00ee 100644 --- a/src/libstd/sys/unix/ext/process.rs +++ b/src/libstd/sys/unix/ext/process.rs @@ -16,7 +16,6 @@ use prelude::v1::*; use io; use os::unix::io::{FromRawFd, RawFd, AsRawFd, IntoRawFd}; -use os::unix::raw::{uid_t, gid_t}; use process; use sys; use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner}; @@ -28,12 +27,12 @@ pub trait CommandExt { /// `setuid` call in the child process. Failure in the `setuid` /// call will cause the spawn to fail. #[stable(feature = "rust1", since = "1.0.0")] - fn uid(&mut self, id: uid_t) -> &mut process::Command; + fn uid(&mut self, id: u32) -> &mut process::Command; /// Similar to `uid`, but sets the group id of the child process. This has /// the same semantics as the `uid` field. #[stable(feature = "rust1", since = "1.0.0")] - fn gid(&mut self, id: gid_t) -> &mut process::Command; + fn gid(&mut self, id: u32) -> &mut process::Command; /// Create a new session (cf. `setsid(2)`) for the child process. This means /// that the child is the leader of a new process group. The parent process @@ -101,12 +100,12 @@ pub trait CommandExt { #[stable(feature = "rust1", since = "1.0.0")] impl CommandExt for process::Command { - fn uid(&mut self, id: uid_t) -> &mut process::Command { + fn uid(&mut self, id: u32) -> &mut process::Command { self.as_inner_mut().uid(id); self } - fn gid(&mut self, id: gid_t) -> &mut process::Command { + fn gid(&mut self, id: u32) -> &mut process::Command { self.as_inner_mut().gid(id); self } diff --git a/src/libstd/sys/unix/ext/raw.rs b/src/libstd/sys/unix/ext/raw.rs index d1cc6cba51d..96535e88604 100644 --- a/src/libstd/sys/unix/ext/raw.rs +++ b/src/libstd/sys/unix/ext/raw.rs @@ -11,6 +11,12 @@ //! Unix-specific primitives available on all unix platforms #![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] +#![allow(deprecated)] #[stable(feature = "raw_ext", since = "1.1.0")] pub type uid_t = u32; #[stable(feature = "raw_ext", since = "1.1.0")] pub type gid_t = u32; diff --git a/src/libstd/sys/unix/ext/thread.rs b/src/libstd/sys/unix/ext/thread.rs index c1c1609632a..bb8200ff859 100644 --- a/src/libstd/sys/unix/ext/thread.rs +++ b/src/libstd/sys/unix/ext/thread.rs @@ -12,11 +12,13 @@ #![unstable(feature = "thread_extensions", issue = "29791")] -use os::unix::raw::{pthread_t}; +#[allow(deprecated)] +use os::unix::raw::pthread_t; use sys_common::{AsInner, IntoInner}; -use thread::{JoinHandle}; +use thread::JoinHandle; #[unstable(feature = "thread_extensions", issue = "29791")] +#[allow(deprecated)] pub type RawPthread = pthread_t; /// Unix-specific extensions to `std::thread::JoinHandle` diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index ee81c516e33..e8e0a604e55 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -15,22 +15,29 @@ use os::unix::prelude::*; use ffi::{CString, CStr, OsString, OsStr}; use fmt; use io::{self, Error, ErrorKind, SeekFrom}; -use libc::{self, dirent, c_int, off_t, mode_t}; +use libc::{self, c_int, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; use sync::Arc; use sys::fd::FileDesc; -use sys::platform::raw; use sys::time::SystemTime; use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; +#[cfg(target_os = "linux")] +use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64}; +#[cfg(not(target_os = "linux"))] +use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t, + ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64, open as open64}; +#[cfg(not(any(target_os = "linux", target_os = "solaris")))] +use libc::{readdir_r as readdir64_r}; + pub struct File(FileDesc); #[derive(Clone)] pub struct FileAttr { - stat: raw::stat, + stat: stat64, } pub struct ReadDir { @@ -44,7 +51,7 @@ unsafe impl Send for Dir {} unsafe impl Sync for Dir {} pub struct DirEntry { - entry: dirent, + entry: dirent64, root: Arc<PathBuf>, // We need to store an owned copy of the directory name // on Solaris because a) it uses a zero-length array to @@ -116,14 +123,14 @@ impl FileAttr { impl FileAttr { pub fn modified(&self) -> io::Result<SystemTime> { Ok(SystemTime::from(libc::timespec { - tv_sec: self.stat.st_mtime, + tv_sec: self.stat.st_mtime as libc::time_t, tv_nsec: self.stat.st_mtime_nsec as libc::c_long, })) } pub fn accessed(&self) -> io::Result<SystemTime> { Ok(SystemTime::from(libc::timespec { - tv_sec: self.stat.st_atime, + tv_sec: self.stat.st_atime as libc::time_t, tv_nsec: self.stat.st_atime_nsec as libc::c_long, })) } @@ -133,7 +140,7 @@ impl FileAttr { target_os = "openbsd"))] pub fn created(&self) -> io::Result<SystemTime> { Ok(SystemTime::from(libc::timespec { - tv_sec: self.stat.st_birthtime, + tv_sec: self.stat.st_birthtime as libc::time_t, tv_nsec: self.stat.st_birthtime_nsec as libc::c_long, })) } @@ -148,26 +155,8 @@ impl FileAttr { } } -impl AsInner<raw::stat> for FileAttr { - fn as_inner(&self) -> &raw::stat { &self.stat } -} - -/// OS-specific extension methods for `fs::Metadata` -#[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { - /// Gain a reference to the underlying `stat` structure which contains the - /// raw information returned by the OS. - /// - /// The contents of the returned `stat` are **not** consistent across Unix - /// platforms. The `os::unix::fs::MetadataExt` trait contains the cross-Unix - /// abstractions contained within the raw stat. - #[stable(feature = "metadata_ext", since = "1.1.0")] - fn as_raw_stat(&self) -> &raw::stat; -} - -#[stable(feature = "metadata_ext", since = "1.1.0")] -impl MetadataExt for ::fs::Metadata { - fn as_raw_stat(&self) -> &raw::stat { &self.as_inner().stat } +impl AsInner<stat64> for FileAttr { + fn as_inner(&self) -> &stat64 { &self.stat } } impl FilePermissions { @@ -179,7 +168,7 @@ impl FilePermissions { self.mode |= 0o222; } } - pub fn mode(&self) -> raw::mode_t { self.mode } + pub fn mode(&self) -> u32 { self.mode as u32 } } impl FileType { @@ -190,8 +179,8 @@ impl FileType { pub fn is(&self, mode: mode_t) -> bool { self.mode & libc::S_IFMT == mode } } -impl FromInner<raw::mode_t> for FilePermissions { - fn from_inner(mode: raw::mode_t) -> FilePermissions { +impl FromInner<u32> for FilePermissions { + fn from_inner(mode: u32) -> FilePermissions { FilePermissions { mode: mode as mode_t } } } @@ -237,7 +226,7 @@ impl Iterator for ReadDir { }; let mut entry_ptr = ptr::null_mut(); loop { - if libc::readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { + if readdir64_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { return Some(Err(Error::last_os_error())) } if entry_ptr.is_null() { @@ -293,15 +282,11 @@ impl DirEntry { #[cfg(any(target_os = "macos", target_os = "ios", target_os = "linux", - target_os = "solaris", - target_os = "emscripten"))] - pub fn ino(&self) -> raw::ino_t { - self.entry.d_ino - } - - #[cfg(target_os = "android")] - pub fn ino(&self) -> raw::ino_t { - self.entry.d_ino as raw::ino_t + target_os = "emscripten", + target_os = "android", + target_os = "solaris"))] + pub fn ino(&self) -> u64 { + self.entry.d_ino as u64 } #[cfg(any(target_os = "freebsd", @@ -309,8 +294,8 @@ impl DirEntry { target_os = "bitrig", target_os = "netbsd", target_os = "dragonfly"))] - pub fn ino(&self) -> raw::ino_t { - self.entry.d_fileno + pub fn ino(&self) -> u64 { + self.entry.d_fileno as u64 } #[cfg(any(target_os = "macos", @@ -364,7 +349,7 @@ impl OpenOptions { pub fn create_new(&mut self, create_new: bool) { self.create_new = create_new; } pub fn custom_flags(&mut self, flags: i32) { self.custom_flags = flags; } - pub fn mode(&mut self, mode: raw::mode_t) { self.mode = mode as mode_t; } + pub fn mode(&mut self, mode: u32) { self.mode = mode as mode_t; } fn get_access_mode(&self) -> io::Result<c_int> { match (self.read, self.write, self.append) { @@ -412,7 +397,7 @@ impl File { try!(opts.get_creation_mode()) | (opts.custom_flags as c_int & !libc::O_ACCMODE); let fd = try!(cvt_r(|| unsafe { - libc::open(path.as_ptr(), flags, opts.mode as c_int) + open64(path.as_ptr(), flags, opts.mode as c_int) })); let fd = FileDesc::new(fd); @@ -431,9 +416,9 @@ impl File { } pub fn file_attr(&self) -> io::Result<FileAttr> { - let mut stat: raw::stat = unsafe { mem::zeroed() }; + let mut stat: stat64 = unsafe { mem::zeroed() }; try!(cvt(unsafe { - libc::fstat(self.0.raw(), &mut stat as *mut _ as *mut _) + fstat64(self.0.raw(), &mut stat) })); Ok(FileAttr { stat: stat }) } @@ -461,7 +446,7 @@ impl File { pub fn truncate(&self, size: u64) -> io::Result<()> { try!(cvt_r(|| unsafe { - libc::ftruncate(self.0.raw(), size as libc::off_t) + ftruncate64(self.0.raw(), size as off64_t) })); Ok(()) } @@ -478,11 +463,11 @@ impl File { pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> { let (whence, pos) = match pos { - SeekFrom::Start(off) => (libc::SEEK_SET, off as off_t), - SeekFrom::End(off) => (libc::SEEK_END, off as off_t), - SeekFrom::Current(off) => (libc::SEEK_CUR, off as off_t), + SeekFrom::Start(off) => (libc::SEEK_SET, off as off64_t), + SeekFrom::End(off) => (libc::SEEK_END, off as off64_t), + SeekFrom::Current(off) => (libc::SEEK_CUR, off as off64_t), }; - let n = try!(cvt(unsafe { libc::lseek(self.0.raw(), pos, whence) })); + let n = try!(cvt(unsafe { lseek64(self.0.raw(), pos, whence) })); Ok(n as u64) } @@ -506,8 +491,8 @@ impl DirBuilder { Ok(()) } - pub fn set_mode(&mut self, mode: mode_t) { - self.mode = mode; + pub fn set_mode(&mut self, mode: u32) { + self.mode = mode as mode_t; } } @@ -689,18 +674,18 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> { pub fn stat(p: &Path) -> io::Result<FileAttr> { let p = try!(cstr(p)); - let mut stat: raw::stat = unsafe { mem::zeroed() }; + let mut stat: stat64 = unsafe { mem::zeroed() }; try!(cvt(unsafe { - libc::stat(p.as_ptr(), &mut stat as *mut _ as *mut _) + stat64(p.as_ptr(), &mut stat as *mut _ as *mut _) })); Ok(FileAttr { stat: stat }) } pub fn lstat(p: &Path) -> io::Result<FileAttr> { let p = try!(cstr(p)); - let mut stat: raw::stat = unsafe { mem::zeroed() }; + let mut stat: stat64 = unsafe { mem::zeroed() }; try!(cvt(unsafe { - libc::lstat(p.as_ptr(), &mut stat as *mut _ as *mut _) + lstat64(p.as_ptr(), &mut stat as *mut _ as *mut _) })); Ok(FileAttr { stat: stat }) } diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index a868abbb731..1b5faf64ad6 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -46,7 +46,7 @@ mod imp { use super::Handler; use mem; use ptr; - use libc::{sigaltstack, SIGSTKSZ}; + use libc::{sigaltstack, SIGSTKSZ, SS_DISABLE}; use libc::{sigaction, SIGBUS, SIG_DFL, SA_SIGINFO, SA_ONSTACK, sighandler_t}; use libc; @@ -169,13 +169,32 @@ mod imp { } pub unsafe fn make_handler() -> Handler { - let stack = get_stack(); - sigaltstack(&stack, ptr::null_mut()); - Handler { _data: stack.ss_sp as *mut libc::c_void } + let mut stack = mem::zeroed(); + sigaltstack(ptr::null(), &mut stack); + // Configure alternate signal stack, if one is not already set. + if stack.ss_flags & SS_DISABLE != 0 { + stack = get_stack(); + sigaltstack(&stack, ptr::null_mut()); + Handler { _data: stack.ss_sp as *mut libc::c_void } + } else { + Handler { _data: ptr::null_mut() } + } } pub unsafe fn drop_handler(handler: &mut Handler) { - munmap(handler._data, SIGSTKSZ); + if !handler._data.is_null() { + let stack = libc::stack_t { + ss_sp: ptr::null_mut(), + ss_flags: SS_DISABLE, + // Workaround for bug in MacOS implementation of sigaltstack + // UNIX2003 which returns ENOMEM when disabling a stack while + // passing ss_size smaller than MINSIGSTKSZ. According to POSIX + // both ss_sp and ss_size should be ignored in this case. + ss_size: SIGSTKSZ, + }; + sigaltstack(&stack, ptr::null_mut()); + munmap(handler._data, SIGSTKSZ); + } } } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 9fdeb0aef14..d25d8e0b804 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -240,6 +240,7 @@ pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8; pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c; pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003; +pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001; pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4; pub const FSCTL_DELETE_REPARSE_POINT: DWORD = 0x900ac; @@ -533,6 +534,15 @@ pub struct SYMBOLIC_LINK_REPARSE_BUFFER { pub PathBuffer: WCHAR, } +#[repr(C)] +pub struct MOUNT_POINT_REPARSE_BUFFER { + pub SubstituteNameOffset: c_ushort, + pub SubstituteNameLength: c_ushort, + pub PrintNameOffset: c_ushort, + pub PrintNameLength: c_ushort, + pub PathBuffer: WCHAR, +} + pub type LPPROGRESS_ROUTINE = ::option::Option<unsafe extern "system" fn( TotalFileSize: LARGE_INTEGER, TotalBytesTransferred: LARGE_INTEGER, diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 3062d38f8c2..95fb1e7c600 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -30,7 +30,11 @@ pub struct File { handle: Handle } #[derive(Clone)] pub struct FileAttr { - data: c::WIN32_FILE_ATTRIBUTE_DATA, + attributes: c::DWORD, + creation_time: c::FILETIME, + last_access_time: c::FILETIME, + last_write_time: c::FILETIME, + file_size: u64, reparse_tag: c::DWORD, } @@ -142,15 +146,17 @@ impl DirEntry { pub fn metadata(&self) -> io::Result<FileAttr> { Ok(FileAttr { - data: c::WIN32_FILE_ATTRIBUTE_DATA { - dwFileAttributes: self.data.dwFileAttributes, - ftCreationTime: self.data.ftCreationTime, - ftLastAccessTime: self.data.ftLastAccessTime, - ftLastWriteTime: self.data.ftLastWriteTime, - nFileSizeHigh: self.data.nFileSizeHigh, - nFileSizeLow: self.data.nFileSizeLow, - }, - reparse_tag: self.data.dwReserved0, + attributes: self.data.dwFileAttributes, + creation_time: self.data.ftCreationTime, + last_access_time: self.data.ftLastAccessTime, + last_write_time: self.data.ftLastWriteTime, + file_size: ((self.data.nFileSizeHigh as u64) << 32) | (self.data.nFileSizeLow as u64), + reparse_tag: if self.data.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 { + // reserved unless this is a reparse point + self.data.dwReserved0 + } else { + 0 + }, }) } } @@ -240,15 +246,6 @@ impl OpenOptions { } impl File { - fn open_reparse_point(path: &Path, write: bool) -> io::Result<File> { - let mut opts = OpenOptions::new(); - opts.read(!write); - opts.write(write); - opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | - c::FILE_FLAG_BACKUP_SEMANTICS); - File::open(path, &opts) - } - pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> { let path = try!(to_u16s(path)); let handle = unsafe { @@ -294,14 +291,11 @@ impl File { try!(cvt(c::GetFileInformationByHandle(self.handle.raw(), &mut info))); let mut attr = FileAttr { - data: c::WIN32_FILE_ATTRIBUTE_DATA { - dwFileAttributes: info.dwFileAttributes, - ftCreationTime: info.ftCreationTime, - ftLastAccessTime: info.ftLastAccessTime, - ftLastWriteTime: info.ftLastWriteTime, - nFileSizeHigh: info.nFileSizeHigh, - nFileSizeLow: info.nFileSizeLow, - }, + attributes: info.dwFileAttributes, + creation_time: info.ftCreationTime, + last_access_time: info.ftLastAccessTime, + last_write_time: info.ftLastWriteTime, + file_size: ((info.nFileSizeHigh as u64) << 32) | (info.nFileSizeLow as u64), reparse_tag: 0, }; if attr.is_reparse_point() { @@ -371,19 +365,34 @@ impl File { fn readlink(&self) -> io::Result<PathBuf> { let mut space = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; let (_bytes, buf) = try!(self.reparse_point(&mut space)); - if buf.ReparseTag != c::IO_REPARSE_TAG_SYMLINK { - return Err(io::Error::new(io::ErrorKind::Other, "not a symlink")) - } - unsafe { - let info: *const c::SYMBOLIC_LINK_REPARSE_BUFFER = - &buf.rest as *const _ as *const _; - let path_buffer = &(*info).PathBuffer as *const _ as *const u16; - let subst_off = (*info).SubstituteNameOffset / 2; + let (path_buffer, subst_off, subst_len, relative) = match buf.ReparseTag { + c::IO_REPARSE_TAG_SYMLINK => { + let info: *const c::SYMBOLIC_LINK_REPARSE_BUFFER = + &buf.rest as *const _ as *const _; + (&(*info).PathBuffer as *const _ as *const u16, + (*info).SubstituteNameOffset / 2, + (*info).SubstituteNameLength / 2, + (*info).Flags & c::SYMLINK_FLAG_RELATIVE != 0) + }, + c::IO_REPARSE_TAG_MOUNT_POINT => { + let info: *const c::MOUNT_POINT_REPARSE_BUFFER = + &buf.rest as *const _ as *const _; + (&(*info).PathBuffer as *const _ as *const u16, + (*info).SubstituteNameOffset / 2, + (*info).SubstituteNameLength / 2, + false) + }, + _ => return Err(io::Error::new(io::ErrorKind::Other, + "Unsupported reparse point type")) + }; let subst_ptr = path_buffer.offset(subst_off as isize); - let subst_len = (*info).SubstituteNameLength / 2; - let subst = slice::from_raw_parts(subst_ptr, subst_len as usize); - + let mut subst = slice::from_raw_parts(subst_ptr, subst_len as usize); + // Absolute paths start with an NT internal namespace prefix `\??\` + // We should not let it leak through. + if !relative && subst.starts_with(&[92u16, 63u16, 63u16, 92u16]) { + subst = &subst[4..]; + } Ok(PathBuf::from(OsString::from_wide(subst))) } } @@ -409,45 +418,45 @@ impl fmt::Debug for File { impl FileAttr { pub fn size(&self) -> u64 { - ((self.data.nFileSizeHigh as u64) << 32) | (self.data.nFileSizeLow as u64) + self.file_size } pub fn perm(&self) -> FilePermissions { - FilePermissions { attrs: self.data.dwFileAttributes } + FilePermissions { attrs: self.attributes } } - pub fn attrs(&self) -> u32 { self.data.dwFileAttributes as u32 } + pub fn attrs(&self) -> u32 { self.attributes as u32 } pub fn file_type(&self) -> FileType { - FileType::new(self.data.dwFileAttributes, self.reparse_tag) + FileType::new(self.attributes, self.reparse_tag) } pub fn modified(&self) -> io::Result<SystemTime> { - Ok(SystemTime::from(self.data.ftLastWriteTime)) + Ok(SystemTime::from(self.last_write_time)) } pub fn accessed(&self) -> io::Result<SystemTime> { - Ok(SystemTime::from(self.data.ftLastAccessTime)) + Ok(SystemTime::from(self.last_access_time)) } pub fn created(&self) -> io::Result<SystemTime> { - Ok(SystemTime::from(self.data.ftCreationTime)) + Ok(SystemTime::from(self.creation_time)) } pub fn modified_u64(&self) -> u64 { - to_u64(&self.data.ftLastWriteTime) + to_u64(&self.last_write_time) } pub fn accessed_u64(&self) -> u64 { - to_u64(&self.data.ftLastAccessTime) + to_u64(&self.last_access_time) } pub fn created_u64(&self) -> u64 { - to_u64(&self.data.ftCreationTime) + to_u64(&self.creation_time) } fn is_reparse_point(&self) -> bool { - self.data.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 + self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 } } @@ -577,8 +586,15 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { rmdir(path) } -pub fn readlink(p: &Path) -> io::Result<PathBuf> { - let file = try!(File::open_reparse_point(p, false)); +pub fn readlink(path: &Path) -> io::Result<PathBuf> { + // Open the link with no access mode, instead of generic read. + // By default FILE_LIST_DIRECTORY is denied for the junction "C:\Documents and Settings", so + // this is needed for a common case. + let mut opts = OpenOptions::new(); + opts.access_mode(0); + opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | + c::FILE_FLAG_BACKUP_SEMANTICS); + let file = try!(File::open(&path, &opts)); file.readlink() } @@ -605,42 +621,23 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> { Ok(()) } -pub fn stat(p: &Path) -> io::Result<FileAttr> { - let attr = try!(lstat(p)); - - // If this is a reparse point, then we need to reopen the file to get the - // actual destination. We also pass the FILE_FLAG_BACKUP_SEMANTICS flag to - // ensure that we can open directories (this path may be a directory - // junction). Once the file is opened we ask the opened handle what its - // metadata information is. - if attr.is_reparse_point() { - let mut opts = OpenOptions::new(); - // No read or write permissions are necessary - opts.access_mode(0); - // This flag is so we can open directories too - opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS); - let file = try!(File::open(p, &opts)); - file.file_attr() - } else { - Ok(attr) - } +pub fn stat(path: &Path) -> io::Result<FileAttr> { + let mut opts = OpenOptions::new(); + // No read or write permissions are necessary + opts.access_mode(0); + // This flag is so we can open directories too + opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS); + let file = try!(File::open(path, &opts)); + file.file_attr() } -pub fn lstat(p: &Path) -> io::Result<FileAttr> { - let u16s = try!(to_u16s(p)); - unsafe { - let mut attr: FileAttr = mem::zeroed(); - try!(cvt(c::GetFileAttributesExW(u16s.as_ptr(), - c::GetFileExInfoStandard, - &mut attr.data as *mut _ as *mut _))); - if attr.is_reparse_point() { - attr.reparse_tag = File::open_reparse_point(p, false).and_then(|f| { - let mut b = [0; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; - f.reparse_point(&mut b).map(|(_, b)| b.ReparseTag) - }).unwrap_or(0); - } - Ok(attr) - } +pub fn lstat(path: &Path) -> io::Result<FileAttr> { + let mut opts = OpenOptions::new(); + // No read or write permissions are necessary + opts.access_mode(0); + opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | c::FILE_FLAG_OPEN_REPARSE_POINT); + let file = try!(File::open(path, &opts)); + file.file_attr() } pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { @@ -709,7 +706,12 @@ pub fn symlink_junction<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::R fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { let d = DirBuilder::new(); try!(d.mkdir(&junction)); - let f = try!(File::open_reparse_point(junction, true)); + + let mut opts = OpenOptions::new(); + opts.write(true); + opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | + c::FILE_FLAG_BACKUP_SEMANTICS); + let f = try!(File::open(junction, &opts)); let h = f.handle().raw(); unsafe { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 48c9b70dce4..688475a7565 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -338,9 +338,9 @@ pub fn home_dir() -> Option<PathBuf> { let _handle = Handle::new(token); super::fill_utf16_buf(|buf, mut sz| { match c::GetUserProfileDirectoryW(token, buf, &mut sz) { - 0 if c::GetLastError() != 0 => 0, + 0 if c::GetLastError() != c::ERROR_INSUFFICIENT_BUFFER => 0, 0 => sz, - n => n as c::DWORD, + _ => sz - 1, // sz includes the null terminator } }, super::os2path).ok() }) |
