Skip to content

Commit 95b9d53

Browse files
committed
Use #[cfg(unix)] and #[cfg(windows)] everywhere
1 parent 7ef825b commit 95b9d53

File tree

18 files changed

+103
-187
lines changed

18 files changed

+103
-187
lines changed

src/libcore/cmath.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ native mod c_double {
4848
pure fn frexp(n: c_double, &value: c_int) -> c_double;
4949
pure fn hypot(x: c_double, y: c_double) -> c_double;
5050
pure fn ldexp(x: c_double, n: c_int) -> c_double;
51-
#[cfg(target_os = "linux")]
52-
#[cfg(target_os = "macos")]
53-
#[cfg(target_os = "freebsd")]
51+
#[cfg(unix)]
5452
#[link_name="lgamma_r"] pure fn lgamma(n: c_double,
5553
&sign: c_int) -> c_double;
56-
#[cfg(target_os = "win32")]
54+
#[cfg(windows)]
5755
#[link_name="__lgamma_r"] pure fn lgamma(n: c_double,
5856
&sign: c_int) -> c_double;
5957
// renamed: log is a reserved keyword; ln seems more natural, too
@@ -131,13 +129,11 @@ native mod c_float {
131129
#[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float;
132130
#[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float;
133131

134-
#[cfg(target_os="linux")]
135-
#[cfg(target_os="macos")]
136-
#[cfg(target_os="freebsd")]
132+
#[cfg(unix)]
137133
#[link_name="lgammaf_r"] pure fn lgamma(n: c_float,
138134
&sign: c_int) -> c_float;
139135

140-
#[cfg(target_os="win32")]
136+
#[cfg(windows)]
141137
#[link_name="__lgammaf_r"] pure fn lgamma(n: c_float,
142138
&sign: c_int) -> c_float;
143139

src/libcore/comm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,15 @@ fn test_recv_chan() {
420420

421421
#[test]
422422
#[should_fail]
423-
#[ignore(cfg(target_os = "win32"))]
423+
#[ignore(cfg(windows))]
424424
fn test_recv_chan_dead() {
425425
let ch = chan(port());
426426
send(ch, "flower");
427427
recv_chan(ch);
428428
}
429429

430430
#[test]
431-
#[ignore(cfg(target_os = "win32"))]
431+
#[ignore(cfg(windows))]
432432
fn test_recv_chan_wrong_task() {
433433
let po = port();
434434
let ch = chan(po);
@@ -464,7 +464,7 @@ fn test_listen() {
464464
}
465465

466466
#[test]
467-
#[ignore(cfg(target_os="win32"))]
467+
#[ignore(cfg(windows))]
468468
fn test_port_detach_fail() {
469469
iter::repeat(100u) {||
470470
let builder = task::builder();

src/libcore/io.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,10 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> writer {
398398
fn mk_file_writer(path: str, flags: [fileflag])
399399
-> result<writer, str> {
400400

401-
#[cfg(target_os = "win32")]
401+
#[cfg(windows)]
402402
fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int }
403403

404-
#[cfg(target_os = "linux")]
405-
#[cfg(target_os = "macos")]
406-
#[cfg(target_os = "freebsd")]
404+
#[cfg(unix)]
407405
fn wb() -> c_int { O_WRONLY as c_int }
408406

409407
let mut fflags: c_int = wb();

src/libcore/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn test_min() {
229229
230230
#[test]
231231
#[should_fail]
232-
#[ignore(cfg(target_os = "win32"))]
232+
#[ignore(cfg(windows))]
233233
fn test_min_empty() {
234234
min::<int, [int]>([]);
235235
}
@@ -241,7 +241,7 @@ fn test_max() {
241241
242242
#[test]
243243
#[should_fail]
244-
#[ignore(cfg(target_os = "win32"))]
244+
#[ignore(cfg(windows))]
245245
fn test_max_empty() {
246246
max::<int, [int]>([]);
247247
}

src/libcore/os.rs

+35-61
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
7979
}
8080
}
8181

82-
#[cfg(target_os = "win32")]
82+
#[cfg(windows)]
8383
mod win32 {
8484
import dword = libc::types::os::arch::extra::DWORD;
8585

@@ -200,9 +200,7 @@ mod global_env {
200200

201201
mod impl {
202202

203-
#[cfg(target_os = "linux")]
204-
#[cfg(target_os = "macos")]
205-
#[cfg(target_os = "freebsd")]
203+
#[cfg(unix)]
206204
fn getenv(n: str) -> option<str> unsafe {
207205
let s = str::as_c_str(n, libc::getenv);
208206
ret if unsafe::reinterpret_cast(s) == 0 {
@@ -213,7 +211,7 @@ mod global_env {
213211
};
214212
}
215213

216-
#[cfg(target_os = "win32")]
214+
#[cfg(windows)]
217215
fn getenv(n: str) -> option<str> unsafe {
218216
import libc::types::os::arch::extra::*;
219217
import libc::funcs::extra::kernel32::*;
@@ -226,9 +224,7 @@ mod global_env {
226224
}
227225

228226

229-
#[cfg(target_os = "linux")]
230-
#[cfg(target_os = "macos")]
231-
#[cfg(target_os = "freebsd")]
227+
#[cfg(unix)]
232228
fn setenv(n: str, v: str) {
233229

234230
// FIXME: remove this when export globs work properly.
@@ -241,7 +237,7 @@ mod global_env {
241237
}
242238

243239

244-
#[cfg(target_os = "win32")]
240+
#[cfg(windows)]
245241
fn setenv(n: str, v: str) {
246242
// FIXME: remove imports when export globs work properly.
247243
import libc::funcs::extra::kernel32::*;
@@ -265,7 +261,7 @@ fn fdopen(fd: c_int) -> *FILE {
265261

266262
// fsync related
267263

268-
#[cfg(target_os = "win32")]
264+
#[cfg(windows)]
269265
fn fsync_fd(fd: c_int, _level: io::fsync::level) -> c_int {
270266
import libc::funcs::extra::msvcrt::*;
271267
ret commit(fd);
@@ -305,14 +301,12 @@ fn fsync_fd(fd: c_int, _l: io::fsync::level) -> c_int {
305301
}
306302

307303

308-
#[cfg(target_os = "win32")]
304+
#[cfg(windows)]
309305
fn waitpid(pid: pid_t) -> c_int {
310306
ret rustrt::rust_process_wait(pid);
311307
}
312308

313-
#[cfg(target_os = "linux")]
314-
#[cfg(target_os = "freebsd")]
315-
#[cfg(target_os = "macos")]
309+
#[cfg(unix)]
316310
fn waitpid(pid: pid_t) -> c_int {
317311
import libc::funcs::posix01::wait::*;
318312
let status = 0 as c_int;
@@ -323,9 +317,7 @@ fn waitpid(pid: pid_t) -> c_int {
323317
}
324318

325319

326-
#[cfg(target_os = "linux")]
327-
#[cfg(target_os = "freebsd")]
328-
#[cfg(target_os = "macos")]
320+
#[cfg(unix)]
329321
fn pipe() -> {in: c_int, out: c_int} {
330322
let fds = {mut in: 0 as c_int,
331323
mut out: 0 as c_int };
@@ -335,7 +327,7 @@ fn pipe() -> {in: c_int, out: c_int} {
335327

336328

337329

338-
#[cfg(target_os = "win32")]
330+
#[cfg(windows)]
339331
fn pipe() -> {in: c_int, out: c_int} {
340332
// FIXME: remove this when export globs work properly.
341333
import libc::consts::os::extra::*;
@@ -359,12 +351,10 @@ fn pipe() -> {in: c_int, out: c_int} {
359351
fn dll_filename(base: str) -> str {
360352
ret pre() + base + dll_suffix();
361353

362-
#[cfg(target_os = "macos")]
363-
#[cfg(target_os = "linux")]
364-
#[cfg(target_os = "freebsd")]
354+
#[cfg(unix)]
365355
fn pre() -> str { "lib" }
366356

367-
#[cfg(target_os = "win32")]
357+
#[cfg(windows)]
368358
fn pre() -> str { "" }
369359
}
370360

@@ -405,7 +395,7 @@ fn self_exe_path() -> option<path> {
405395
}
406396
}
407397

408-
#[cfg(target_os = "win32")]
398+
#[cfg(windows)]
409399
fn load_self() -> option<path> unsafe {
410400
// FIXME: remove imports when export globs work properly.
411401
import libc::types::os::arch::extra::*;
@@ -449,14 +439,12 @@ fn homedir() -> option<path> {
449439
}
450440
};
451441

452-
#[cfg(target_os = "linux")]
453-
#[cfg(target_os = "macos")]
454-
#[cfg(target_os = "freebsd")]
442+
#[cfg(unix)]
455443
fn secondary() -> option<path> {
456444
none
457445
}
458446

459-
#[cfg(target_os = "win32")]
447+
#[cfg(windows)]
460448
fn secondary() -> option<path> {
461449
option::chain(getenv("USERPROFILE")) {|p|
462450
if !str::is_empty(p) {
@@ -536,7 +524,7 @@ fn make_absolute(p: path) -> path {
536524
fn make_dir(p: path, mode: c_int) -> bool {
537525
ret mkdir(p, mode);
538526

539-
#[cfg(target_os = "win32")]
527+
#[cfg(windows)]
540528
fn mkdir(p: path, _mode: c_int) -> bool unsafe {
541529
// FIXME: remove imports when export globs work properly.
542530
import libc::types::os::arch::extra::*;
@@ -549,9 +537,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
549537
}
550538
}
551539

552-
#[cfg(target_os = "linux")]
553-
#[cfg(target_os = "macos")]
554-
#[cfg(target_os = "freebsd")]
540+
#[cfg(unix)]
555541
fn mkdir(p: path, mode: c_int) -> bool {
556542
as_c_charp(p) {|c|
557543
libc::mkdir(c, mode as mode_t) == (0 as c_int)
@@ -562,12 +548,10 @@ fn make_dir(p: path, mode: c_int) -> bool {
562548
#[doc = "Lists the contents of a directory"]
563549
fn list_dir(p: path) -> [str] {
564550

565-
#[cfg(target_os = "linux")]
566-
#[cfg(target_os = "macos")]
567-
#[cfg(target_os = "freebsd")]
551+
#[cfg(unix)]
568552
fn star(p: str) -> str { p }
569553

570-
#[cfg(target_os = "win32")]
554+
#[cfg(windows)]
571555
fn star(p: str) -> str {
572556
let pl = str::len(p);
573557
if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
@@ -602,7 +586,7 @@ fn list_dir_path(p: path) -> [str] {
602586
fn remove_dir(p: path) -> bool {
603587
ret rmdir(p);
604588

605-
#[cfg(target_os = "win32")]
589+
#[cfg(windows)]
606590
fn rmdir(p: path) -> bool {
607591
// FIXME: remove imports when export globs work properly.
608592
import libc::funcs::extra::kernel32::*;
@@ -613,9 +597,7 @@ fn remove_dir(p: path) -> bool {
613597
};
614598
}
615599

616-
#[cfg(target_os = "linux")]
617-
#[cfg(target_os = "macos")]
618-
#[cfg(target_os = "freebsd")]
600+
#[cfg(unix)]
619601
fn rmdir(p: path) -> bool {
620602
ret as_c_charp(p) {|buf|
621603
libc::rmdir(buf) == (0 as c_int)
@@ -626,7 +608,7 @@ fn remove_dir(p: path) -> bool {
626608
fn change_dir(p: path) -> bool {
627609
ret chdir(p);
628610

629-
#[cfg(target_os = "win32")]
611+
#[cfg(windows)]
630612
fn chdir(p: path) -> bool {
631613
// FIXME: remove imports when export globs work properly.
632614
import libc::funcs::extra::kernel32::*;
@@ -637,9 +619,7 @@ fn change_dir(p: path) -> bool {
637619
};
638620
}
639621

640-
#[cfg(target_os = "linux")]
641-
#[cfg(target_os = "macos")]
642-
#[cfg(target_os = "freebsd")]
622+
#[cfg(unix)]
643623
fn chdir(p: path) -> bool {
644624
ret as_c_charp(p) {|buf|
645625
libc::chdir(buf) == (0 as c_int)
@@ -651,7 +631,7 @@ fn change_dir(p: path) -> bool {
651631
fn copy_file(from: path, to: path) -> bool {
652632
ret do_copy_file(from, to);
653633

654-
#[cfg(target_os = "win32")]
634+
#[cfg(windows)]
655635
fn do_copy_file(from: path, to: path) -> bool {
656636
// FIXME: remove imports when export globs work properly.
657637
import libc::funcs::extra::kernel32::*;
@@ -664,9 +644,7 @@ fn copy_file(from: path, to: path) -> bool {
664644
}
665645
}
666646

667-
#[cfg(target_os = "linux")]
668-
#[cfg(target_os = "macos")]
669-
#[cfg(target_os = "freebsd")]
647+
#[cfg(unix)]
670648
fn do_copy_file(from: path, to: path) -> bool unsafe {
671649
let istream = as_c_charp(from) {|fromp|
672650
as_c_charp("rb") {|modebuf|
@@ -716,7 +694,7 @@ fn copy_file(from: path, to: path) -> bool {
716694
fn remove_file(p: path) -> bool {
717695
ret unlink(p);
718696

719-
#[cfg(target_os = "win32")]
697+
#[cfg(windows)]
720698
fn unlink(p: path) -> bool {
721699
// FIXME: remove imports when export globs work properly.
722700
// (similar to Issue #2006)
@@ -728,9 +706,7 @@ fn remove_file(p: path) -> bool {
728706
};
729707
}
730708

731-
#[cfg(target_os = "linux")]
732-
#[cfg(target_os = "macos")]
733-
#[cfg(target_os = "freebsd")]
709+
#[cfg(unix)]
734710
fn unlink(p: path) -> bool {
735711
ret as_c_charp(p) {|buf|
736712
libc::unlink(buf) == (0 as c_int)
@@ -755,12 +731,10 @@ fn set_exit_status(code: int) {
755731
rustrt::rust_set_exit_status(code as libc::intptr_t);
756732
}
757733

758-
#[cfg(target_os = "macos")]
759-
#[cfg(target_os = "linux")]
760-
#[cfg(target_os = "freebsd")]
734+
#[cfg(unix)]
761735
fn family() -> str { "unix" }
762736

763-
#[cfg(target_os = "win32")]
737+
#[cfg(windows)]
764738
fn family() -> str { "windows" }
765739

766740
#[cfg(target_os = "macos")]
@@ -824,7 +798,8 @@ mod tests {
824798
}
825799

826800
#[test]
827-
#[ignore(cgf(target_os = "win32"))]
801+
#[ignore(cfg(windows))]
802+
#[ignore]
828803
fn test_setenv_overwrite() {
829804
let n = make_rand_name();
830805
setenv(n, "1");
@@ -837,7 +812,8 @@ mod tests {
837812
// Windows GetEnvironmentVariable requires some extra work to make sure
838813
// the buffer the variable is copied into is the right size
839814
#[test]
840-
#[ignore(cgf(target_os = "win32"))]
815+
#[ignore(cfg(windows))]
816+
#[ignore]
841817
fn test_getenv_big() {
842818
let mut s = "";
843819
let mut i = 0;
@@ -902,9 +878,7 @@ mod tests {
902878
}
903879

904880
#[test]
905-
#[cfg(target_os = "linux")]
906-
#[cfg(target_os = "macos")]
907-
#[cfg(target_os = "freebsd")]
881+
#[cfg(unix)]
908882
fn homedir() {
909883
let oldhome = getenv("HOME");
910884

@@ -918,7 +892,7 @@ mod tests {
918892
}
919893

920894
#[test]
921-
#[cfg(target_os = "win32")]
895+
#[cfg(windows)]
922896
fn homedir() {
923897

924898
let oldhome = getenv("HOME");

0 commit comments

Comments
 (0)