Merge pull request #741 from alpinevm/feat/libc-strnlen-s

feat(libc): implement strnlen_s
This commit is contained in:
Dean
2026-10-06 12:14:04 +13:00
committed by GitHub
3 changed files with 7 additions and 9 deletions
-9
View File
@@ -38,15 +38,6 @@ int APS5_VABI libcUnknown_u2tMGOLaqnE() {
return 0;
}
// Live float->float import of Cyberpunk 2077 (unnamed); callers pass one
// float in xmm0 and consume the result, so return 0.0f instead of integer 0.
APS5_EXPORT("DQbtGaBKlaw", libcCyberUnknown17);
float APS5_VABI libcCyberUnknown17(float x) {
(void)x;
NotImplemented_nid_no_patch("DQbtGaBKlaw");
return 0.0f;
}
// Live Cyberpunk 2077 import used in an fopen/fseek/ftell-like file-size
// idiom as (handle, 0, 2); returning 0 reports success.
APS5_EXPORT("rWSuTWY2JN0", libcCyberUnknown18);
@@ -26,6 +26,10 @@ std::size_t APS5_VABI strnlen_nid_postfix(const char* text, std::size_t limit) {
return length;
}
std::size_t APS5_VABI strnlen_s_nid_postfix(const char* text, std::size_t limit) {
return text ? strnlen_nid_postfix(text, limit) : 0;
}
char* APS5_VABI strncat_nid_postfix(char* destination, const char* source, std::size_t limit) {
return std::strncat(destination, source, limit);
}
+3
View File
@@ -8,6 +8,7 @@ extern "C" {
char* APS5_VABI basename_nid_postfix(const char*);
int* APS5_VABI __error_nid_postfix();
std::size_t APS5_VABI strnlen_nid_postfix(const char*, std::size_t);
std::size_t APS5_VABI strnlen_s_nid_postfix(const char*, std::size_t);
char* APS5_VABI strncat_nid_postfix(char*, const char*, std::size_t);
char* APS5_VABI strpbrk_nid_postfix(const char*, const char*);
std::size_t APS5_VABI strcspn_nid_postfix(const char*, const char*);
@@ -88,6 +89,8 @@ int main() {
Require(strnlen_nid_postfix(bounded, 0) == 0);
Require(strnlen_nid_postfix(bounded, sizeof(bounded)) == 3);
Require(strnlen_nid_postfix("a", 8) == 1);
Require(strnlen_s_nid_postfix(nullptr, 8) == 0);
Require(strnlen_s_nid_postfix("abc", 8) == 3 && strnlen_s_nid_postfix("abcdef", 4) == 4);
char truncated[] = "abXX";
Require(strlcat_nid_postfix(truncated, "cd", 2) == 4);
Require(std::strcmp(truncated, "abXX") == 0);