Skip to content

Commit 7ab37ee

Browse files
committed
Everywhere: Remove string.h include from AK/Traits.h and resolve fallout
A lot of places were relying on AK/Traits.h to give it strnlen, memcmp, memcpy and other related declarations. In the quest to remove inclusion of LibC headers from Kernel files, deal with all the fallout of this included-everywhere header including less things.
1 parent 0420736 commit 7ab37ee

File tree

14 files changed

+35
-18
lines changed

14 files changed

+35
-18
lines changed

AK/FuzzyMatch.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <AK/CharacterTypes.h>
88
#include <AK/FuzzyMatch.h>
9+
#include <string.h>
910

1011
namespace AK {
1112

AK/JsonObjectSerializer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class JsonObjectSerializer {
8484
TRY(begin_item(key));
8585
if constexpr (IsLegacyBuilder<Builder>) {
8686
TRY(m_builder.try_append('"'));
87-
TRY(m_builder.try_append_escaped_for_json({ value, strlen(value) }));
87+
TRY(m_builder.try_append_escaped_for_json({ value, __builtin_strlen(value) }));
8888
TRY(m_builder.try_append('"'));
8989
} else {
9090
TRY(m_builder.append('"'));
91-
TRY(m_builder.append_escaped_for_json({ value, strlen(value) }));
91+
TRY(m_builder.append_escaped_for_json({ value, __builtin_strlen(value) }));
9292
TRY(m_builder.append('"'));
9393
}
9494
return {};

AK/PrintfImplementation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#include <AK/StdLibExtras.h>
1111
#include <AK/Types.h>
1212
#include <stdarg.h>
13-
#include <wchar.h>
1413

1514
#ifndef KERNEL
1615
# include <math.h>
16+
# include <wchar.h>
1717
#endif
1818

1919
#ifdef AK_OS_SERENITY

AK/StringUtils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
#include <AK/StringView.h>
1515
#include <AK/Vector.h>
1616

17-
#ifndef KERNEL
17+
#ifdef KERNEL
18+
# include <Kernel/StdLib.h>
19+
#else
1820
# include <AK/DeprecatedString.h>
1921
# include <AK/FloatingPointStringConversions.h>
22+
# include <string.h>
2023
#endif
2124

2225
namespace AK {

AK/Time.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
#include <AK/Platform.h>
1212
#include <AK/Types.h>
1313

14-
// Kernel and Userspace pull in the definitions from different places.
15-
// Avoid trying to figure out which one.
16-
struct timeval;
17-
struct timespec;
18-
19-
#if defined(AK_OS_WINDOWS)
14+
#if defined(AK_OS_SERENITY) && defined(KERNEL)
15+
# include <Kernel/API/POSIX/sys/time.h>
16+
# include <Kernel/API/POSIX/time.h>
17+
#else
18+
# include <sys/time.h>
2019
# include <time.h>
2120
#endif
2221

AK/Traits.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <AK/Forward.h>
1212
#include <AK/HashFunctions.h>
1313
#include <AK/StringHash.h>
14-
#include <string.h>
1514

1615
namespace AK {
1716

Kernel/Bus/USB/USBConfiguration.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <Kernel/Bus/USB/USBConfiguration.h>
1010
#include <Kernel/Bus/USB/USBInterface.h>
1111
#include <Kernel/Bus/USB/USBRequest.h>
12+
#include <Kernel/StdLib.h>
1213

1314
namespace Kernel::USB {
1415

Kernel/Bus/USB/USBTransfer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <Kernel/Bus/USB/USBTransfer.h>
88
#include <Kernel/Memory/MemoryManager.h>
9+
#include <Kernel/StdLib.h>
910

1011
namespace Kernel::USB {
1112

Kernel/FileSystem/Ext2FS/Inode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,11 @@ ErrorOr<void> Ext2FSInode::update_timestamps(Optional<Time> atime, Optional<Time
992992
MutexLocker locker(m_inode_lock);
993993
if (fs().is_readonly())
994994
return EROFS;
995-
if (atime.value_or({}).to_timespec().tv_sec > INT32_MAX)
995+
if (atime.value_or({}).to_timespec().tv_sec > NumericLimits<i32>::max())
996996
return EINVAL;
997-
if (ctime.value_or({}).to_timespec().tv_sec > INT32_MAX)
997+
if (ctime.value_or({}).to_timespec().tv_sec > NumericLimits<i32>::max())
998998
return EINVAL;
999-
if (mtime.value_or({}).to_timespec().tv_sec > INT32_MAX)
999+
if (mtime.value_or({}).to_timespec().tv_sec > NumericLimits<i32>::max())
10001000
return EINVAL;
10011001
if (atime.has_value())
10021002
m_raw_inode.i_atime = atime.value().to_timespec().tv_sec;

Kernel/KBuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <AK/Assertions.h>
1919
#include <AK/StringView.h>
2020
#include <Kernel/Memory/MemoryManager.h>
21+
#include <Kernel/StdLib.h> // For memcpy. FIXME: Make memcpy less expensive to access a declaration of in the Kernel.
2122

2223
namespace Kernel {
2324

0 commit comments

Comments
 (0)