Skip to content

Commit 1721364

Browse files
committed
mirb, mruby-io test: build with current mingw-w64 headers
Both define a static fallback for a POSIX function that Windows lacked, and mingw-w64 now declares both: mkdtemp() in <stdlib.h> since 14.0, and strndup() in <string.h> on its master branch, which MSYS2 and llvm-mingw ship. A static definition after a non-static declaration is an error with GCC and clang: mirb_completion.c:30:1: error: static declaration of 'strndup' follows non-static declaration mruby_io_test.c:43:1: error: static declaration of 'mkdtemp' follows non-static declaration mirb now always uses its own helper, renamed to mirb_strndup(), since no released mingw-w64 version can be tested for yet. The mruby-io test keeps its mkdtemp() for MSVC and for mingw-w64 before 14.0, the way it already does for mkstemp().
1 parent d474475 commit 1721364

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎mrbgems/mruby-bin-mirb/tools/mirb/mirb_completion.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#define strdup _strdup
2525
#endif
2626

27-
/* strndup is not available on Windows (MSVC and MinGW) */
28-
#ifdef _WIN32
27+
/* strndup is missing from MSVC and older MinGW, and newer MinGW declares it,
28+
so use a helper of our own everywhere */
2929
static char*
30-
strndup(const char *s, size_t n)
30+
mirb_strndup(const char *s, size_t n)
3131
{
3232
size_t len = strlen(s);
3333
if (len > n) len = n;
@@ -38,7 +38,6 @@ strndup(const char *s, size_t n)
3838
}
3939
return p;
4040
}
41-
#endif
4241

4342
/* ============================================================
4443
* Core Completion Engine
@@ -505,7 +504,7 @@ mirb_generate_completions(mirb_completion_ctx *ctx, const char *line, int cursor
505504
if (ctx->match_prefix) {
506505
free(ctx->match_prefix);
507506
}
508-
ctx->match_prefix = strndup(line + i, cursor_pos - i);
507+
ctx->match_prefix = mirb_strndup(line + i, cursor_pos - i);
509508
ctx->prefix_len = cursor_pos - i;
510509

511510
/* Detect completion type */

‎mrbgems/mruby-io/test/mruby_io_test.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ mkstemp(char *p)
3939
}
4040
#endif
4141

42+
/* mingw-w64 has mkdtemp() since 14.0 */
43+
#if !defined(MRB_MINGW64_VERSION) || MRB_MINGW64_VERSION < 14000
4244
static char*
4345
mkdtemp(char *temp)
4446
{
@@ -47,6 +49,7 @@ mkdtemp(char *temp)
4749
if (_mkdir(path) < 0) return NULL;
4850
return path;
4951
}
52+
#endif
5053

5154
#define umask(mode) _umask(mode)
5255
#define rmdir(path) _rmdir(path)

0 commit comments

Comments
 (0)