auto merge of #13078 : klutzy/rust/issue-13075, r=alexcrichton

`FormatMessageW()` is called by `std::os::last_os_error()` to convert
errno into string, but the function may fail on non-english locale.
I don't know why it fails, but anyway it's better to return errno
than to `fail!()` in the case.

Fixes #13075
Fixes #13073
This commit is contained in:
bors 2014-03-22 08:36:50 -07:00
commit 5e8e1b515a

View file

@ -740,11 +740,16 @@ fn FormatMessageW(flags: DWORD,
buf.len() as DWORD,
ptr::null());
if res == 0 {
fail!("[{}] FormatMessage failure", errno());
// Sometimes FormatMessageW can fail e.g. system doesn't like langId,
let fm_err = errno();
return format!("OS Error {} (FormatMessageW() returned error {})", err, fm_err);
}
str::from_utf16(str::truncate_utf16_at_nul(buf))
.expect("FormatMessageW returned invalid UTF-16")
let msg = str::from_utf16(str::truncate_utf16_at_nul(buf));
match msg {
Some(msg) => format!("OS Error {}: {}", err, msg),
None => format!("OS Error {} (FormatMessageW() returned invalid UTF-16)", err),
}
}
}