]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-13259-windows-tcb-trash.rs
auto merge of #17654 : gereeter/rust/no-unnecessary-cell, r=alexcrichton
[rust.git] / src / test / run-pass / issue-13259-windows-tcb-trash.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 extern crate libc;
12
13 #[cfg(windows)]
14 mod imp {
15     use libc::{c_void, LPVOID, DWORD};
16     use libc::types::os::arch::extra::LPWSTR;
17
18     extern "system" {
19         fn FormatMessageW(flags: DWORD,
20                           lpSrc: LPVOID,
21                           msgId: DWORD,
22                           langId: DWORD,
23                           buf: LPWSTR,
24                           nsize: DWORD,
25                           args: *const c_void)
26                           -> DWORD;
27     }
28
29     pub fn test() {
30         let mut buf: [u16, ..50] = [0, ..50];
31         let ret = unsafe {
32             FormatMessageW(0x1000, 0 as *mut c_void, 1, 0x400,
33                            buf.as_mut_ptr(), buf.len() as u32, 0 as *const c_void)
34         };
35         // On some 32-bit Windowses (Win7-8 at least) this will fail with segmented
36         // stacks taking control of pvArbitrary
37         assert!(ret != 0);
38     }
39 }
40
41 #[cfg(not(windows))]
42 mod imp {
43     pub fn test() { }
44 }
45
46 fn main() {
47     imp::test()
48 }