Skip to content

Commit ae7d98b

Browse files
committed
Extract constant for minimum fd
1 parent 0933314 commit ae7d98b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/shims/fs.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ pub struct FileHandler {
2323
handles: BTreeMap<i32, FileHandle>,
2424
}
2525

26+
// fd numbers 0, 1, and 2 are reserved for stdin, stdout, and stderr
27+
const MIN_NORMAL_FILE_FD: i32 = 3;
28+
2629
impl FileHandler {
2730
fn insert_fd(&mut self, file_handle: FileHandle) -> i32 {
28-
self.insert_fd_with_min_fd(file_handle, 3)
31+
self.insert_fd_with_min_fd(file_handle, 0)
2932
}
3033

3134
fn insert_fd_with_min_fd(&mut self, file_handle: FileHandle, min_fd: i32) -> i32 {
32-
let min_fd = std::cmp::max(min_fd, 3);
35+
let min_fd = std::cmp::max(min_fd, MIN_NORMAL_FILE_FD);
3336

3437
// Find the lowest unused FD, starting from min_fd. If the first such unused FD is in
3538
// between used FDs, the find_map combinator will return it. If the first such unused FD
@@ -171,7 +174,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
171174
// because exec() isn't supported. The F_DUPFD and F_DUPFD_CLOEXEC commands only
172175
// differ in whether the FD_CLOEXEC flag is pre-set on the new file descriptor,
173176
// thus they can share the same implementation here.
174-
if fd <= 2 {
177+
if fd < MIN_NORMAL_FILE_FD {
175178
throw_unsup_format!("Duplicating file descriptors for stdin, stdout, or stderr is not supported")
176179
}
177180
let start_op = start_op.ok_or_else(|| {

0 commit comments

Comments
 (0)