Skip to content

Commit 6d54cd4

Browse files
committed
std: Move a plattform-specific constant to sys::stdio
1 parent 8b2600d commit 6d54cd4

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

src/libstd/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ mod lazy;
289289
mod util;
290290
mod stdio;
291291

292-
const DEFAULT_BUF_SIZE: usize = 8 * 1024;
292+
const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
293293

294294
// A few methods below (read_to_string, read_line) will append data into a
295295
// `String` buffer, but we need to be pretty careful when doing this. The

src/libstd/io/stdio.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,7 @@ pub fn stdin() -> Stdin {
214214
_ => Maybe::Fake
215215
};
216216

217-
// The default buffer capacity is 64k, but apparently windows
218-
// doesn't like 64k reads on stdin. See #13304 for details, but the
219-
// idea is that on windows we use a slightly smaller buffer that's
220-
// been seen to be acceptable.
221-
Arc::new(Mutex::new(if cfg!(windows) {
222-
BufReader::with_capacity(8 * 1024, stdin)
223-
} else {
224-
BufReader::new(stdin)
225-
}))
217+
Arc::new(Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin)))
226218
}
227219
}
228220

src/libstd/sys/common/io.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use io::ErrorKind;
1212
use io::Read;
1313
use slice::from_raw_parts_mut;
1414

15+
pub const DEFAULT_BUF_SIZE: usize = 8 * 1024;
16+
1517
// Provides read_to_end functionality over an uninitialized buffer.
1618
// This function is unsafe because it calls the underlying
1719
// read function with a slice into uninitialized memory. The default

src/libstd/sys/unix/stdio.rs

+1
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ impl io::Write for Stderr {
6767
}
6868

6969
pub const EBADF_ERR: i32 = ::libc::EBADF as i32;
70+
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;

src/libstd/sys/windows/stdio.rs

+5
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,8 @@ fn invalid_encoding() -> io::Error {
207207
}
208208

209209
pub const EBADF_ERR: i32 = ::sys::c::ERROR_INVALID_HANDLE as i32;
210+
// The default buffer capacity is 64k, but apparently windows
211+
// doesn't like 64k reads on stdin. See #13304 for details, but the
212+
// idea is that on windows we use a slightly smaller buffer that's
213+
// been seen to be acceptable.
214+
pub const STDIN_BUF_SIZE: usize = 8 * 1024;

src/tools/tidy/src/pal.rs

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const EXCEPTION_PATHS: &'static [&'static str] = &[
6666
"src/libstd/lib.rs", // This could probably be done within the sys directory
6767
"src/libstd/rtdeps.rs", // Until rustbuild replaces make
6868
"src/libstd/path.rs",
69-
"src/libstd/io/stdio.rs",
7069
"src/libstd/num/f32.rs",
7170
"src/libstd/num/f64.rs",
7271
"src/libstd/sys/common/mod.rs",

0 commit comments

Comments
 (0)