mruby-bin-mirb: fix Windows/MSVC compilation warnings

- Define strdup as _strdup on MSVC to avoid deprecation warning
- Add strndup implementation for Windows (not available in MSVC)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-12-26 17:21:33 +09:00
parent 6f32125178
commit d51a3504e8
2 changed files with 22 additions and 0 deletions
@@ -19,6 +19,23 @@
#include <stdlib.h>
#include <string.h>
/* Windows compatibility */
#ifdef _MSC_VER
#define strdup _strdup
static char*
strndup(const char *s, size_t n)
{
size_t len = strlen(s);
if (len > n) len = n;
char *p = (char*)malloc(len + 1);
if (p) {
memcpy(p, s, len);
p[len] = '\0';
}
return p;
}
#endif
#ifdef MRB_USE_READLINE
#ifndef MRB_USE_LINENOISE
#include MRB_READLINE_HEADER
@@ -9,6 +9,11 @@
#include <stdlib.h>
#include <string.h>
/* Windows compatibility */
#ifdef _MSC_VER
#define strdup _strdup
#endif
/*
* Initialize history
*/