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
+
1
11
extern crate libc;
2
- use libc:: { c_void, LPVOID , DWORD } ;
3
- use libc:: types:: os:: arch:: extra:: LPWSTR ;
4
12
5
- extern "system" {
6
- fn FormatMessageW ( flags : DWORD ,
7
- lpSrc : LPVOID ,
8
- msgId : DWORD ,
9
- langId : DWORD ,
10
- buf : LPWSTR ,
11
- nsize : DWORD ,
12
- args : * const c_void )
13
- -> DWORD ;
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
+ }
14
39
}
15
40
16
- fn test ( ) {
17
- let mut buf: [ u16 , ..50 ] = [ 0 , ..50 ] ;
18
- let ret = unsafe {
19
- FormatMessageW ( 0x1000 , 0 as * mut c_void , 1 , 0x400 ,
20
- buf. as_mut_ptr ( ) , buf. len ( ) as u32 , 0 as * const c_void )
21
- } ;
22
- // On some 32-bit Windowses (Win7-8 at least) this will fail with segmented
23
- // stacks taking control of pvArbitrary
24
- assert ! ( ret != 0 ) ;
41
+ #[ cfg( not( windows) ) ]
42
+ mod imp {
43
+ pub fn test ( ) { }
25
44
}
45
+
26
46
fn main ( ) {
27
- test ( )
28
- }
47
+ imp :: test ( )
48
+ }
0 commit comments