Skip to content

Commit b83bd19

Browse files
committed
use -std=gnu11 on linux platform
1 parent 0d455aa commit b83bd19

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

build.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pub fn build(b: *std.Build) void {
77
// Standard optimization options
88
const optimize = b.standardOptimizeOption(.{});
99

10+
// Determine C standard based on platform
11+
const c_std = if (target.result.os.tag == .linux) "-std=gnu11" else "-std=c11";
12+
1013
// Build options
1114
const build_shared = b.option(bool, "shared", "Build shared library") orelse false;
1215
const build_examples = b.option(bool, "examples", "Build example programs") orelse true;
@@ -65,7 +68,7 @@ pub fn build(b: *std.Build) void {
6568
.flags = &.{
6669
"-Wall",
6770
"-Wextra",
68-
"-std=c11",
71+
c_std,
6972
"-DHAVE_CONFIG_H",
7073
},
7174
});
@@ -135,7 +138,7 @@ pub fn build(b: *std.Build) void {
135138
"-Wall",
136139
"-Wextra",
137140
"-pedantic",
138-
"-std=c11",
141+
c_std,
139142
},
140143
});
141144

@@ -213,6 +216,7 @@ pub fn build(b: *std.Build) void {
213216
opt: std.builtin.OptimizeMode,
214217
colyseus_lib: *std.Build.Step.Compile,
215218
wslay_version_header: *std.Build.Step.ConfigHeader,
219+
c_standard: []const u8,
216220
) void {
217221
const example_module = builder.createModule(.{
218222
.target = tgt,
@@ -230,7 +234,7 @@ pub fn build(b: *std.Build) void {
230234
.flags = &.{
231235
"-Wall",
232236
"-Wextra",
233-
"-std=c11",
237+
c_standard,
234238
},
235239
});
236240

@@ -261,14 +265,14 @@ pub fn build(b: *std.Build) void {
261265
.source_file = "examples/simple_example.c",
262266
.run_step_name = "run-example",
263267
.run_step_desc = "Run the simple example",
264-
}, target, optimize, colyseus, wslay_version_h);
268+
}, target, optimize, colyseus, wslay_version_h, c_std);
265269

266270
buildExample(b, .{
267271
.name = "auth_example",
268272
.source_file = "examples/auth_example.c",
269273
.run_step_name = "run-auth-example",
270274
.run_step_desc = "Run the auth example",
271-
}, target, optimize, colyseus, wslay_version_h);
275+
}, target, optimize, colyseus, wslay_version_h, c_std);
272276
}
273277

274278
// ========================================================================

include/colyseus/utils/strUtil.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@
66
#include <stddef.h>
77
#include <stdlib.h>
88

9-
#if !defined(HAVE_STRNDUP) && !defined(__APPLE__)
10-
#ifndef _GNU_SOURCE
11-
static inline size_t strnlen(const char *s, size_t maxlen) {
12-
size_t i;
13-
for (i = 0; i < maxlen && s[i]; i++);
14-
return i;
15-
}
16-
static inline char* strndup(const char* s, size_t n) {
17-
size_t len = strnlen(s, n);
18-
char* result = malloc(len + 1);
19-
if (!result) return NULL;
20-
memcpy(result, s, len);
21-
result[len] = '\0';
22-
return result;
23-
}
24-
#endif
25-
#endif
26-
279
#ifdef __cplusplus
2810
extern "C" {
2911
#endif

0 commit comments

Comments
 (0)