2015-04-15 23:21:13 -07:00
|
|
|
// 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
|
|
|
|
|
std: Stabilize a number of new fs features
This commit stabilizes the following APIs, slating them all to be cherry-picked
into the 1.1 release.
* fs::FileType (and transitively the derived trait implementations)
* fs::Metadata::file_type
* fs::FileType::is_dir
* fs::FileType::is_file
* fs::FileType::is_symlink
* fs::DirEntry::metadata
* fs::DirEntry::file_type
* fs::DirEntry::file_name
* fs::set_permissions
* fs::symlink_metadata
* os::raw::{self, *}
* os::{android, bitrig, linux, ...}::raw::{self, *}
* os::{android, bitrig, linux, ...}::fs::MetadataExt
* os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat
* os::unix::fs::PermissionsExt
* os::unix::fs::PermissionsExt::mode
* os::unix::fs::PermissionsExt::set_mode
* os::unix::fs::PermissionsExt::from_mode
* os::unix::fs::OpenOptionsExt
* os::unix::fs::OpenOptionsExt::mode
* os::unix::fs::DirEntryExt
* os::unix::fs::DirEntryExt::ino
* os::windows::fs::MetadataExt
* os::windows::fs::MetadataExt::file_attributes
* os::windows::fs::MetadataExt::creation_time
* os::windows::fs::MetadataExt::last_access_time
* os::windows::fs::MetadataExt::last_write_time
* os::windows::fs::MetadataExt::file_size
The `os::unix::fs::Metadata` structure was also removed entirely, moving all of
its associated methods into the `os::unix::fs::MetadataExt` trait instead. The
methods are all marked as `#[stable]` still.
As some minor cleanup, some deprecated and unstable fs apis were also removed:
* File::path
* Metadata::accessed
* Metadata::modified
Features that were explicitly left unstable include:
* fs::WalkDir - the semantics of this were not considered in the recent fs
expansion RFC.
* fs::DirBuilder - it's still not 100% clear if the naming is right here and if
the set of functionality exposed is appropriate.
* fs::canonicalize - the implementation on Windows here is specifically in
question as it always returns a verbatim path. Additionally the Unix
implementation is susceptible to buffer overflows on long paths unfortunately.
* fs::PathExt - as this is just a convenience trait, it is not stabilized at
this time.
* fs::set_file_times - this funciton is still waiting on a time abstraction.
2015-05-27 16:29:55 -07:00
|
|
|
#![stable(feature = "raw_os", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
|
2015-11-11 14:25:18 -05:00
|
|
|
#[cfg(any(target_os = "android",
|
2015-11-26 19:05:10 +00:00
|
|
|
target_os = "emscripten",
|
2015-11-11 14:25:18 -05:00
|
|
|
all(target_os = "linux", any(target_arch = "aarch64",
|
2015-12-28 21:09:06 +00:00
|
|
|
target_arch = "arm",
|
|
|
|
target_arch = "powerpc",
|
2016-01-30 13:27:00 -08:00
|
|
|
target_arch = "powerpc64"))))]
|
std: Stabilize a number of new fs features
This commit stabilizes the following APIs, slating them all to be cherry-picked
into the 1.1 release.
* fs::FileType (and transitively the derived trait implementations)
* fs::Metadata::file_type
* fs::FileType::is_dir
* fs::FileType::is_file
* fs::FileType::is_symlink
* fs::DirEntry::metadata
* fs::DirEntry::file_type
* fs::DirEntry::file_name
* fs::set_permissions
* fs::symlink_metadata
* os::raw::{self, *}
* os::{android, bitrig, linux, ...}::raw::{self, *}
* os::{android, bitrig, linux, ...}::fs::MetadataExt
* os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat
* os::unix::fs::PermissionsExt
* os::unix::fs::PermissionsExt::mode
* os::unix::fs::PermissionsExt::set_mode
* os::unix::fs::PermissionsExt::from_mode
* os::unix::fs::OpenOptionsExt
* os::unix::fs::OpenOptionsExt::mode
* os::unix::fs::DirEntryExt
* os::unix::fs::DirEntryExt::ino
* os::windows::fs::MetadataExt
* os::windows::fs::MetadataExt::file_attributes
* os::windows::fs::MetadataExt::creation_time
* os::windows::fs::MetadataExt::last_access_time
* os::windows::fs::MetadataExt::last_write_time
* os::windows::fs::MetadataExt::file_size
The `os::unix::fs::Metadata` structure was also removed entirely, moving all of
its associated methods into the `os::unix::fs::MetadataExt` trait instead. The
methods are all marked as `#[stable]` still.
As some minor cleanup, some deprecated and unstable fs apis were also removed:
* File::path
* Metadata::accessed
* Metadata::modified
Features that were explicitly left unstable include:
* fs::WalkDir - the semantics of this were not considered in the recent fs
expansion RFC.
* fs::DirBuilder - it's still not 100% clear if the naming is right here and if
the set of functionality exposed is appropriate.
* fs::canonicalize - the implementation on Windows here is specifically in
question as it always returns a verbatim path. Additionally the Unix
implementation is susceptible to buffer overflows on long paths unfortunately.
* fs::PathExt - as this is just a convenience trait, it is not stabilized at
this time.
* fs::set_file_times - this funciton is still waiting on a time abstraction.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
|
2015-11-11 14:25:18 -05:00
|
|
|
#[cfg(not(any(target_os = "android",
|
2015-11-26 19:05:10 +00:00
|
|
|
target_os = "emscripten",
|
2015-11-11 14:25:18 -05:00
|
|
|
all(target_os = "linux", any(target_arch = "aarch64",
|
2015-12-28 21:09:06 +00:00
|
|
|
target_arch = "arm",
|
|
|
|
target_arch = "powerpc",
|
2016-01-30 13:27:00 -08:00
|
|
|
target_arch = "powerpc64")))))]
|
std: Stabilize a number of new fs features
This commit stabilizes the following APIs, slating them all to be cherry-picked
into the 1.1 release.
* fs::FileType (and transitively the derived trait implementations)
* fs::Metadata::file_type
* fs::FileType::is_dir
* fs::FileType::is_file
* fs::FileType::is_symlink
* fs::DirEntry::metadata
* fs::DirEntry::file_type
* fs::DirEntry::file_name
* fs::set_permissions
* fs::symlink_metadata
* os::raw::{self, *}
* os::{android, bitrig, linux, ...}::raw::{self, *}
* os::{android, bitrig, linux, ...}::fs::MetadataExt
* os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat
* os::unix::fs::PermissionsExt
* os::unix::fs::PermissionsExt::mode
* os::unix::fs::PermissionsExt::set_mode
* os::unix::fs::PermissionsExt::from_mode
* os::unix::fs::OpenOptionsExt
* os::unix::fs::OpenOptionsExt::mode
* os::unix::fs::DirEntryExt
* os::unix::fs::DirEntryExt::ino
* os::windows::fs::MetadataExt
* os::windows::fs::MetadataExt::file_attributes
* os::windows::fs::MetadataExt::creation_time
* os::windows::fs::MetadataExt::last_access_time
* os::windows::fs::MetadataExt::last_write_time
* os::windows::fs::MetadataExt::file_size
The `os::unix::fs::Metadata` structure was also removed entirely, moving all of
its associated methods into the `os::unix::fs::MetadataExt` trait instead. The
methods are all marked as `#[stable]` still.
As some minor cleanup, some deprecated and unstable fs apis were also removed:
* File::path
* Metadata::accessed
* Metadata::modified
Features that were explicitly left unstable include:
* fs::WalkDir - the semantics of this were not considered in the recent fs
expansion RFC.
* fs::DirBuilder - it's still not 100% clear if the naming is right here and if
the set of functionality exposed is appropriate.
* fs::canonicalize - the implementation on Windows here is specifically in
question as it always returns a verbatim path. Additionally the Unix
implementation is susceptible to buffer overflows on long paths unfortunately.
* fs::PathExt - as this is just a convenience trait, it is not stabilized at
this time.
* fs::set_file_times - this funciton is still waiting on a time abstraction.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
|
|
|
|
#[cfg(any(target_pointer_width = "32", windows))]
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
|
|
|
|
#[cfg(any(target_pointer_width = "32", windows))]
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
|
|
|
|
#[cfg(all(target_pointer_width = "64", not(windows)))]
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
|
|
|
|
#[cfg(all(target_pointer_width = "64", not(windows)))]
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
|
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
|
2015-04-15 23:21:13 -07:00
|
|
|
|
|
|
|
/// 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)]
|
std: Stabilize a number of new fs features
This commit stabilizes the following APIs, slating them all to be cherry-picked
into the 1.1 release.
* fs::FileType (and transitively the derived trait implementations)
* fs::Metadata::file_type
* fs::FileType::is_dir
* fs::FileType::is_file
* fs::FileType::is_symlink
* fs::DirEntry::metadata
* fs::DirEntry::file_type
* fs::DirEntry::file_name
* fs::set_permissions
* fs::symlink_metadata
* os::raw::{self, *}
* os::{android, bitrig, linux, ...}::raw::{self, *}
* os::{android, bitrig, linux, ...}::fs::MetadataExt
* os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat
* os::unix::fs::PermissionsExt
* os::unix::fs::PermissionsExt::mode
* os::unix::fs::PermissionsExt::set_mode
* os::unix::fs::PermissionsExt::from_mode
* os::unix::fs::OpenOptionsExt
* os::unix::fs::OpenOptionsExt::mode
* os::unix::fs::DirEntryExt
* os::unix::fs::DirEntryExt::ino
* os::windows::fs::MetadataExt
* os::windows::fs::MetadataExt::file_attributes
* os::windows::fs::MetadataExt::creation_time
* os::windows::fs::MetadataExt::last_access_time
* os::windows::fs::MetadataExt::last_write_time
* os::windows::fs::MetadataExt::file_size
The `os::unix::fs::Metadata` structure was also removed entirely, moving all of
its associated methods into the `os::unix::fs::MetadataExt` trait instead. The
methods are all marked as `#[stable]` still.
As some minor cleanup, some deprecated and unstable fs apis were also removed:
* File::path
* Metadata::accessed
* Metadata::modified
Features that were explicitly left unstable include:
* fs::WalkDir - the semantics of this were not considered in the recent fs
expansion RFC.
* fs::DirBuilder - it's still not 100% clear if the naming is right here and if
the set of functionality exposed is appropriate.
* fs::canonicalize - the implementation on Windows here is specifically in
question as it always returns a verbatim path. Additionally the Unix
implementation is susceptible to buffer overflows on long paths unfortunately.
* fs::PathExt - as this is just a convenience trait, it is not stabilized at
this time.
* fs::set_file_times - this funciton is still waiting on a time abstraction.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "raw_os", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub enum c_void {
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
|
|
|
|
issue = "0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
#[doc(hidden)] __variant1,
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
|
|
|
|
issue = "0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
#[doc(hidden)] __variant2,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2016-01-22 23:49:57 -08:00
|
|
|
#[allow(unused_imports)]
|
2015-04-15 23:21:13 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-18 13:29:49 +01:00
|
|
|
#[cfg(all(unix, not(target_os = "android")))]
|
|
|
|
#[test]
|
2015-04-15 23:21:13 -07:00
|
|
|
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)]
|
2015-12-18 13:29:49 +01:00
|
|
|
#[test]
|
2015-04-15 23:21:13 -07:00
|
|
|
fn windows() {
|
|
|
|
use os::windows::raw;
|
|
|
|
}
|
|
|
|
}
|