@@ -808,7 +808,7 @@ pub fn errno() -> uint {
808
808
}
809
809
810
810
unsafe {
811
- GetLastError ( ) as uint ;
811
+ GetLastError ( ) as uint
812
812
}
813
813
}
814
814
@@ -852,15 +852,45 @@ pub fn last_os_error() -> ~str {
852
852
if err < 0 {
853
853
die ! ( ~"strerror_r failure");
854
854
}
855
-
855
+
856
856
str::raw::from_c_str(&buf[0])
857
857
}
858
858
}
859
859
860
860
#[cfg(windows)]
861
861
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;
862
884
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])
864
894
}
865
895
}
866
896
0 commit comments