| 157 | } |
| 158 | |
| 159 | auto FileDescriptorTable::SetupStandardFiles(vfs::File* stdin_file, |
| 160 | vfs::File* stdout_file, |
| 161 | vfs::File* stderr_file) |
| 162 | -> Expected<void> { |
| 163 | LockGuard guard(lock_); |
| 164 | |
| 165 | // 仅对之前未占用的槽位增加计数 |
| 166 | if (table_[kStdinFd] == nullptr && stdin_file != nullptr) { |
| 167 | ++open_count_; |
| 168 | } |
| 169 | if (table_[kStdoutFd] == nullptr && stdout_file != nullptr) { |
| 170 | ++open_count_; |
| 171 | } |
| 172 | if (table_[kStderrFd] == nullptr && stderr_file != nullptr) { |
| 173 | ++open_count_; |
| 174 | } |
| 175 | |
| 176 | table_[kStdinFd] = stdin_file; |
| 177 | table_[kStdoutFd] = stdout_file; |
| 178 | table_[kStderrFd] = stderr_file; |
| 179 | |
| 180 | return {}; |
| 181 | } |
| 182 | |
| 183 | auto FileDescriptorTable::GetOpenCount() const -> int { return open_count_; } |
| 184 | |