zig libc: simplify implementation

- use symbol export helper
- move all declarations from common.zig into c.zig
- correct documentation
- delete dead code
This commit is contained in:
Andrew Kelley
2026-02-10 13:06:18 -08:00
parent 6840326711
commit 96bd268c8c
18 changed files with 382 additions and 371 deletions
+13 -11
View File
@@ -1,21 +1,23 @@
//! drand48 functions are based off a 48-bit lcg prng: https://pubs.opengroup.org/onlinepubs/9799919799/functions/drand48.html
const std = @import("std");
const common = @import("../common.zig");
const builtin = @import("builtin");
const std = @import("std");
const Lcg = std.Random.lcg.Wrapping(u48);
const symbol = @import("../../c.zig").symbol;
comptime {
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
@export(&erand48, .{ .name = "erand48", .linkage = common.linkage, .visibility = common.visibility });
@export(&jrand48, .{ .name = "jrand48", .linkage = common.linkage, .visibility = common.visibility });
@export(&nrand48, .{ .name = "nrand48", .linkage = common.linkage, .visibility = common.visibility });
@export(&drand48, .{ .name = "drand48", .linkage = common.linkage, .visibility = common.visibility });
@export(&lrand48, .{ .name = "lrand48", .linkage = common.linkage, .visibility = common.visibility });
@export(&mrand48, .{ .name = "mrand48", .linkage = common.linkage, .visibility = common.visibility });
@export(&lcong48, .{ .name = "lcong48", .linkage = common.linkage, .visibility = common.visibility });
@export(&seed48, .{ .name = "seed48", .linkage = common.linkage, .visibility = common.visibility });
@export(&srand48, .{ .name = "srand48", .linkage = common.linkage, .visibility = common.visibility });
symbol(&erand48, "erand48");
symbol(&jrand48, "jrand48");
symbol(&nrand48, "nrand48");
symbol(&drand48, "drand48");
symbol(&lrand48, "lrand48");
symbol(&mrand48, "mrand48");
symbol(&lcong48, "lcong48");
symbol(&seed48, "seed48");
symbol(&srand48, "srand48");
}
}
+5 -5
View File
@@ -1,12 +1,12 @@
const std = @import("std");
const common = @import("../common.zig");
const builtin = @import("builtin");
const std = @import("std");
const symbol = @import("../../c.zig").symbol;
comptime {
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
@export(&rand, .{ .name = "rand", .linkage = common.linkage, .visibility = common.visibility });
@export(&srand, .{ .name = "srand", .linkage = common.linkage, .visibility = common.visibility });
@export(&rand_r, .{ .name = "rand_r", .linkage = common.linkage, .visibility = common.visibility });
symbol(&rand, "rand");
symbol(&srand, "srand");
symbol(&rand_r, "rand_r");
}
}