mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
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.
This commit is contained in:
parent
df72c9327b
commit
ab27fce86f
4 changed files with 34 additions and 0 deletions
25
AK/Error.cpp
Normal file
25
AK/Error.cpp
Normal file
|
@ -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
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue