diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-02-26 12:57:00 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-02-27 12:03:57 -0800 |
| commit | cd9010c77e764e9348ecd92dc4a285f6514505dc (patch) | |
| tree | 2f21e810536e25d0aea7c84c5c01768ae99f46b7 /src/libstd | |
| parent | 843c5e6308920018defe62fd1951c8a5b45553b1 (diff) | |
| download | rust-cd9010c77e764e9348ecd92dc4a285f6514505dc.tar.gz rust-cd9010c77e764e9348ecd92dc4a285f6514505dc.zip | |
native: Improve windows file handling
This commit splits the file implementation into file_unix and file_win32. The two implementations have diverged to the point that they share almost 0 code at this point, so it's easier to maintain as separate files. The other major change accompanied with this commit is that file::open is no longer based on libc's open function on windows, but rather windows's CreateFile function. This fixes dealing with binary files on windows (test added in previous commit). This also changes the read/write functions to use ReadFile and WriteFile instead of libc's read/write. Closes #12406
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/libc.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index 73bf4a1e69a..6b692112f5f 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -1745,6 +1745,10 @@ pub mod consts { pub static OPEN_EXISTING: DWORD = 3; pub static TRUNCATE_EXISTING: DWORD = 5; + pub static FILE_APPEND_DATA: DWORD = 0x00000004; + pub static FILE_READ_DATA: DWORD = 0x00000001; + pub static FILE_WRITE_DATA: DWORD = 0x00000002; + pub static FILE_ATTRIBUTE_ARCHIVE: DWORD = 0x20; pub static FILE_ATTRIBUTE_COMPRESSED: DWORD = 0x800; pub static FILE_ATTRIBUTE_DEVICE: DWORD = 0x40; @@ -1791,6 +1795,18 @@ pub mod consts { pub static FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100; pub static FILE_READ_ATTRIBUTES: DWORD = 0x00000080; + pub static STANDARD_RIGHTS_READ: DWORD = 0x20000; + pub static STANDARD_RIGHTS_WRITE: DWORD = 0x20000; + pub static FILE_WRITE_EA: DWORD = 0x00000010; + pub static FILE_READ_EA: DWORD = 0x00000008; + pub static FILE_GENERIC_READ: DWORD = + STANDARD_RIGHTS_READ | FILE_READ_DATA | + FILE_READ_ATTRIBUTES | FILE_READ_EA | SYNCHRONIZE; + pub static FILE_GENERIC_WRITE: DWORD = + STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | + FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_APPEND_DATA | + SYNCHRONIZE; + pub static FILE_BEGIN: DWORD = 0; pub static FILE_CURRENT: DWORD = 1; pub static FILE_END: DWORD = 2; @@ -4231,6 +4247,7 @@ pub mod funcs { pub mod msvcrt { use libc::types::os::arch::c95::{c_int, c_long}; + use libc::types::os::arch::c99::intptr_t; #[nolink] extern { @@ -4239,6 +4256,10 @@ pub mod funcs { #[link_name = "_get_osfhandle"] pub fn get_osfhandle(fd: c_int) -> c_long; + + #[link_name = "_open_osfhandle"] + pub fn open_osfhandle(osfhandle: intptr_t, + flags: c_int) -> c_int; } } } |
