diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-23 02:41:00 -0500 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-23 02:41:00 -0500 |
| commit | 35a6a5c870164947ce4e865b30e8b93f320d0ab5 (patch) | |
| tree | 6dc372290330fdba430b9821c327de9aba5d9de7 /lib | |
| parent | c0788e4d6ae801f13f242b252ea9d0084c30c04a (diff) | |
feat: libsteps: error handling and parsing functions/operators.
feat: mimick nekernel filesystem tree in repository as well.
feat: update modules as well.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'lib')
| m--------- | lib/libocl | 0 | ||||
| -rw-r--r-- | lib/libsteps/dev/lib/steps.hpp | 23 |
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/libocl b/lib/libocl -Subproject 8470a48ef4c6ea4b16e9a764aaedc7158f9c37e +Subproject 9a70f32ddaec0eef99efbf7ff5597c2adf08f45 diff --git a/lib/libsteps/dev/lib/steps.hpp b/lib/libsteps/dev/lib/steps.hpp index d160506..ce6be51 100644 --- a/lib/libsteps/dev/lib/steps.hpp +++ b/lib/libsteps/dev/lib/steps.hpp @@ -6,8 +6,9 @@ Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. #pragma once -#include <libsteps/dev/lib/defines.hpp> #include <cstring> +#include <fstream> +#include <libsteps/dev/lib/defines.hpp> #define kStepsExtension ".stp" #define kStepsStrLen (256U) @@ -16,8 +17,8 @@ Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. #define kStepsMagicLen (4U) #define kStepsVersion (0x0100) -namespace steps { -struct record final { +namespace ocl::steps { +struct __attribute__((packed)) record final { ocl::char_type magic[kStepsMagicLen] = {kStepsMagic[0], kStepsMagic[1], kStepsMagic[2], kStepsMagic[3]}; ocl::char_type name[kStepsStrLen] = ""; @@ -28,7 +29,21 @@ struct record final { int32_t check_page = 0, eula_page = 0; }; +inline bool is_valid(record& r) noexcept { + return r.pages > 1 && r.version > 0 && strcmp(r.magic, kStepsMagic) == 0; +} + namespace operators { +inline std::ifstream &operator>>(std::ifstream &f, record &r) { + f.read((char *)&r, sizeof(r)); + return f; +} + +inline std::ofstream &operator<<(std::ofstream &f, record &r) { + f.write((char *)&r, sizeof(r)); + return f; +} + /// =========================================================== /// /// @brief Equal operator for steps records. /// =========================================================== /// @@ -43,4 +58,4 @@ inline bool operator!=(const record &r, const record &l) { return (std::strncmp(r.magic, l.magic, kStepsMagicLen) > 0); } } // namespace operators -} // namespace steps +} // namespace ocl::steps |
