fennec
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31
32#ifndef FENNEC_MEMORY_H
33#define FENNEC_MEMORY_H
34
36#include <fennec/memory/detail/_string.h>
37
38namespace fennec
39{
40
46template<typename TypeT>
47constexpr TypeT* addressof(TypeT& obj) {
48 return FENNEC_BUILTIN_ADDRESSOF(obj);
49}
50
57using ::memchr;
58using ::wmemchr;
59
67using ::memcmp;
68using ::wmemcmp;
69
78constexpr int memcmp_s(const void* lhs, size_t n0, const void* rhs, size_t n1) {
79 return memcmp(lhs, rhs, n0 < n1 ? n0 : n1);
80}
81
94using ::memcpy;
95using ::wmemcpy;
96
104constexpr void* memcpy_s(void* dst, size_t n0, const void* src, size_t n1) {
105 return memcpy(dst, src, n0 < n1 ? n0 : n1);
106}
107
114using ::memmove;
115using ::wmemmove;
116
124constexpr void* memmove_s(void* dst, size_t n0, const void* src, size_t n1) {
125 return memmove(dst, src, n0 < n1 ? n0 : n1);
126}
127
134using ::memset;
135using ::wmemset;
136
137}
138
139#endif // FENNEC_MEMORY_H
constexpr void * memcpy_s(void *dst, size_t n0, const void *src, size_t n1)
Safe version of memcpy.
Definition common.h:104
constexpr void * memmove_s(void *dst, size_t n0, const void *src, size_t n1)
Safe version of memmove.
Definition common.h:124
constexpr TypeT * addressof(TypeT &obj)
Returns the address of an object regardless of whether the & operators is implemented.
Definition common.h:47
constexpr int memcmp_s(const void *lhs, size_t n0, const void *rhs, size_t n1)
Safe version of memcmp.
Definition common.h:78
Type Traits