1
+ import ctypes:: * ;
1
2
2
3
#[ abi = "cdecl" ]
3
4
#[ link_name = "" ]
4
5
native mod libc {
5
- fn read ( fd : int , buf : * u8 , count : uint ) -> int ;
6
- fn write ( fd : int , buf : * u8 , count : uint ) -> int ;
7
- fn fread ( buf : * u8 , size : uint , n : uint , f : libc:: FILE ) -> uint ;
8
- fn fwrite ( buf : * u8 , size : uint , n : uint , f : libc:: FILE ) -> uint ;
6
+ fn read ( fd : fd_t , buf : * u8 , count : size_t ) -> ssize_t ;
7
+ fn write ( fd : fd_t , buf : * u8 , count : size_t ) -> ssize_t ;
8
+ fn fread ( buf : * u8 , size : size_t , n : size_t , f : libc:: FILE ) -> size_t ;
9
+ fn fwrite ( buf : * u8 , size : size_t , n : size_t , f : libc:: FILE ) -> size_t ;
9
10
#[ link_name = "_open" ]
10
- fn open ( s : str:: sbuf , flags : int , mode : uint ) -> int ;
11
+ fn open ( s : str:: sbuf , flags : c_int , mode : c_int ) -> c_int ;
11
12
#[ link_name = "_close" ]
12
- fn close ( fd : int ) -> int ;
13
+ fn close ( fd : fd_t ) -> c_int ;
13
14
type FILE ;
14
15
fn fopen ( path : str:: sbuf , mode : str:: sbuf ) -> FILE ;
15
- fn _fdopen ( fd : int , mode : str:: sbuf ) -> FILE ;
16
+ fn _fdopen ( fd : fd_t , mode : str:: sbuf ) -> FILE ;
16
17
fn fclose ( f : FILE ) ;
17
- fn fgetc ( f : FILE ) -> int ;
18
- fn ungetc ( c : int , f : FILE ) ;
19
- fn feof ( f : FILE ) -> int ;
20
- fn fseek ( f : FILE , offset : int , whence : int ) -> int ;
21
- fn ftell ( f : FILE ) -> int ;
22
- fn _pipe ( fds : * mutable int , size : uint , mode : int ) -> int ;
18
+ fn fgetc ( f : FILE ) -> c_int ;
19
+ fn ungetc ( c : c_int , f : FILE ) ;
20
+ fn feof ( f : FILE ) -> c_int ;
21
+ fn fseek ( f : FILE , offset : long , whence : c_int ) -> c_int ;
22
+ fn ftell ( f : FILE ) -> long ;
23
+ fn _pipe ( fds : * mutable fd_t , size : unsigned , mode : c_int ) -> c_int ;
23
24
}
24
25
25
26
mod libc_constants {
26
- const O_RDONLY : int = 0 ;
27
- const O_WRONLY : int = 1 ;
28
- const O_RDWR : int = 2 ;
29
- const O_APPEND : int = 8 ;
30
- const O_CREAT : int = 256 ;
31
- const O_EXCL : int = 1024 ;
32
- const O_TRUNC : int = 512 ;
33
- const O_TEXT : int = 16384 ;
34
- const O_BINARY : int = 32768 ;
35
- const O_NOINHERIT : int = 128 ;
36
- const S_IRUSR : uint = 256 u ; // really _S_IREAD in win32
37
- const S_IWUSR : uint = 128 u ; // really _S_IWRITE in win32
27
+ const O_RDONLY : c_int = 0i32 ;
28
+ const O_WRONLY : c_int = 1i32 ;
29
+ const O_RDWR : c_int = 2i32 ;
30
+ const O_APPEND : c_int = 8i32 ;
31
+ const O_CREAT : c_int = 256i32 ;
32
+ const O_EXCL : c_int = 1024i32 ;
33
+ const O_TRUNC : c_int = 512i32 ;
34
+ const O_TEXT : c_int = 16384i32 ;
35
+ const O_BINARY : c_int = 32768i32 ;
36
+ const O_NOINHERIT : c_int = 128i32 ;
37
+ const S_IRUSR : unsigned = 256u32 ; // really _S_IREAD in win32
38
+ const S_IWUSR : unsigned = 128u32 ; // really _S_IWRITE in win32
38
39
}
39
40
40
41
type DWORD = u32 ;
@@ -57,28 +58,28 @@ fn target_os() -> str { ret "win32"; }
57
58
58
59
fn dylib_filename ( base : str ) -> str { ret base + ".dll" ; }
59
60
60
- fn pipe ( ) -> { in: int , out: int } {
61
+ fn pipe ( ) -> { in: fd_t , out: fd_t } {
61
62
// Windows pipes work subtly differently than unix pipes, and their
62
63
// inheritance has to be handled in a different way that I don't fully
63
64
// understand. Here we explicitly make the pipe non-inheritable,
64
65
// which means to pass it to a subprocess they need to be duplicated
65
66
// first, as in rust_run_program.
66
- let fds = { mutable in: 0 , mutable out: 0 } ;
67
+ let fds = { mutable in: 0i32 , mutable out: 0i32 } ;
67
68
let res =
68
- os:: libc:: _pipe ( ptr:: mut_addr_of ( fds. in ) , 1024 u ,
69
+ os:: libc:: _pipe ( ptr:: mut_addr_of ( fds. in ) , 1024u32 ,
69
70
libc_constants:: O_BINARY |
70
71
libc_constants:: O_NOINHERIT ) ;
71
- assert ( res == 0 ) ;
72
- assert ( fds. in != -1 && fds. in != 0 ) ;
73
- assert ( fds. out != -1 && fds. in != 0 ) ;
72
+ assert ( res == 0i32 ) ;
73
+ assert ( fds. in != -1i32 && fds. in != 0i32 ) ;
74
+ assert ( fds. out != -1i32 && fds. in != 0i32 ) ;
74
75
ret { in : fds. in , out : fds. out } ;
75
76
}
76
77
77
- fn fd_FILE ( fd : int ) -> libc:: FILE {
78
+ fn fd_FILE ( fd : fd_t ) -> libc:: FILE {
78
79
ret str:: as_buf ( "r" , { |modebuf| libc:: _fdopen ( fd, modebuf) } ) ;
79
80
}
80
81
81
- fn close ( fd : int ) -> int {
82
+ fn close ( fd : fd_t ) -> c_int {
82
83
libc:: close ( fd)
83
84
}
84
85
@@ -88,11 +89,11 @@ fn fclose(file: libc::FILE) {
88
89
89
90
#[ abi = "cdecl" ]
90
91
native mod rustrt {
91
- fn rust_process_wait ( handle : int ) -> int ;
92
+ fn rust_process_wait ( handle : c_int ) -> c_int ;
92
93
fn rust_getcwd ( ) -> str ;
93
94
}
94
95
95
- fn waitpid ( pid : int ) -> int { ret rustrt:: rust_process_wait ( pid) ; }
96
+ fn waitpid ( pid : pid_t ) -> i32 { ret rustrt:: rust_process_wait ( pid) ; }
96
97
97
98
fn getcwd ( ) -> str { ret rustrt:: rust_getcwd ( ) ; }
98
99
0 commit comments