Skip to content

Commit 1583fa7

Browse files
committed
---
yaml --- r: 228246 b: refs/heads/try c: b83ec47 h: refs/heads/master v: v3
1 parent 40fef06 commit 1583fa7

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: d99d4fbf70acce44c14448a572f7dce4cb883ce8
4+
refs/heads/try: b83ec47808c219cb8e85eeebb370be6466b2d690
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libstd/sys/unix/mod.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
7575
}
7676
}
7777

78-
// Some system functions expect the user to pass a appropiately-sized buffer
79-
// without specifying its size. They will only report back whether the buffer
80-
// was large enough or not.
81-
//
82-
// The callback is yielded an uninitialized vector which can be passed to a
83-
// syscall. The closure is expected to return `Err(v)` with the passed vector
84-
// if the space was insufficient and `Ok(r)` if the syscall did not fail due to
85-
// insufficient space.
86-
fn fill_bytes_buf<F, T>(mut f: F) -> io::Result<T>
87-
where F: FnMut(Vec<u8>) -> Result<io::Result<T>,Vec<u8>>,
88-
{
89-
let mut buf = Vec::new();
90-
let mut n = os::BUF_BYTES;
91-
loop {
92-
buf.reserve(n);
93-
match f(buf) {
94-
Err(b) => { buf = b; n *= 2; }
95-
Ok(r) => return r,
96-
}
97-
}
98-
}
99-
10078
pub fn cvt<T: One + PartialEq + Neg<Output=T>>(t: T) -> io::Result<T> {
10179
let one: T = T::one();
10280
if t == -one {

branches/try/src/libstd/sys/unix/os.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use sys::c;
3030
use sys::fd;
3131
use vec;
3232

33-
pub const BUF_BYTES: usize = 2048;
33+
const GETCWD_BUF_BYTES: usize = 2048;
3434
const TMPBUF_SZ: usize = 128;
3535

3636
/// Returns the platform-specific value of errno
@@ -94,22 +94,26 @@ pub fn error_string(errno: i32) -> String {
9494
}
9595

9696
pub fn getcwd() -> io::Result<PathBuf> {
97-
super::fill_bytes_buf(|mut buf| {
97+
let mut buf = Vec::new();
98+
let mut n = GETCWD_BUF_BYTES;
99+
loop {
98100
unsafe {
101+
buf.reserve(n);
99102
let ptr = buf.as_mut_ptr() as *mut libc::c_char;
100-
Ok(if !libc::getcwd(ptr, buf.capacity() as libc::size_t).is_null() {
103+
if !libc::getcwd(ptr, buf.capacity() as libc::size_t).is_null() {
101104
let len = CStr::from_ptr(buf.as_ptr() as *const libc::c_char).to_bytes().len();
102105
buf.set_len(len);
103-
Ok(PathBuf::from(OsString::from_bytes(buf).unwrap()))
106+
buf.shrink_to_fit();
107+
return Ok(PathBuf::from(OsString::from_vec(buf)));
104108
} else {
105109
let error = io::Error::last_os_error();
106-
if error.raw_os_error().unwrap() == libc::ERANGE {
107-
return Err(buf);
110+
if error.raw_os_error() != Some(libc::ERANGE) {
111+
return Err(error);
108112
}
109-
Err(error)
110-
})
113+
}
114+
n *= 2;
111115
}
112-
})
116+
}
113117
}
114118

115119
pub fn chdir(p: &path::Path) -> io::Result<()> {

0 commit comments

Comments
 (0)