diff options
author | Liav A <liavalb@gmail.com> | 2023-02-05 12:27:38 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-10 09:14:20 +0000 |
commit | ab27fce86f18341d463bc921a2071aefc0071a93 (patch) | |
tree | 31e521505d8e1964d4c4f3ef32ccefa10f6e5427 /AK/Error.cpp | |
parent | df72c9327b1c33e3113c7949ec05b8febecf29c9 (diff) | |
download | serenity-ab27fce86f18341d463bc921a2071aefc0071a93.zip |
AK: Add a new method to propagate errno while printing errors in Kernel
This new method is meant to be used in both userspace and kernel code.
The idea is to allow printing of a verbose message and then returning an
errno code which is the proper mechanism for kernel code because we
should almost always assume that such error will be propagated back to
userspace in some way, so the userspace code could reasonably decode it.
For userspace code however, this new method is meant to be a simple
wrapper for Error::from_string_view, because for most invocations, it's
much more useful to have a verbose & literal error than a errno code, so
we simply ignore that errno code completely in such context.
Diffstat (limited to 'AK/Error.cpp')
-rw-r--r-- | AK/Error.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/AK/Error.cpp b/AK/Error.cpp new file mode 100644 index 0000000000..df2e9a1986 --- /dev/null +++ b/AK/Error.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/Error.h> + +#ifdef KERNEL +# include <AK/Format.h> +#endif + +namespace AK { + +Error Error::from_string_view_or_print_error_and_return_errno(StringView string_literal, [[maybe_unused]] int code) +{ +#ifdef KERNEL + dmesgln("{}", string_literal); + return Error::from_errno(code); +#else + return Error::from_string_view(string_literal); +#endif +} + +} |