@@ -87,10 +87,6 @@ pub fn getcwd() -> Path {
87
87
88
88
// FIXME: move these to str perhaps? #2620
89
89
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
-
94
90
pub fn fill_charp_buf ( f : & fn ( * mut c_char , size_t ) -> bool )
95
91
-> Option < ~str > {
96
92
let mut buf = vec:: from_elem ( TMPBUF_SZ , 0u8 as c_char ) ;
@@ -335,10 +331,10 @@ pub fn unsetenv(n: &str) {
335
331
}
336
332
337
333
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 {
340
336
libc:: fdopen ( fd, modebuf)
341
- } ;
337
+ }
342
338
}
343
339
}
344
340
@@ -471,7 +467,7 @@ pub fn self_exe_path() -> Option<Path> {
471
467
let mut path_str = str:: with_capacity ( TMPBUF_SZ ) ;
472
468
let len = do str:: as_c_str ( path_str) |buf| {
473
469
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| {
475
471
readlink ( proc_self_buf, buf, TMPBUF_SZ as size_t )
476
472
}
477
473
} ;
@@ -654,9 +650,9 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool {
654
650
655
651
#[ cfg( unix) ]
656
652
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 )
660
656
}
661
657
}
662
658
}
@@ -830,10 +826,10 @@ pub fn remove_dir(p: &Path) -> bool {
830
826
831
827
#[ cfg( unix) ]
832
828
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 {
835
831
libc:: rmdir ( buf) == ( 0 as c_int )
836
- } ;
832
+ }
837
833
}
838
834
}
839
835
}
@@ -855,10 +851,10 @@ pub fn change_dir(p: &Path) -> bool {
855
851
856
852
#[ cfg( unix) ]
857
853
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 {
860
856
libc:: chdir ( buf) == ( 0 as c_int )
861
- } ;
857
+ }
862
858
}
863
859
}
864
860
}
@@ -883,8 +879,8 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
883
879
#[ cfg( unix) ]
884
880
fn do_copy_file( from : & Path , to : & Path ) -> bool {
885
881
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| {
888
884
libc:: fopen ( fromp, modebuf)
889
885
}
890
886
} ;
@@ -895,8 +891,8 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
895
891
let from_mode = from. get_mode ( ) . expect ( "copy_file: couldn't get permissions \
896
892
for source file") ;
897
893
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| {
900
896
libc::fopen(top, modebuf)
901
897
}
902
898
};
@@ -955,9 +951,9 @@ pub fn remove_file(p: &Path) -> bool {
955
951
#[cfg(unix)]
956
952
fn unlink(p: &Path) -> bool {
957
953
unsafe {
958
- return do as_c_charp ( p. to_str ( ) ) |buf| {
954
+ do p.to_str().as_c_str |buf| {
959
955
libc::unlink(buf) == (0 as c_int)
960
- } ;
956
+ }
961
957
}
962
958
}
963
959
}
@@ -1703,7 +1699,7 @@ mod tests {
1703
1699
use libc;
1704
1700
use option::Some;
1705
1701
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};
1707
1703
use os::{remove_file, setenv, unsetenv};
1708
1704
use os;
1709
1705
use path::Path;
@@ -1941,8 +1937,8 @@ mod tests {
1941
1937
let out = tempdir. push( "out.txt" ) ;
1942
1938
1943
1939
/* 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| {
1946
1942
libc:: fopen( fromp, modebuf)
1947
1943
}
1948
1944
} ;
@@ -2020,16 +2016,16 @@ mod tests {
2020
2016
}
2021
2017
}
2022
2018
2023
- let p = tmpdir().push(" mmap_file. tmp");
2019
+ let path = tmpdir().push(" mmap_file. tmp");
2024
2020
let size = page_size() * 2;
2025
- remove_file(&p );
2021
+ remove_file(&path );
2026
2022
2027
2023
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| {
2029
2025
open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)
2030
2026
};
2031
2027
lseek_(fd, size);
2032
- do as_c_charp( " x") |x| {
2028
+ do " x" . as_c_str |x| {
2033
2029
assert!( write( fd, x as * c_void, 1 ) == 1 ) ;
2034
2030
}
2035
2031
fd
0 commit comments