diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index ee220a9aaa6..51e42db8821 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -8,6 +8,9 @@ #include #include +#ifdef KERNEL +# include +#endif namespace AK { @@ -205,6 +208,17 @@ inline OwnPtr adopt_own_if_nonnull(T* object) return {}; } +#ifdef KERNEL +template +inline Kernel::KResultOr> adopt_nonnull_own_or_enomem(T* object) +{ + auto result = adopt_own_if_nonnull(object); + if (!result) + return ENOMEM; + return result.release_nonnull(); +} +#endif + template requires(IsConstructible) inline OwnPtr try_make(Args&&... args) { @@ -232,3 +246,7 @@ struct Traits> : public GenericTraits> { using AK::adopt_own_if_nonnull; using AK::OwnPtr; using AK::try_make; + +#ifdef KERNEL +using AK::adopt_nonnull_own_or_enomem; +#endif