File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
branches/try/src/libstd/sys/unix Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
3
3
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4
- refs/heads/try: 7723550fdd7fe29bee9dcbd45bdef4f209a7e1f1
4
+ refs/heads/try: 6065678e627643cc3275c677408d11f48802595e
5
5
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
6
6
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
7
7
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ use sys::c;
30
30
use sys:: fd;
31
31
use vec;
32
32
33
- const GETCWD_BUF_BYTES : usize = 2048 ;
34
33
const TMPBUF_SZ : usize = 128 ;
35
34
36
35
/// Returns the platform-specific value of errno
@@ -94,11 +93,9 @@ pub fn error_string(errno: i32) -> String {
94
93
}
95
94
96
95
pub fn getcwd ( ) -> io:: Result < PathBuf > {
97
- let mut buf = Vec :: new ( ) ;
98
- let mut n = GETCWD_BUF_BYTES ;
96
+ let mut buf = Vec :: with_capacity ( 512 ) ;
99
97
loop {
100
98
unsafe {
101
- buf. reserve ( n) ;
102
99
let ptr = buf. as_mut_ptr ( ) as * mut libc:: c_char ;
103
100
if !libc:: getcwd ( ptr, buf. capacity ( ) as libc:: size_t ) . is_null ( ) {
104
101
let len = CStr :: from_ptr ( buf. as_ptr ( ) as * const libc:: c_char ) . to_bytes ( ) . len ( ) ;
@@ -111,7 +108,12 @@ pub fn getcwd() -> io::Result<PathBuf> {
111
108
return Err ( error) ;
112
109
}
113
110
}
114
- n *= 2 ;
111
+
112
+ // Trigger the internal buffer resizing logic of `Vec` by requiring
113
+ // more space than the current capacity.
114
+ let cap = buf. capacity ( ) ;
115
+ buf. set_len ( cap) ;
116
+ buf. reserve ( 1 ) ;
115
117
}
116
118
}
117
119
}
You can’t perform that action at this time.
0 commit comments