mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:07:43 +00:00
AK+Kernel: Add the FixedStringBuffer class and StdLib functions for it
This class encapsulates a fixed Array with compile-time size definition for storing ASCII characters. There are also new Kernel StdLib functions to copy user data into such objects so this class will be useful later on.
This commit is contained in:
parent
3b09560251
commit
0d30f558f4
2 changed files with 118 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,6 +9,7 @@
|
|||
|
||||
#include <AK/Checked.h>
|
||||
#include <AK/Error.h>
|
||||
#include <AK/FixedStringBuffer.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Time.h>
|
||||
#include <AK/Userspace.h>
|
||||
|
@ -16,6 +18,25 @@
|
|||
#include <stddef.h>
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<char const*>, size_t);
|
||||
|
||||
template<size_t Size>
|
||||
ErrorOr<void> try_copy_string_from_user_into_fixed_string_buffer(Userspace<char const*> user_str, FixedStringBuffer<Size>& buffer, size_t user_str_size)
|
||||
{
|
||||
if (user_str_size > Size)
|
||||
return E2BIG;
|
||||
TRY(buffer.copy_characters_from_user(user_str, user_str_size));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<size_t Size>
|
||||
ErrorOr<void> try_copy_name_from_user_into_fixed_string_buffer(Userspace<char const*> user_str, FixedStringBuffer<Size>& buffer, size_t user_str_size)
|
||||
{
|
||||
if (user_str_size > Size)
|
||||
return ENAMETOOLONG;
|
||||
TRY(buffer.copy_characters_from_user(user_str, user_str_size));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<Duration> copy_time_from_user(timespec const*);
|
||||
ErrorOr<Duration> copy_time_from_user(timeval const*);
|
||||
template<typename T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue