diff --git a/userspace/libraries/LibC/CMakeLists.txt b/userspace/libraries/LibC/CMakeLists.txt index 9cacaaf141..a6a5389e27 100644 --- a/userspace/libraries/LibC/CMakeLists.txt +++ b/userspace/libraries/LibC/CMakeLists.txt @@ -4,6 +4,7 @@ set(LIBC_SOURCES ctype.cpp dirent.cpp dlfcn.cpp + errno.cpp fcntl.cpp ftw.cpp grp.cpp diff --git a/userspace/libraries/LibC/errno.cpp b/userspace/libraries/LibC/errno.cpp new file mode 100644 index 0000000000..e60ef5c382 --- /dev/null +++ b/userspace/libraries/LibC/errno.cpp @@ -0,0 +1,8 @@ +#include + +static int s_errno = 0; + +int* __errno_location() +{ + return &s_errno; +} diff --git a/userspace/libraries/LibC/include/errno.h b/userspace/libraries/LibC/include/errno.h index 2dcc3e5789..d415145967 100644 --- a/userspace/libraries/LibC/include/errno.h +++ b/userspace/libraries/LibC/include/errno.h @@ -93,9 +93,9 @@ __BEGIN_DECLS #define EUNKNOWN 0xFF -#define errno __errno +#define errno (*__errno_location()) -extern int __errno; +int* __errno_location(void); __END_DECLS diff --git a/userspace/libraries/LibC/string.cpp b/userspace/libraries/LibC/string.cpp index 853735db48..fd17f356ea 100644 --- a/userspace/libraries/LibC/string.cpp +++ b/userspace/libraries/LibC/string.cpp @@ -8,8 +8,6 @@ #include #include -int errno = 0; - void* memccpy(void* __restrict s1, const void* __restrict s2, int c, size_t n) { unsigned char* dst = static_cast(s1);