@@ -4,82 +4,90 @@ Module: os
4
4
TODO: Restructure and document
5
5
*/
6
6
7
+ import ctypes:: * ;
8
+
9
+ export libc;
10
+ export libc_constants;
11
+ export pipe;
12
+ export fd_FILE;
13
+ export close;
14
+ export fclose;
15
+ export waitpid;
16
+ export getcwd;
17
+ export exec_suffix;
18
+ export target_os;
19
+ export dylib_filename;
20
+ export get_exe_path;
21
+
7
22
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
8
23
// by https://github.com/graydon/rust/issues#issue/268
24
+
9
25
#[ link_name = "" ]
10
26
#[ abi = "cdecl" ]
11
27
native mod libc {
12
- fn read ( fd : int , buf : * u8 , count : uint ) -> int ;
13
- fn write ( fd : int , buf : * u8 , count : uint ) -> int ;
14
- fn fread ( buf : * u8 , size : uint , n : uint , f : libc:: FILE ) -> uint ;
15
- fn fwrite ( buf : * u8 , size : uint , n : uint , f : libc:: FILE ) -> uint ;
16
- fn open ( s : str:: sbuf , flags : int , mode : uint ) -> int ;
17
- fn close ( fd : int ) -> int ;
28
+ fn read ( fd : fd_t , buf : * u8 , count : size_t ) -> ssize_t ;
29
+ fn write ( fd : fd_t , buf : * u8 , count : size_t ) -> ssize_t ;
30
+ fn fread ( buf : * u8 , size : size_t , n : size_t , f : libc:: FILE ) -> size_t ;
31
+ fn fwrite ( buf : * u8 , size : size_t , n : size_t , f : libc:: FILE ) -> size_t ;
32
+ fn open ( s : str:: sbuf , flags : c_int , mode : unsigned ) -> fd_t ;
33
+ fn close ( fd : fd_t ) -> int ;
18
34
type FILE ;
19
35
fn fopen ( path : str:: sbuf , mode : str:: sbuf ) -> FILE ;
20
- fn fdopen ( fd : int , mode : str:: sbuf ) -> FILE ;
36
+ fn fdopen ( fd : fd_t , mode : str:: sbuf ) -> FILE ;
21
37
fn fclose ( f : FILE ) ;
22
- fn fgetc ( f : FILE ) -> int ;
23
- fn ungetc ( c : int , f : FILE ) ;
24
- fn feof ( f : FILE ) -> int ;
25
- fn fseek ( f : FILE , offset : int , whence : int ) -> int ;
26
- fn ftell ( f : FILE ) -> int ;
38
+ fn fgetc ( f : FILE ) -> c_int ;
39
+ fn ungetc ( c : c_int , f : FILE ) ;
40
+ fn feof ( f : FILE ) -> c_int ;
41
+ fn fseek ( f : FILE , offset : long , whence : c_int ) -> c_int ;
42
+ fn ftell ( f : FILE ) -> long ;
27
43
type dir ;
28
44
fn opendir ( d : str:: sbuf ) -> dir ;
29
- fn closedir ( d : dir ) -> int ;
45
+ fn closedir ( d : dir ) -> c_int ;
30
46
type dirent ;
31
47
fn readdir ( d : dir ) -> dirent ;
32
48
fn getenv ( n : str:: sbuf ) -> str:: sbuf ;
33
- fn setenv ( n : str:: sbuf , v : str:: sbuf , overwrite : int ) -> int ;
34
- fn unsetenv ( n : str:: sbuf ) -> int ;
35
- fn pipe ( buf : * mutable int ) -> int ;
36
- fn waitpid ( pid : int , & status: int , options : int ) -> int ;
37
- fn readlink ( path : str:: sbuf , buf : str:: sbuf ,
38
- bufsize : ctypes:: size_t ) -> ctypes:: ssize_t ;
49
+ fn setenv ( n : str:: sbuf , v : str:: sbuf , overwrite : c_int ) -> c_int ;
50
+ fn unsetenv ( n : str:: sbuf ) -> c_int ;
51
+ fn pipe ( buf : * mutable fd_t ) -> c_int ;
52
+ fn waitpid ( pid : pid_t , & status: c_int , options : c_int ) -> pid_t ;
39
53
}
40
54
41
55
mod libc_constants {
42
- const O_RDONLY : int = 0 ;
43
- const O_WRONLY : int = 1 ;
44
- const O_RDWR : int = 2 ;
45
- const O_APPEND : int = 1024 ;
46
- const O_CREAT : int = 64 ;
47
- const O_EXCL : int = 128 ;
48
- const O_TRUNC : int = 512 ;
49
- const O_TEXT : int = 0 ; // nonexistent in linux libc
50
- const O_BINARY : int = 0 ; // nonexistent in linux libc
51
-
52
- const S_IRUSR : uint = 256 u;
53
- const S_IWUSR : uint = 128 u;
54
- }
56
+ const O_RDONLY : c_int = 0 ;
57
+ const O_WRONLY : c_int = 1 ;
58
+ const O_RDWR : c_int = 2 ;
59
+ const O_APPEND : c_int = 1024 ;
60
+ const O_CREAT : c_int = 64 ;
61
+ const O_EXCL : c_int = 128 ;
62
+ const O_TRUNC : c_int = 512 ;
63
+ const O_TEXT : c_int = 0 ; // nonexistent in linux libc
64
+ const O_BINARY : c_int = 0 ; // nonexistent in linux libc
55
65
56
- // FIXME turn into constants
57
- fn exec_suffix ( ) -> str { ret "" ; }
58
- fn target_os ( ) -> str { ret "linux" ; }
59
-
60
- fn dylib_filename ( base : str ) -> str { ret "lib" + base + ".so" ; }
66
+ const S_IRUSR : unsigned = 256 u;
67
+ const S_IWUSR : unsigned = 128 u;
68
+ }
61
69
62
- fn pipe ( ) -> { in: int , out: int } {
63
- let fds = { mutable in: 0 , mutable out: 0 } ;
64
- assert ( os:: libc:: pipe ( ptr:: mut_addr_of ( fds. in ) ) == 0 ) ;
70
+ fn pipe ( ) -> { in: fd_t , out: fd_t } {
71
+ let fds = { mutable in: 0i32 , mutable out: 0i32 } ;
72
+ assert ( os:: libc:: pipe ( ptr:: mut_addr_of ( fds. in ) ) == 0i32 ) ;
65
73
ret { in : fds. in , out : fds. out } ;
66
74
}
67
75
68
- fn fd_FILE ( fd : int ) -> libc:: FILE {
76
+ fn fd_FILE ( fd : fd_t ) -> libc:: FILE {
69
77
ret str:: as_buf ( "r" , { |modebuf| libc:: fdopen ( fd, modebuf) } ) ;
70
78
}
71
79
72
- fn close ( fd : int ) -> int {
80
+ fn close ( fd : fd_t ) -> int {
73
81
libc:: close ( fd)
74
82
}
75
83
76
84
fn fclose ( file : libc:: FILE ) {
77
85
libc:: fclose ( file)
78
86
}
79
87
80
- fn waitpid ( pid : int ) -> int {
81
- let status = 0 ;
82
- assert ( os:: libc:: waitpid ( pid, status, 0 ) != -1 ) ;
88
+ fn waitpid ( pid : pid_t ) -> i32 {
89
+ let status = 0i32 ;
90
+ assert ( os:: libc:: waitpid ( pid, status, 0i32 ) != -1i32 ) ;
83
91
ret status;
84
92
}
85
93
@@ -90,6 +98,12 @@ native mod rustrt {
90
98
91
99
fn getcwd ( ) -> str { ret rustrt:: rust_getcwd ( ) ; }
92
100
101
+ fn exec_suffix ( ) -> str { ret "" ; }
102
+
103
+ fn target_os ( ) -> str { ret "linux" ; }
104
+
105
+ fn dylib_filename ( base : str ) -> str { ret "lib" + base + ".so" ; }
106
+
93
107
/// Returns the directory containing the running program
94
108
/// followed by a path separator
95
109
fn get_exe_path ( ) -> option:: t < fs:: path > {
0 commit comments