Skip to content

Commit ef59723

Browse files
committed
---
yaml --- r: 67231 b: refs/heads/master c: cfd89c4 h: refs/heads/master i: 67229: adc9b4c 67227: 86728d7 67223: fa8ef9a 67215: 40b7775 67199: 30c83ab v: v3
1 parent d3d98b1 commit ef59723

File tree

3 files changed

+40
-45
lines changed

3 files changed

+40
-45
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9ad815e063e8c7785cc10ea1afac55a19ea4e51a
2+
refs/heads/master: cfd89c407598673bf55ea11525b1398c53cd3725
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libstd/io.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use iterator::IteratorUtil;
6363
use ptr;
6464
use result;
6565
use str;
66-
use str::StrSlice;
66+
use str::{StrSlice, OwnedStr, StrUtil};
6767
use to_str::ToStr;
6868
use uint;
6969
use vec;
@@ -1031,17 +1031,16 @@ pub fn stdin() -> @Reader {
10311031
}
10321032

10331033
pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
1034-
unsafe {
1035-
let f = os::as_c_charp(path.to_str(), |pathbuf| {
1036-
os::as_c_charp("r", |modebuf|
1037-
libc::fopen(pathbuf, modebuf)
1038-
)
1039-
});
1040-
return if f as uint == 0u { result::Err(~"error opening "
1041-
+ path.to_str()) }
1042-
else {
1043-
result::Ok(FILE_reader(f, true))
1034+
let f = do path.to_str().as_c_str |pathbuf| {
1035+
do "r".as_c_str |modebuf| {
1036+
unsafe { libc::fopen(pathbuf, modebuf as *libc::c_char) }
10441037
}
1038+
};
1039+
1040+
if f as uint == 0u {
1041+
result::Err(~"error opening " + path.to_str())
1042+
} else {
1043+
result::Ok(FILE_reader(f, true))
10451044
}
10461045
}
10471046
@@ -1282,7 +1281,7 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
12821281
}
12831282
}
12841283
let fd = unsafe {
1285-
do os::as_c_charp(path.to_str()) |pathbuf| {
1284+
do path.to_str().as_c_str |pathbuf| {
12861285
libc::open(pathbuf, fflags,
12871286
(S_IRUSR | S_IWUSR) as c_int)
12881287
}
@@ -1567,8 +1566,8 @@ pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> {
15671566
// FIXME: fileflags // #2004
15681567
pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
15691568
unsafe {
1570-
let f = do os::as_c_charp(path.to_str()) |pathbuf| {
1571-
do os::as_c_charp("w") |modebuf| {
1569+
let f = do path.to_str().as_c_str |pathbuf| {
1570+
do "w".as_c_str |modebuf| {
15721571
libc::fopen(pathbuf, modebuf)
15731572
}
15741573
};

trunk/src/libstd/os.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ pub fn getcwd() -> Path {
8787

8888
// FIXME: move these to str perhaps? #2620
8989

90-
pub fn as_c_charp<T>(s: &str, f: &fn(*c_char) -> T) -> T {
91-
str::as_c_str(s, |b| f(b as *c_char))
92-
}
93-
9490
pub fn fill_charp_buf(f: &fn(*mut c_char, size_t) -> bool)
9591
-> Option<~str> {
9692
let mut buf = vec::from_elem(TMPBUF_SZ, 0u8 as c_char);
@@ -335,10 +331,10 @@ pub fn unsetenv(n: &str) {
335331
}
336332

337333
pub fn fdopen(fd: c_int) -> *FILE {
338-
unsafe {
339-
return do as_c_charp("r") |modebuf| {
334+
do "r".as_c_str |modebuf| {
335+
unsafe {
340336
libc::fdopen(fd, modebuf)
341-
};
337+
}
342338
}
343339
}
344340

@@ -471,7 +467,7 @@ pub fn self_exe_path() -> Option<Path> {
471467
let mut path_str = str::with_capacity(TMPBUF_SZ);
472468
let len = do str::as_c_str(path_str) |buf| {
473469
let buf = buf as *mut c_char;
474-
do as_c_charp("/proc/self/exe") |proc_self_buf| {
470+
do "/proc/self/exe".as_c_str |proc_self_buf| {
475471
readlink(proc_self_buf, buf, TMPBUF_SZ as size_t)
476472
}
477473
};
@@ -654,9 +650,9 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool {
654650

655651
#[cfg(unix)]
656652
fn mkdir(p: &Path, mode: c_int) -> bool {
657-
unsafe {
658-
do as_c_charp(p.to_str()) |c| {
659-
libc::mkdir(c, mode as libc::mode_t) == (0 as c_int)
653+
do p.to_str().as_c_str |buf| {
654+
unsafe {
655+
libc::mkdir(buf, mode as libc::mode_t) == (0 as c_int)
660656
}
661657
}
662658
}
@@ -830,10 +826,10 @@ pub fn remove_dir(p: &Path) -> bool {
830826

831827
#[cfg(unix)]
832828
fn rmdir(p: &Path) -> bool {
833-
unsafe {
834-
return do as_c_charp(p.to_str()) |buf| {
829+
do p.to_str().as_c_str |buf| {
830+
unsafe {
835831
libc::rmdir(buf) == (0 as c_int)
836-
};
832+
}
837833
}
838834
}
839835
}
@@ -855,10 +851,10 @@ pub fn change_dir(p: &Path) -> bool {
855851

856852
#[cfg(unix)]
857853
fn chdir(p: &Path) -> bool {
858-
unsafe {
859-
return do as_c_charp(p.to_str()) |buf| {
854+
do p.to_str().as_c_str |buf| {
855+
unsafe {
860856
libc::chdir(buf) == (0 as c_int)
861-
};
857+
}
862858
}
863859
}
864860
}
@@ -883,8 +879,8 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
883879
#[cfg(unix)]
884880
fn do_copy_file(from: &Path, to: &Path) -> bool {
885881
unsafe {
886-
let istream = do as_c_charp(from.to_str()) |fromp| {
887-
do as_c_charp("rb") |modebuf| {
882+
let istream = do from.to_str().as_c_str |fromp| {
883+
do "rb".as_c_str |modebuf| {
888884
libc::fopen(fromp, modebuf)
889885
}
890886
};
@@ -895,8 +891,8 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
895891
let from_mode = from.get_mode().expect("copy_file: couldn't get permissions \
896892
for source file");
897893

898-
let ostream = do as_c_charp(to.to_str()) |top| {
899-
do as_c_charp("w+b") |modebuf| {
894+
let ostream = do to.to_str().as_c_str |top| {
895+
do "w+b".as_c_str |modebuf| {
900896
libc::fopen(top, modebuf)
901897
}
902898
};
@@ -955,9 +951,9 @@ pub fn remove_file(p: &Path) -> bool {
955951
#[cfg(unix)]
956952
fn unlink(p: &Path) -> bool {
957953
unsafe {
958-
return do as_c_charp(p.to_str()) |buf| {
954+
do p.to_str().as_c_str |buf| {
959955
libc::unlink(buf) == (0 as c_int)
960-
};
956+
}
961957
}
962958
}
963959
}
@@ -1703,7 +1699,7 @@ mod tests {
17031699
use libc;
17041700
use option::Some;
17051701
use option;
1706-
use os::{as_c_charp, env, getcwd, getenv, make_absolute, real_args};
1702+
use os::{env, getcwd, getenv, make_absolute, real_args};
17071703
use os::{remove_file, setenv, unsetenv};
17081704
use os;
17091705
use path::Path;
@@ -1941,8 +1937,8 @@ mod tests {
19411937
let out = tempdir.push("out.txt");
19421938

19431939
/* Write the temp input file */
1944-
let ostream = do as_c_charp(in.to_str()) |fromp| {
1945-
do as_c_charp("w+b") |modebuf| {
1940+
let ostream = do in.to_str().as_c_str |fromp| {
1941+
do "w+b".as_c_str |modebuf| {
19461942
libc::fopen(fromp, modebuf)
19471943
}
19481944
};
@@ -2020,16 +2016,16 @@ mod tests {
20202016
}
20212017
}
20222018
2023-
let p = tmpdir().push("mmap_file.tmp");
2019+
let path = tmpdir().push("mmap_file.tmp");
20242020
let size = page_size() * 2;
2025-
remove_file(&p);
2021+
remove_file(&path);
20262022
20272023
let fd = unsafe {
2028-
let fd = do as_c_charp(p.to_str()) |path| {
2024+
let fd = do path.to_str().as_c_str |path| {
20292025
open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)
20302026
};
20312027
lseek_(fd, size);
2032-
do as_c_charp("x") |x| {
2028+
do "x".as_c_str |x| {
20332029
assert!(write(fd, x as *c_void, 1) == 1);
20342030
}
20352031
fd

0 commit comments

Comments
 (0)