Skip to content

Commit 23bb158

Browse files
committed
fix win32 types, make close() use i32 as return type
1 parent e3699a2 commit 23bb158

File tree

4 files changed

+54
-53
lines changed

4 files changed

+54
-53
lines changed

src/lib/linux_os.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ native mod libc {
3030
fn fread(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
3131
fn fwrite(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
3232
fn open(s: str::sbuf, flags: c_int, mode: unsigned) -> fd_t;
33-
fn close(fd: fd_t) -> int;
33+
fn close(fd: fd_t) -> c_int;
3434
type FILE;
3535
fn fopen(path: str::sbuf, mode: str::sbuf) -> FILE;
3636
fn fdopen(fd: fd_t, mode: str::sbuf) -> FILE;
@@ -54,18 +54,18 @@ native mod libc {
5454
}
5555

5656
mod libc_constants {
57-
const O_RDONLY: c_int = 0;
58-
const O_WRONLY: c_int = 1;
59-
const O_RDWR: c_int = 2;
60-
const O_APPEND: c_int = 1024;
61-
const O_CREAT: c_int = 64;
62-
const O_EXCL: c_int = 128;
63-
const O_TRUNC: c_int = 512;
64-
const O_TEXT: c_int = 0; // nonexistent in linux libc
65-
const O_BINARY: c_int = 0; // nonexistent in linux libc
66-
67-
const S_IRUSR: unsigned = 256u;
68-
const S_IWUSR: unsigned = 128u;
57+
const O_RDONLY: c_int = 0i32;
58+
const O_WRONLY: c_int = 1i32;
59+
const O_RDWR: c_int = 2i32;
60+
const O_APPEND: c_int = 1024i32;
61+
const O_CREAT: c_int = 64i32;
62+
const O_EXCL: c_int = 128i32;
63+
const O_TRUNC: c_int = 512i32;
64+
const O_TEXT: c_int = 0i32; // nonexistent in linux libc
65+
const O_BINARY: c_int = 0i32; // nonexistent in linux libc
66+
67+
const S_IRUSR: unsigned = 256u32;
68+
const S_IWUSR: unsigned = 128u32;
6969
}
7070

7171
fn pipe() -> {in: fd_t, out: fd_t} {
@@ -78,7 +78,7 @@ fn fd_FILE(fd: fd_t) -> libc::FILE {
7878
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
7979
}
8080

81-
fn close(fd: fd_t) -> int {
81+
fn close(fd: fd_t) -> c_int {
8282
libc::close(fd)
8383
}
8484

src/lib/macos_os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ native mod libc {
2424
fn fread(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
2525
fn fwrite(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
2626
fn open(s: str::sbuf, flags: c_int, mode: unsigned) -> fd_t;
27-
fn close(fd: fd_t) -> int;
27+
fn close(fd: fd_t) -> c_int;
2828
type FILE;
2929
fn fopen(path: str::sbuf, mode: str::sbuf) -> FILE;
3030
fn fdopen(fd: fd_t, mode: str::sbuf) -> FILE;
@@ -71,7 +71,7 @@ fn fd_FILE(fd: fd_t) -> libc::FILE {
7171
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
7272
}
7373

74-
fn close(fd: fd_t) -> int {
74+
fn close(fd: fd_t) -> c_int {
7575
libc::close(fd)
7676
}
7777

src/lib/run_program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ fn waitpid(pid: pid_t) -> int {
259259
ret waitpid_os(pid);
260260

261261
#[cfg(target_os = "win32")]
262-
fn waitpid_os(pid: int) -> int {
263-
os::waitpid(pid)
262+
fn waitpid_os(pid: pid_t) -> int {
263+
os::waitpid(pid) as int
264264
}
265265

266266
#[cfg(target_os = "linux")]

src/lib/win32_os.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1+
import ctypes::*;
12

23
#[abi = "cdecl"]
34
#[link_name = ""]
45
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;
910
#[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;
1112
#[link_name = "_close"]
12-
fn close(fd: int) -> int;
13+
fn close(fd: fd_t) -> c_int;
1314
type FILE;
1415
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;
1617
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;
2324
}
2425

2526
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 = 256u; // really _S_IREAD in win32
37-
const S_IWUSR: uint = 128u; // 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
3839
}
3940

4041
type DWORD = u32;
@@ -57,28 +58,28 @@ fn target_os() -> str { ret "win32"; }
5758

5859
fn dylib_filename(base: str) -> str { ret base + ".dll"; }
5960

60-
fn pipe() -> {in: int, out: int} {
61+
fn pipe() -> {in: fd_t, out: fd_t} {
6162
// Windows pipes work subtly differently than unix pipes, and their
6263
// inheritance has to be handled in a different way that I don't fully
6364
// understand. Here we explicitly make the pipe non-inheritable,
6465
// which means to pass it to a subprocess they need to be duplicated
6566
// first, as in rust_run_program.
66-
let fds = {mutable in: 0, mutable out: 0};
67+
let fds = {mutable in: 0i32, mutable out: 0i32};
6768
let res =
68-
os::libc::_pipe(ptr::mut_addr_of(fds.in), 1024u,
69+
os::libc::_pipe(ptr::mut_addr_of(fds.in), 1024u32,
6970
libc_constants::O_BINARY |
7071
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);
7475
ret {in: fds.in, out: fds.out};
7576
}
7677

77-
fn fd_FILE(fd: int) -> libc::FILE {
78+
fn fd_FILE(fd: fd_t) -> libc::FILE {
7879
ret str::as_buf("r", {|modebuf| libc::_fdopen(fd, modebuf) });
7980
}
8081

81-
fn close(fd: int) -> int {
82+
fn close(fd: fd_t) -> c_int {
8283
libc::close(fd)
8384
}
8485

@@ -88,11 +89,11 @@ fn fclose(file: libc::FILE) {
8889

8990
#[abi = "cdecl"]
9091
native mod rustrt {
91-
fn rust_process_wait(handle: int) -> int;
92+
fn rust_process_wait(handle: c_int) -> c_int;
9293
fn rust_getcwd() -> str;
9394
}
9495

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); }
9697

9798
fn getcwd() -> str { ret rustrt::rust_getcwd(); }
9899

0 commit comments

Comments
 (0)