strdup for Windows

This commit is contained in:
DanielSvoboda 2024-07-07 00:36:54 -03:00 committed by GitHub
parent 379ec554a8
commit c6c220c323
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,8 @@
#include "core/libraries/kernel/file_system.h"
#include "core/libraries/libs.h"
#include "libkernel.h"
#include <cstdlib>
#include <cstring>
namespace Libraries::Kernel {
@ -452,4 +454,16 @@ void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
posix_open); // _open shoudld be equal to open function
}
#ifdef _WIN32
// Implementation of strdup for Windows, as it is not standard
char* strdup(const char* str) {
size_t len = strlen(str) + 1; // +1 for the final '\0'
char* dup = (char*)malloc(len);
if (dup) {
strcpy_s(dup, len, str); // Using strcpy_s for safety
}
return dup;
}
#endif
} // namespace Libraries::Kernel