diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-04-15 23:21:13 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-04-27 17:16:44 -0700 |
| commit | 9348700007c6ac913df97c8e9e1ab7df6f91f130 (patch) | |
| tree | a69d87dfe3b7e1e8c7cd9f7f48fdabdb1436c308 /src/libstd/os | |
| parent | b772ce6342962792620e21623997d0d3b98164b7 (diff) | |
| download | rust-9348700007c6ac913df97c8e9e1ab7df6f91f130.tar.gz rust-9348700007c6ac913df97c8e9e1ab7df6f91f130.zip | |
std: Expand the area of std::fs
This commit is an implementation of [RFC 1044][rfc] which adds additional
surface area to the `std::fs` module. All new APIs are `#[unstable]` behind
assorted feature names for each one.
[rfc]: https://github.com/rust-lang/rfcs/pull/1044
The new APIs added are:
* `fs::canonicalize` - bindings to `realpath` on unix and
`GetFinalPathNameByHandle` on windows.
* `fs::symlink_metadata` - similar to `lstat` on unix
* `fs::FileType` and accessor methods as `is_{file,dir,symlink}`
* `fs::Metadata::file_type` - accessor for the raw file type
* `fs::DirEntry::metadata` - acquisition of metadata which is free on Windows
but requires a syscall on unix.
* `fs::DirEntry::file_type` - access the file type which may not require a
syscall on most platforms.
* `fs::DirEntry::file_name` - access just the file name without leading
components.
* `fs::PathExt::symlink_metadata` - convenience method for the top-level
function.
* `fs::PathExt::canonicalize` - convenience method for the top-level
function.
* `fs::PathExt::read_link` - convenience method for the top-level
function.
* `fs::PathExt::read_dir` - convenience method for the top-level
function.
* `std::os::raw` - type definitions for raw OS/C types available on all
platforms.
* `std::os::$platform` - new modules have been added for all currently supported
platforms (e.g. those more specific than just `unix`).
* `std::os::$platform::raw` - platform-specific type definitions. These modules
are populated with the bare essentials necessary for lowing I/O types into
their raw representations, and currently largely consist of the `stat`
definition for unix platforms.
This commit also deprecates `Metadata::{modified, accessed}` in favor of
inspecting the raw representations via the lowering methods of `Metadata`.
Diffstat (limited to 'src/libstd/os')
| -rw-r--r-- | src/libstd/os/android/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/android/raw.rs | 46 | ||||
| -rw-r--r-- | src/libstd/os/bitrig/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/bitrig/raw.rs | 48 | ||||
| -rw-r--r-- | src/libstd/os/dragonfly/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/dragonfly/raw.rs | 50 | ||||
| -rw-r--r-- | src/libstd/os/freebsd/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/freebsd/raw.rs | 50 | ||||
| -rw-r--r-- | src/libstd/os/ios/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/ios/raw.rs | 49 | ||||
| -rw-r--r-- | src/libstd/os/linux/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/linux/raw.rs | 170 | ||||
| -rw-r--r-- | src/libstd/os/macos/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/macos/raw.rs | 49 | ||||
| -rw-r--r-- | src/libstd/os/mod.rs | 29 | ||||
| -rw-r--r-- | src/libstd/os/nacl/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/nacl/raw.rs | 169 | ||||
| -rw-r--r-- | src/libstd/os/openbsd/mod.rs | 19 | ||||
| -rw-r--r-- | src/libstd/os/openbsd/raw.rs | 48 | ||||
| -rw-r--r-- | src/libstd/os/raw.rs | 92 |
20 files changed, 971 insertions, 0 deletions
diff --git a/src/libstd/os/android/mod.rs b/src/libstd/os/android/mod.rs new file mode 100644 index 00000000000..346a903c4d9 --- /dev/null +++ b/src/libstd/os/android/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! Android-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/android/raw.rs b/src/libstd/os/android/raw.rs new file mode 100644 index 00000000000..538ed7c4688 --- /dev/null +++ b/src/libstd/os/android/raw.rs @@ -0,0 +1,46 @@ +// Copyright 2015 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. + +//! Android-specific raw type definitions + +use os::raw::{c_uint, c_uchar, c_ulonglong, c_longlong, c_ulong}; +use os::unix::raw::{uid_t, gid_t}; + +pub type blkcnt_t = u32; +pub type blksize_t = u32; +pub type dev_t = u32; +pub type ino_t = u32; +pub type mode_t = u16; +pub type nlink_t = u16; +pub type off_t = i32; +pub type time_t = i32; + +#[repr(C)] +pub struct stat { + pub st_dev: c_ulonglong, + pub __pad0: [c_uchar; 4], + pub __st_ino: ino_t, + pub st_mode: c_uint, + pub st_nlink: c_uint, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: c_ulonglong, + pub __pad3: [c_uchar; 4], + pub st_size: c_longlong, + pub st_blksize: blksize_t, + pub st_blocks: c_ulonglong, + pub st_atime: time_t, + pub st_atime_nsec: c_ulong, + pub st_mtime: time_t, + pub st_mtime_nsec: c_ulong, + pub st_ctime: time_t, + pub st_ctime_nsec: c_ulong, + pub st_ino: c_ulonglong, +} diff --git a/src/libstd/os/bitrig/mod.rs b/src/libstd/os/bitrig/mod.rs new file mode 100644 index 00000000000..01ea542b3b7 --- /dev/null +++ b/src/libstd/os/bitrig/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! Bitrig-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/bitrig/raw.rs b/src/libstd/os/bitrig/raw.rs new file mode 100644 index 00000000000..aebc21aa718 --- /dev/null +++ b/src/libstd/os/bitrig/raw.rs @@ -0,0 +1,48 @@ +// Copyright 2015 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. + +//! Bitrig-specific raw type definitions + +use os::raw::c_long; +use os::unix::raw::{uid_t, gid_t}; + +pub type blkcnt_t = i64; +pub type blksize_t = u32; +pub type dev_t = i32; +pub type fflags_t = u32; // type not declared, but struct stat have u_int32_t +pub type ino_t = u64; +pub type mode_t = u32; +pub type nlink_t = u32; +pub type off_t = i64; +pub type time_t = i64; + +#[repr(C)] +pub struct stat { + pub st_mode: mode_t, + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_size: off_t, + pub st_blocks: blkcnt_t, + pub st_blksize: blksize_t, + pub st_flags: fflags_t, + pub st_gen: u32, + pub st_birthtime: time_t, + pub st_birthtime_nsec: c_long, +} diff --git a/src/libstd/os/dragonfly/mod.rs b/src/libstd/os/dragonfly/mod.rs new file mode 100644 index 00000000000..677f8b706cd --- /dev/null +++ b/src/libstd/os/dragonfly/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! Dragonfly-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/dragonfly/raw.rs b/src/libstd/os/dragonfly/raw.rs new file mode 100644 index 00000000000..22c811ead43 --- /dev/null +++ b/src/libstd/os/dragonfly/raw.rs @@ -0,0 +1,50 @@ +// Copyright 2015 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. + +//! Dragonfly-specific raw type definitions + +use os::raw::c_long; +use os::unix::raw::{pid_t, uid_t, gid_t}; + +pub type blkcnt_t = i64; +pub type blksize_t = u32; +pub type dev_t = u32; +pub type fflags_t = u32; +pub type ino_t = u64; +pub type mode_t = u16; +pub type nlink_t = u16; +pub type off_t = i64; +pub type time_t = i64; + +#[repr(C)] +pub struct stat { + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_dev: dev_t, + pub st_mode: mode_t, + pub st_padding1: u16, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_size: off_t, + pub st_blocks: blkcnt_t, + pub st_blksize: blksize_t, + pub st_flags: fflags_t, + pub st_gen: uint32_t, + pub st_lspare: int32_t, + pub st_qspare1: int64_t, + pub st_qspare2: int64_t, +} diff --git a/src/libstd/os/freebsd/mod.rs b/src/libstd/os/freebsd/mod.rs new file mode 100644 index 00000000000..73b6fd21137 --- /dev/null +++ b/src/libstd/os/freebsd/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! FreeBSD-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/freebsd/raw.rs b/src/libstd/os/freebsd/raw.rs new file mode 100644 index 00000000000..a810eff45d3 --- /dev/null +++ b/src/libstd/os/freebsd/raw.rs @@ -0,0 +1,50 @@ +// Copyright 2015 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. + +//! FreeBSD-specific raw type definitions + +use os::raw::c_long; +use os::unix::raw::{uid_t, gid_t, pid_t}; + +pub type blkcnt_t = i64; +pub type blksize_t = i64; +pub type dev_t = u32; +pub type fflags_t = u32; +pub type ino_t = u32; +pub type mode_t = u16; +pub type nlink_t = u16; +pub type off_t = i64; +pub type time_t = i64; + +#[repr(C)] +pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_size: off_t, + pub st_blocks: blkcnt_t, + pub st_blksize: blksize_t, + pub st_flags: fflags_t, + pub st_gen: u32, + pub st_lspare: i32, + pub st_birthtime: time_t, + pub st_birthtime_nsec: c_long, + pub __unused: [u8; 2], +} diff --git a/src/libstd/os/ios/mod.rs b/src/libstd/os/ios/mod.rs new file mode 100644 index 00000000000..d471cf12fe6 --- /dev/null +++ b/src/libstd/os/ios/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! iOS-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/ios/raw.rs b/src/libstd/os/ios/raw.rs new file mode 100644 index 00000000000..3266b3846d8 --- /dev/null +++ b/src/libstd/os/ios/raw.rs @@ -0,0 +1,49 @@ +// Copyright 2015 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. + +//! iOS-specific raw type definitions + +use os::raw::c_long; +use os::unix::raw::{uid_t, gid_t, pid_t}; + +pub type blkcnt_t = i64; +pub type blksize_t = i32; +pub type dev_t = i32; +pub type ino_t = u64; +pub type mode_t = u16; +pub type nlink_t = u16; +pub type off_t = i64; +pub type time_t = c_long; + +#[repr(C)] +pub struct stat { + pub st_dev: dev_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_ino: ino_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_birthtime: time_t, + pub st_birthtime_nsec: c_long, + pub st_size: off_t, + pub st_blocks: blkcnt_t, + pub st_blksize: blksize_t, + pub st_flags: u32, + pub st_gen: u32, + pub st_lspare: i32, + pub st_qspare: [i64; 2], +} diff --git a/src/libstd/os/linux/mod.rs b/src/libstd/os/linux/mod.rs new file mode 100644 index 00000000000..43376a1baeb --- /dev/null +++ b/src/libstd/os/linux/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! Linux-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/linux/raw.rs b/src/libstd/os/linux/raw.rs new file mode 100644 index 00000000000..adce5f22ebc --- /dev/null +++ b/src/libstd/os/linux/raw.rs @@ -0,0 +1,170 @@ +// Copyright 2015 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. + +//! Linux-specific raw type definitions + +pub type dev_t = u64; +pub type mode_t = u32; + +#[doc(inline)] +pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t}; + +#[cfg(any(target_arch = "x86", + target_arch = "le32", + target_arch = "powerpc", + target_arch = "arm"))] +mod arch { + use super::{dev_t, mode_t}; + use os::raw::{c_long, c_short}; + use os::unix::raw::{gid_t, uid_t}; + + pub type blkcnt_t = i32; + pub type blksize_t = i32; + pub type ino_t = u32; + pub type nlink_t = u32; + pub type off_t = i32; + pub type time_t = i32; + + #[repr(C)] + pub struct stat { + pub st_dev: dev_t, + pub __pad1: c_short, + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub __pad2: c_short, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub __unused4: c_long, + pub __unused5: c_long, + } +} + +#[cfg(any(target_arch = "mips", + target_arch = "mipsel"))] +mod arch { + use super::{dev_t, mode_t}; + use os::raw::c_long; + use os::unix::raw::{gid_t, uid_t}; + + pub type blkcnt_t = i32; + pub type blksize_t = i32; + pub type ino_t = u32; + pub type nlink_t = u32; + pub type off_t = i32; + pub type time_t = i32; + + #[repr(C)] + pub struct stat { + pub st_dev: c_ulong, + pub st_pad1: [c_long; 3], + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: c_ulong, + pub st_pad2: [c_long; 2], + pub st_size: off_t, + pub st_pad3: c_long, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_pad5: [c_long; 14], + } +} + +#[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}; + + pub type blkcnt_t = i64; + pub type blksize_t = i32; + pub type ino_t = u64; + pub type nlink_t = u32; + pub type off_t = i64; + pub type time_t = i64; + + #[repr(C)] + pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub __pad1: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub __pad2: c_int, + pub st_blocks: blkcnt_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub __unused: [c_int; 2], + } +} + +#[cfg(target_arch = "x86_64")] +mod arch { + use super::{dev_t, mode_t}; + use os::raw::{c_long, c_int}; + use os::unix::raw::{gid_t, uid_t}; + + pub type blkcnt_t = i64; + pub type blksize_t = i64; + pub type ino_t = u64; + pub type nlink_t = u64; + pub type off_t = i64; + pub type time_t = i64; + + #[repr(C)] + pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_mode: mode_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub __pad0: c_int, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub __unused: [c_long; 3], + } +} diff --git a/src/libstd/os/macos/mod.rs b/src/libstd/os/macos/mod.rs new file mode 100644 index 00000000000..bc5ff5b25d2 --- /dev/null +++ b/src/libstd/os/macos/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! MacOS-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/macos/raw.rs b/src/libstd/os/macos/raw.rs new file mode 100644 index 00000000000..03fcb768c11 --- /dev/null +++ b/src/libstd/os/macos/raw.rs @@ -0,0 +1,49 @@ +// Copyright 2015 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. + +//! MacOS-specific raw type definitions + +use os::raw::c_long; +use os::unix::raw::{uid_t, gid_t}; + +pub type blkcnt_t = i64; +pub type blksize_t = i32; +pub type dev_t = i32; +pub type ino_t = u64; +pub type mode_t = u16; +pub type nlink_t = u16; +pub type off_t = i64; +pub type time_t = c_long; + +#[repr(C)] +pub struct stat { + pub st_dev: dev_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_ino: ino_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_birthtime: time_t, + pub st_birthtime_nsec: c_long, + pub st_size: off_t, + pub st_blocks: blkcnt_t, + pub st_blksize: blksize_t, + pub st_flags: u32, + pub st_gen: u32, + pub st_lspare: i32, + pub st_qspare: [i64; 2], +} diff --git a/src/libstd/os/mod.rs b/src/libstd/os/mod.rs new file mode 100644 index 00000000000..cc4b1c944e7 --- /dev/null +++ b/src/libstd/os/mod.rs @@ -0,0 +1,29 @@ +// Copyright 2012-2015 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. + +//! OS-specific functionality + +#![stable(feature = "os", since = "1.0.0")] +#![allow(missing_docs, bad_style)] + +#[cfg(unix)] pub use sys::ext as unix; +#[cfg(windows)] pub use sys::ext as windows; + +#[cfg(target_os = "android")] pub mod android; +#[cfg(target_os = "bitrig")] pub mod bitrig; +#[cfg(target_os = "dragonfly")] pub mod dragonfly; +#[cfg(target_os = "freebsd")] pub mod freebsd; +#[cfg(target_os = "ios")] pub mod ios; +#[cfg(target_os = "linux")] pub mod linux; +#[cfg(target_os = "macos")] pub mod macos; +#[cfg(target_os = "nacl")] pub mod nacl; +#[cfg(target_os = "openbsd")] pub mod openbsd; + +pub mod raw; diff --git a/src/libstd/os/nacl/mod.rs b/src/libstd/os/nacl/mod.rs new file mode 100644 index 00000000000..6baed039514 --- /dev/null +++ b/src/libstd/os/nacl/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! Nacl-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/nacl/raw.rs b/src/libstd/os/nacl/raw.rs new file mode 100644 index 00000000000..9defa8301ea --- /dev/null +++ b/src/libstd/os/nacl/raw.rs @@ -0,0 +1,169 @@ +// Copyright 2015 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. + +//! Nacl-specific raw type definitions + +pub type dev_t = u64; +pub type mode_t = u32; + +pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t}; + +#[cfg(any(target_arch = "x86", + target_arch = "le32", + target_arch = "powerpc", + target_arch = "arm"))] +mod arch { + use super::{dev_t, mode_t}; + use os::raw::{c_long, c_short}; + use os::unix::raw::{gid_t, uid_t}; + + pub type blkcnt_t = i32; + pub type blksize_t = i32; + pub type ino_t = u32; + pub type nlink_t = u32; + pub type off_t = i32; + pub type time_t = i32; + + #[repr(C)] + pub struct stat { + pub st_dev: dev_t, + pub __pad1: c_short, + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub __pad2: c_short, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub __unused4: c_long, + pub __unused5: c_long, + } +} + +#[cfg(any(target_arch = "mips", + target_arch = "mipsel"))] +mod arch { + use super::{dev_t, mode_t}; + use os::raw::c_long; + use os::unix::raw::{gid_t, uid_t}; + + pub type blkcnt_t = i32; + pub type blksize_t = i32; + pub type ino_t = u32; + pub type nlink_t = u32; + pub type off_t = i32; + pub type time_t = i32; + + #[repr(C)] + pub struct stat { + pub st_dev: c_ulong, + pub st_pad1: [c_long; 3], + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: c_ulong, + pub st_pad2: [c_long; 2], + pub st_size: off_t, + pub st_pad3: c_long, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_pad5: [c_long; 14], + } +} + +#[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}; + + pub type blkcnt_t = i64; + pub type blksize_t = i32; + pub type ino_t = u64; + pub type nlink_t = u32; + pub type off_t = i64; + pub type time_t = i64; + + #[repr(C)] + pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub __pad1: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub __pad2: c_int, + pub st_blocks: blkcnt_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub __unused: [c_int; 2], + } +} + +#[cfg(target_arch = "x86_64")] +mod arch { + use super::{dev_t, mode_t}; + use os::raw::{c_long, c_int}; + use os::unix::raw::{gid_t, uid_t}; + + pub type blkcnt_t = i64; + pub type blksize_t = i64; + pub type ino_t = u64; + pub type nlink_t = u64; + pub type off_t = i64; + pub type time_t = i64; + + #[repr(C)] + pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_mode: mode_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub __pad0: c_int, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub __unused: [c_long; 3], + } +} diff --git a/src/libstd/os/openbsd/mod.rs b/src/libstd/os/openbsd/mod.rs new file mode 100644 index 00000000000..1b1a1005590 --- /dev/null +++ b/src/libstd/os/openbsd/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +//! OpenBSD-specific definitions + +#![unstable(feature = "raw_ext", reason = "recently added API")] + +pub mod raw; + +pub mod fs { + pub use sys::fs2::MetadataExt; +} diff --git a/src/libstd/os/openbsd/raw.rs b/src/libstd/os/openbsd/raw.rs new file mode 100644 index 00000000000..632a8c336b7 --- /dev/null +++ b/src/libstd/os/openbsd/raw.rs @@ -0,0 +1,48 @@ +// Copyright 2015 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. + +//! OpenBSD-specific raw type definitions + +use os::raw::c_long; +use os::unix::raw::{uid_t, gid_t, pid_t}; + +pub type blkcnt_t = i64; +pub type blksize_t = u32; +pub type dev_t = i32; +pub type fflags_t = u32; // type not declared, but struct stat have u_int32_t +pub type ino_t = u64; +pub type mode_t = u32; +pub type nlink_t = u32; +pub type off_t = i64; +pub type time_t = i64; + +#[repr(C)] +pub struct stat { + pub st_mode: mode_t, + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_atime: time_t, + pub st_atime_nsec: c_long, + pub st_mtime: time_t, + pub st_mtime_nsec: c_long, + pub st_ctime: time_t, + pub st_ctime_nsec: c_long, + pub st_size: off_t, + pub st_blocks: blkcnt_t, + pub st_blksize: blksize_t, + pub st_flags: fflags_t, + pub st_gen: u32, + pub st_birthtime: time_t, + pub st_birthtime_nsec: c_long, +} diff --git a/src/libstd/os/raw.rs b/src/libstd/os/raw.rs new file mode 100644 index 00000000000..44f4a1c828b --- /dev/null +++ b/src/libstd/os/raw.rs @@ -0,0 +1,92 @@ +// Copyright 2015 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. + +//! Raw OS-specific types for the current platform/architecture + +#![unstable(feature = "raw_os", reason = "recently added API")] + +#[cfg(target_arch = "aarch64")] pub type c_char = u8; +#[cfg(not(target_arch = "aarch64"))] pub type c_char = i8; +pub type c_schar = i8; +pub type c_uchar = u8; +pub type c_short = i16; +pub type c_ushort = u16; +pub type c_int = i32; +pub type c_uint = u32; +#[cfg(any(target_pointer_width = "32", windows))] pub type c_long = i32; +#[cfg(any(target_pointer_width = "32", windows))] pub type c_ulong = u32; +#[cfg(all(target_pointer_width = "64", not(windows)))] pub type c_long = i64; +#[cfg(all(target_pointer_width = "64", not(windows)))] pub type c_ulong = u64; +pub type c_longlong = i64; +pub type c_ulonglong = u64; +pub type c_float = f32; +pub type c_double = f64; + +/// Type used to construct void pointers for use with C. +/// +/// This type is only useful as a pointer target. Do not use it as a +/// return type for FFI functions which have the `void` return type in +/// C. Use the unit type `()` or omit the return type instead. +// NB: For LLVM to recognize the void pointer type and by extension +// functions like malloc(), we need to have it represented as i8* in +// LLVM bitcode. The enum used here ensures this and prevents misuse +// of the "raw" type by only having private variants.. We need two +// variants, because the compiler complains about the repr attribute +// otherwise. +#[repr(u8)] +pub enum c_void { + #[doc(hidden)] __variant1, + #[doc(hidden)] __variant2, +} + +#[cfg(test)] +mod tests { + use any::TypeId; + use libc; + use mem; + + macro_rules! ok { + ($($t:ident)*) => {$( + assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(), + "{} is wrong", stringify!($t)); + )*} + } + + 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(unix)] + 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)] + fn windows() { + use os::windows::raw; + } +} |
