Skip to content

Commit f5f786f

Browse files
committed
---
yaml --- r: 44386 b: refs/heads/master c: 625fac3 h: refs/heads/master v: v3
1 parent 598ca87 commit f5f786f

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9877d98b8f91be7e1494e84d685882996b84c877
2+
refs/heads/master: 625fac3c7eea1d28a38f0636b100b60dd4be15aa
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/src/libcore/os.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ pub fn errno() -> uint {
808808
}
809809

810810
unsafe {
811-
GetLastError() as uint;
811+
GetLastError() as uint
812812
}
813813
}
814814

@@ -852,15 +852,45 @@ pub fn last_os_error() -> ~str {
852852
if err < 0 {
853853
die!(~"strerror_r failure");
854854
}
855-
855+
856856
str::raw::from_c_str(&buf[0])
857857
}
858858
}
859859
860860
#[cfg(windows)]
861861
fn strerror() -> ~str {
862+
use libc::types::os::arch::extra::DWORD;
863+
use libc::types::os::arch::extra::LPSTR;
864+
use libc::types::os::arch::extra::LPVOID;
865+
866+
#[link_name = "kernel32"]
867+
#[abi = "stdcall"]
868+
extern {
869+
unsafe fn FormatMessageA(flags: DWORD, lpSrc: LPVOID,
870+
msgId: DWORD, langId: DWORD,
871+
buf: LPSTR, nsize: DWORD,
872+
args: *c_void) -> DWORD;
873+
}
874+
875+
const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
876+
const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
877+
878+
let mut buf = [0 as c_char, ..TMPBUF_SZ];
879+
880+
// This value is calculated from the macro
881+
// MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT)
882+
let langId = 0x0800 as DWORD;
883+
let err = errno() as DWORD;
862884
unsafe {
863-
rustrt::last_os_error()
885+
let res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
886+
FORMAT_MESSAGE_IGNORE_INSERTS,
887+
ptr::mut_null(), err, langId,
888+
&mut buf[0], TMPBUF_SZ as DWORD, ptr::null());
889+
if res == 0 {
890+
die!(fmt!("[%?] FormatMessage failure", errno()));
891+
}
892+
893+
str::raw::from_c_str(&buf[0])
864894
}
865895
}
866896

0 commit comments

Comments
 (0)