mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:57:45 +00:00
AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature: - int StringType::to_int(bool& ok) const And replace it with sensible new signature: - Optional<int> StringType::to_int() const
This commit is contained in:
parent
15f4043a7a
commit
fdfda6dec2
55 changed files with 354 additions and 455 deletions
|
@ -177,10 +177,9 @@ RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
|
|||
if (name == "." || name == "..")
|
||||
return fs().get_inode(identifier());
|
||||
|
||||
bool ok;
|
||||
unsigned pty_index = name.to_uint(ok);
|
||||
if (ok && ptys->contains(pty_index)) {
|
||||
return fs().get_inode({ fsid(), pty_index_to_inode_index(pty_index) });
|
||||
auto pty_index = name.to_uint();
|
||||
if (pty_index.has_value() && ptys->contains(pty_index.value())) {
|
||||
return fs().get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -1356,17 +1356,16 @@ RefPtr<Inode> ProcFSInode::lookup(StringView name)
|
|||
}
|
||||
}
|
||||
}
|
||||
bool ok;
|
||||
unsigned name_as_number = name.to_uint(ok);
|
||||
if (ok) {
|
||||
bool process_exists = false;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
process_exists = Process::from_pid(name_as_number);
|
||||
}
|
||||
if (process_exists)
|
||||
return fs().get_inode(to_identifier(fsid(), PDI_Root, name_as_number, FI_PID));
|
||||
auto name_as_number = name.to_uint();
|
||||
if (!name_as_number.has_value())
|
||||
return {};
|
||||
bool process_exists = false;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
process_exists = Process::from_pid(name_as_number.value());
|
||||
}
|
||||
if (process_exists)
|
||||
return fs().get_inode(to_identifier(fsid(), PDI_Root, name_as_number.value(), FI_PID));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -1413,18 +1412,17 @@ RefPtr<Inode> ProcFSInode::lookup(StringView name)
|
|||
}
|
||||
|
||||
if (proc_file_type == FI_PID_fd) {
|
||||
bool ok;
|
||||
unsigned name_as_number = name.to_uint(ok);
|
||||
if (ok) {
|
||||
bool fd_exists = false;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (auto* process = Process::from_pid(to_pid(identifier())))
|
||||
fd_exists = process->file_description(name_as_number);
|
||||
}
|
||||
if (fd_exists)
|
||||
return fs().get_inode(to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number));
|
||||
auto name_as_number = name.to_uint();
|
||||
if (!name_as_number.has_value())
|
||||
return {};
|
||||
bool fd_exists = false;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (auto* process = Process::from_pid(to_pid(identifier())))
|
||||
fd_exists = process->file_description(name_as_number.value());
|
||||
}
|
||||
if (fd_exists)
|
||||
return fs().get_inode(to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number.value()));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -251,10 +251,9 @@ void init_stage2()
|
|||
root = root.substring(strlen("/dev/hda"), root.length() - strlen("/dev/hda"));
|
||||
|
||||
if (root.length()) {
|
||||
bool ok;
|
||||
unsigned partition_number = root.to_uint(ok);
|
||||
auto partition_number = root.to_uint();
|
||||
|
||||
if (!ok) {
|
||||
if (!partition_number.has_value()) {
|
||||
klog() << "init_stage2: couldn't parse partition number from root kernel parameter";
|
||||
hang();
|
||||
}
|
||||
|
@ -273,9 +272,9 @@ void init_stage2()
|
|||
klog() << "init_stage2: couldn't read GPT from disk";
|
||||
hang();
|
||||
}
|
||||
auto partition = gpt.partition(partition_number);
|
||||
auto partition = gpt.partition(partition_number.value());
|
||||
if (!partition) {
|
||||
klog() << "init_stage2: couldn't get partition " << partition_number;
|
||||
klog() << "init_stage2: couldn't get partition " << partition_number.value();
|
||||
hang();
|
||||
}
|
||||
root_dev = *partition;
|
||||
|
@ -287,20 +286,20 @@ void init_stage2()
|
|||
klog() << "init_stage2: couldn't read EBR from disk";
|
||||
hang();
|
||||
}
|
||||
auto partition = ebr.partition(partition_number);
|
||||
auto partition = ebr.partition(partition_number.value());
|
||||
if (!partition) {
|
||||
klog() << "init_stage2: couldn't get partition " << partition_number;
|
||||
klog() << "init_stage2: couldn't get partition " << partition_number.value();
|
||||
hang();
|
||||
}
|
||||
root_dev = *partition;
|
||||
} else {
|
||||
if (partition_number < 1 || partition_number > 4) {
|
||||
klog() << "init_stage2: invalid partition number " << partition_number << "; expected 1 to 4";
|
||||
if (partition_number.value() < 1 || partition_number.value() > 4) {
|
||||
klog() << "init_stage2: invalid partition number " << partition_number.value() << "; expected 1 to 4";
|
||||
hang();
|
||||
}
|
||||
auto partition = mbr.partition(partition_number);
|
||||
auto partition = mbr.partition(partition_number.value());
|
||||
if (!partition) {
|
||||
klog() << "init_stage2: couldn't get partition " << partition_number;
|
||||
klog() << "init_stage2: couldn't get partition " << partition_number.value();
|
||||
hang();
|
||||
}
|
||||
root_dev = *partition;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue