summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/InodeFile.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-20 23:11:17 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-20 23:20:02 +0100
commit19d3f8cab77a95b284e30f142521c6b483221324 (patch)
tree8df3f585e91113215b52d10a9a0032c9998dc1b5 /Kernel/FileSystem/InodeFile.cpp
parente279b45aed5509efc537fc8c831f40733d7b1028 (diff)
downloadserenity-19d3f8cab77a95b284e30f142521c6b483221324.zip
Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode. This means that kernel functions that return those types can finally do "return EINVAL;" and it will just work. There's a handful of functions that still deal with signed integers that should be converted to return KResults.
Diffstat (limited to 'Kernel/FileSystem/InodeFile.cpp')
-rw-r--r--Kernel/FileSystem/InodeFile.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp
index 58a3f2459e..3cade1cf5f 100644
--- a/Kernel/FileSystem/InodeFile.cpp
+++ b/Kernel/FileSystem/InodeFile.cpp
@@ -52,7 +52,7 @@ KResultOr<size_t> InodeFile::read(FileDescription& description, size_t offset, U
evaluate_block_conditions();
}
if (nread < 0)
- return KResult(nread);
+ return KResult((ErrnoCode)-nread);
return nread;
}
@@ -65,7 +65,7 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, size_t offset,
evaluate_block_conditions();
}
if (nwritten < 0)
- return KResult(nwritten);
+ return KResult((ErrnoCode)-nwritten);
return nwritten;
}
@@ -78,7 +78,7 @@ KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& descriptio
else
vmobject = PrivateInodeVMObject::create_with_inode(inode());
if (!vmobject)
- return KResult(-ENOMEM);
+ return ENOMEM;
return process.allocate_region_with_vmobject(preferred_vaddr, size, *vmobject, offset, description.absolute_path(), prot, shared);
}
@@ -95,8 +95,8 @@ KResult InodeFile::truncate(u64 size)
if (truncate_result.is_error())
return truncate_result;
int mtime_result = m_inode->set_mtime(kgettimeofday().tv_sec);
- if (mtime_result != 0)
- return KResult(mtime_result);
+ if (mtime_result < 0)
+ return KResult((ErrnoCode)-mtime_result);
return KSuccess;
}