diff options
| author | bors <bors@rust-lang.org> | 2014-05-06 12:41:55 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-06 12:41:55 -0700 |
| commit | cf6857b9e9427f14d383ae2924555bedc251fa02 (patch) | |
| tree | 045b617609058f5042495fd4172b2f2924179360 /src/libnative | |
| parent | 1f6db7f4f6399628eaaca5d38cc5fb38e71b4c23 (diff) | |
| parent | 8d1d7d9b5f3920d70b1edcc258a86106527e83f7 (diff) | |
| download | rust-cf6857b9e9427f14d383ae2924555bedc251fa02.tar.gz rust-cf6857b9e9427f14d383ae2924555bedc251fa02.zip | |
auto merge of #13897 : aturon/rust/issue-6085, r=bjz
The `std::bitflags::bitflags!` macro did not provide support for
adding attributes to the generates structure, due to limitations in
the parser for macros. This patch works around the parser limitations
by requiring a `flags` keyword in the `bitflags!` invocations:
bitflags!(
#[deriving(Hash)]
#[doc="Three flags"]
flags Flags: u32 {
FlagA = 0x00000001,
FlagB = 0x00000010,
FlagC = 0x00000100
}
)
The intent of `std::bitflags` is to allow building type-safe wrappers
around C-style flags APIs. But in addition to construction these flags
from the Rust side, we need a way to convert them from the C
side. This patch adds a `from_bits` function, which is unsafe since
the bits in question may not represent a valid combination of flags.
Finally, this patch changes `std::io::FilePermissions` from an exposed
`u32` representation to a typesafe representation (that only allows valid
flag combinations) using the `std::bitflags`.
Closes #6085.
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/file_unix.rs | 8 | ||||
| -rw-r--r-- | src/libnative/io/file_win32.rs | 6 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index 7c19eb54326..94ca6027841 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -335,7 +335,7 @@ pub fn open(path: &CString, fm: io::FileMode, fa: io::FileAccess) pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> { super::mkerr_libc(retry(|| unsafe { - libc::mkdir(p.with_ref(|p| p), mode as libc::mode_t) + libc::mkdir(p.with_ref(|p| p), mode.bits() as libc::mode_t) })) } @@ -392,7 +392,7 @@ pub fn rename(old: &CString, new: &CString) -> IoResult<()> { pub fn chmod(p: &CString, mode: io::FilePermission) -> IoResult<()> { super::mkerr_libc(retry(|| unsafe { - libc::chmod(p.with_ref(|p| p), mode as libc::mode_t) + libc::chmod(p.with_ref(|p| p), mode.bits() as libc::mode_t) })) } @@ -470,7 +470,9 @@ fn mkstat(stat: &libc::stat, path: &CString) -> io::FileStat { path: Path::new(path), size: stat.st_size as u64, kind: kind, - perm: (stat.st_mode) as io::FilePermission & io::AllPermissions, + perm: unsafe { + io::FilePermission::from_bits(stat.st_mode as u32) & io::AllPermissions + }, created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64), modified: mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64), accessed: mktime(stat.st_atime as u64, stat.st_atime_nsec as u64), diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index aae15a86614..54bb2201314 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -392,7 +392,7 @@ pub fn rename(old: &CString, new: &CString) -> IoResult<()> { pub fn chmod(p: &CString, mode: io::FilePermission) -> IoResult<()> { super::mkerr_libc(as_utf16_p(p.as_str().unwrap(), |p| unsafe { - libc::wchmod(p, mode as libc::c_int) + libc::wchmod(p, mode.bits() as libc::c_int) })) } @@ -471,7 +471,9 @@ fn mkstat(stat: &libc::stat, path: &CString) -> io::FileStat { path: Path::new(path), size: stat.st_size as u64, kind: kind, - perm: (stat.st_mode) as io::FilePermission & io::AllPermissions, + perm: unsafe { + io::FilePermission::from_bits(stat.st_mode as u32) & io::AllPermissions + }, created: stat.st_ctime as u64, modified: stat.st_mtime as u64, accessed: stat.st_atime as u64, |
