@zigc/lib 0.17.0-dev.44 → 0.17.0-dev.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/c/inttypes.zig +0 -10
- package/c/math.zig +27 -116
- package/c/search.zig +1 -27
- package/c/stdlib/drand48.zig +0 -57
- package/c/stdlib.zig +0 -100
- package/c/string.zig +0 -7
- package/c/strings.zig +0 -38
- package/c/unistd.zig +27 -26
- package/c.zig +1 -2
- package/compiler_rt/cos.zig +0 -2
- package/compiler_rt/exp.zig +0 -2
- package/compiler_rt/exp2.zig +0 -2
- package/compiler_rt/fabs.zig +0 -2
- package/compiler_rt/fma.zig +0 -2
- package/compiler_rt/fmax.zig +0 -2
- package/compiler_rt/fmin.zig +0 -2
- package/compiler_rt/fmod.zig +0 -2
- package/compiler_rt/limb64.zig +32 -0
- package/compiler_rt/log.zig +0 -2
- package/compiler_rt/log10.zig +0 -2
- package/compiler_rt/log2.zig +0 -2
- package/compiler_rt/round.zig +0 -2
- package/compiler_rt/sin.zig +0 -2
- package/compiler_rt/sincos.zig +0 -2
- package/compiler_rt/sqrt.zig +0 -2
- package/compiler_rt/tan.zig +0 -2
- package/compiler_rt/trunc.zig +0 -2
- package/package.json +1 -1
- package/std/Io/Dispatch.zig +3 -13
- package/std/Io/Semaphore.zig +112 -17
- package/std/Io/Threaded.zig +158 -24
- package/std/Io/Uring.zig +11 -13
- package/std/Io/net.zig +11 -11
- package/std/Io.zig +89 -25
- package/std/Target.zig +0 -2
- package/std/c/haiku.zig +3 -0
- package/std/c/serenity.zig +1 -6
- package/std/c.zig +59 -6
- package/std/debug.zig +1 -1
- package/std/os.zig +41 -0
- package/std/zig/LibCInstallation.zig +1 -0
- package/libc/musl/src/unistd/dup2.c +0 -20
- package/libc/musl/src/unistd/dup3.c +0 -26
package/c/inttypes.zig
CHANGED
|
@@ -24,13 +24,3 @@ fn imaxdiv(a: intmax_t, b: intmax_t) callconv(.c) imaxdiv_t {
|
|
|
24
24
|
.rem = @rem(a, b),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
test imaxabs {
|
|
29
|
-
const val: intmax_t = -10;
|
|
30
|
-
try std.testing.expectEqual(10, imaxabs(val));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
test imaxdiv {
|
|
34
|
-
const expected: imaxdiv_t = .{ .quot = 9, .rem = 0 };
|
|
35
|
-
try std.testing.expectEqual(expected, imaxdiv(9, 1));
|
|
36
|
-
}
|
package/c/math.zig
CHANGED
|
@@ -2,10 +2,6 @@ const builtin = @import("builtin");
|
|
|
2
2
|
|
|
3
3
|
const std = @import("std");
|
|
4
4
|
const math = std.math;
|
|
5
|
-
const expect = std.testing.expect;
|
|
6
|
-
const expectEqual = std.testing.expectEqual;
|
|
7
|
-
const expectApproxEqAbs = std.testing.expectApproxEqAbs;
|
|
8
|
-
const expectApproxEqRel = std.testing.expectApproxEqRel;
|
|
9
5
|
|
|
10
6
|
const symbol = @import("../c.zig").symbol;
|
|
11
7
|
|
|
@@ -116,13 +112,9 @@ fn atanf(x: f32) callconv(.c) f32 {
|
|
|
116
112
|
}
|
|
117
113
|
|
|
118
114
|
fn atanl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
119
|
-
return switch (@typeInfo(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
64 => math.atan(@as(f64, @floatCast(x))),
|
|
123
|
-
80 => math.atan(@as(f80, @floatCast(x))),
|
|
124
|
-
128 => math.atan(@as(f128, @floatCast(x))),
|
|
125
|
-
else => unreachable,
|
|
115
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
116
|
+
64 => std.c.atan(x),
|
|
117
|
+
else => math.atan(x),
|
|
126
118
|
};
|
|
127
119
|
}
|
|
128
120
|
|
|
@@ -143,7 +135,10 @@ fn copysignf(x: f32, y: f32) callconv(.c) f32 {
|
|
|
143
135
|
}
|
|
144
136
|
|
|
145
137
|
fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
146
|
-
return
|
|
138
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
139
|
+
64 => std.c.copysign(x, y),
|
|
140
|
+
else => math.copysign(x, y),
|
|
141
|
+
};
|
|
147
142
|
}
|
|
148
143
|
|
|
149
144
|
fn cosh(x: f64) callconv(.c) f64 {
|
|
@@ -183,15 +178,18 @@ fn fdimf(x: f32, y: f32) callconv(.c) f32 {
|
|
|
183
178
|
}
|
|
184
179
|
|
|
185
180
|
fn fdiml(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
186
|
-
return
|
|
181
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
182
|
+
64 => std.c.fdim(x, y),
|
|
183
|
+
else => fdimGeneric(c_longdouble, x, y),
|
|
184
|
+
};
|
|
187
185
|
}
|
|
188
186
|
|
|
189
187
|
fn finite(x: f64) callconv(.c) c_int {
|
|
190
|
-
return
|
|
188
|
+
return @intFromBool(math.isFinite(x));
|
|
191
189
|
}
|
|
192
190
|
|
|
193
191
|
fn finitef(x: f32) callconv(.c) c_int {
|
|
194
|
-
return
|
|
192
|
+
return @intFromBool(math.isFinite(x));
|
|
195
193
|
}
|
|
196
194
|
|
|
197
195
|
fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
|
|
@@ -222,7 +220,10 @@ fn frexpf(x: f32, e: *c_int) callconv(.c) f32 {
|
|
|
222
220
|
}
|
|
223
221
|
|
|
224
222
|
fn frexpl(x: c_longdouble, e: *c_int) callconv(.c) c_longdouble {
|
|
225
|
-
return
|
|
223
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
224
|
+
64 => std.c.frexp(x, e),
|
|
225
|
+
else => frexpGeneric(c_longdouble, x, e),
|
|
226
|
+
};
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
fn hypot(x: f64, y: f64) callconv(.c) f64 {
|
|
@@ -234,19 +235,22 @@ fn hypotf(x: f32, y: f32) callconv(.c) f32 {
|
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
237
|
-
return
|
|
238
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
239
|
+
64 => std.c.hypot(x, y),
|
|
240
|
+
else => math.hypot(x, y),
|
|
241
|
+
};
|
|
238
242
|
}
|
|
239
243
|
|
|
240
244
|
fn isnan(x: f64) callconv(.c) c_int {
|
|
241
|
-
return
|
|
245
|
+
return @intFromBool(math.isNan(x));
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
fn isnanf(x: f32) callconv(.c) c_int {
|
|
245
|
-
return
|
|
249
|
+
return @intFromBool(math.isNan(x));
|
|
246
250
|
}
|
|
247
251
|
|
|
248
252
|
fn isnanl(x: c_longdouble) callconv(.c) c_int {
|
|
249
|
-
return
|
|
253
|
+
return @intFromBool(math.isNan(x));
|
|
250
254
|
}
|
|
251
255
|
|
|
252
256
|
fn lrint(x: f64) callconv(.c) c_long {
|
|
@@ -290,60 +294,10 @@ fn modff(x: f32, iptr: *f32) callconv(.c) f32 {
|
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
fn modfl(x: c_longdouble, iptr: *c_longdouble) callconv(.c) c_longdouble {
|
|
293
|
-
return
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
fn testModf(comptime T: type) !void {
|
|
297
|
-
// Choose the appropriate `modf` impl to test based on type
|
|
298
|
-
const f = switch (T) {
|
|
299
|
-
f32 => modff,
|
|
300
|
-
f64 => modf,
|
|
301
|
-
c_longdouble => modfl,
|
|
302
|
-
else => @compileError("modf not implemented for " ++ @typeName(T)),
|
|
297
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
298
|
+
64 => std.c.modf(x, iptr),
|
|
299
|
+
else => modfGeneric(c_longdouble, x, iptr),
|
|
303
300
|
};
|
|
304
|
-
|
|
305
|
-
var int: T = undefined;
|
|
306
|
-
const iptr = ∫
|
|
307
|
-
const eps_val: comptime_float = @max(1e-6, math.floatEps(T));
|
|
308
|
-
|
|
309
|
-
const normal_frac = f(@as(T, 1234.567), iptr);
|
|
310
|
-
// Account for precision error
|
|
311
|
-
const expected = 1234.567 - @as(T, 1234);
|
|
312
|
-
try expectApproxEqAbs(expected, normal_frac, eps_val);
|
|
313
|
-
try expectApproxEqRel(@as(T, 1234.0), iptr.*, eps_val);
|
|
314
|
-
|
|
315
|
-
// When `x` is a NaN, NaN is returned and `*iptr` is set to NaN
|
|
316
|
-
const nan_frac = f(math.nan(T), iptr);
|
|
317
|
-
try expect(math.isNan(nan_frac));
|
|
318
|
-
try expect(math.isNan(iptr.*));
|
|
319
|
-
|
|
320
|
-
// When `x` is positive infinity, +0 is returned and `*iptr` is set to
|
|
321
|
-
// positive infinity
|
|
322
|
-
const pos_zero_frac = f(math.inf(T), iptr);
|
|
323
|
-
try expect(math.isPositiveZero(pos_zero_frac));
|
|
324
|
-
try expect(math.isPositiveInf(iptr.*));
|
|
325
|
-
|
|
326
|
-
// When `x` is negative infinity, -0 is returned and `*iptr` is set to
|
|
327
|
-
// negative infinity
|
|
328
|
-
const neg_zero_frac = f(-math.inf(T), iptr);
|
|
329
|
-
try expect(math.isNegativeZero(neg_zero_frac));
|
|
330
|
-
try expect(math.isNegativeInf(iptr.*));
|
|
331
|
-
|
|
332
|
-
// Return -0 when `x` is a negative integer
|
|
333
|
-
const nz_frac = f(@as(T, -1000.0), iptr);
|
|
334
|
-
try expect(math.isNegativeZero(nz_frac));
|
|
335
|
-
try expectEqual(@as(T, -1000.0), iptr.*);
|
|
336
|
-
|
|
337
|
-
// Return +0 when `x` is a positive integer
|
|
338
|
-
const pz_frac = f(@as(T, 1000.0), iptr);
|
|
339
|
-
try expect(math.isPositiveZero(pz_frac));
|
|
340
|
-
try expectEqual(@as(T, 1000.0), iptr.*);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
test "modf" {
|
|
344
|
-
try testModf(f32);
|
|
345
|
-
try testModf(f64);
|
|
346
|
-
try testModf(c_longdouble);
|
|
347
301
|
}
|
|
348
302
|
|
|
349
303
|
fn nan(_: [*:0]const c_char) callconv(.c) f64 {
|
|
@@ -410,49 +364,6 @@ fn rintf(x: f32) callconv(.c) f32 {
|
|
|
410
364
|
return y;
|
|
411
365
|
}
|
|
412
366
|
|
|
413
|
-
fn testRint(comptime T: type) !void {
|
|
414
|
-
const f = switch (T) {
|
|
415
|
-
f32 => rintf,
|
|
416
|
-
f64 => rint,
|
|
417
|
-
else => @compileError("rint not implemented for" ++ @typeName(T)),
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
// Positive numbers round correctly
|
|
421
|
-
try expectEqual(@as(T, 42.0), f(42.2));
|
|
422
|
-
try expectEqual(@as(T, 42.0), f(41.8));
|
|
423
|
-
|
|
424
|
-
// Negative numbers round correctly
|
|
425
|
-
try expectEqual(@as(T, -6.0), f(-5.9));
|
|
426
|
-
try expectEqual(@as(T, -6.0), f(-6.1));
|
|
427
|
-
|
|
428
|
-
// No rounding needed test
|
|
429
|
-
try expectEqual(@as(T, 5.0), f(5.0));
|
|
430
|
-
try expectEqual(@as(T, -10.0), f(-10.0));
|
|
431
|
-
try expectEqual(@as(T, 0.0), f(0.0));
|
|
432
|
-
|
|
433
|
-
// Very large numbers return unchanged
|
|
434
|
-
const large: T = 9007199254740992.0; // 2^53
|
|
435
|
-
try expectEqual(large, f(large));
|
|
436
|
-
try expectEqual(-large, f(-large));
|
|
437
|
-
|
|
438
|
-
// Small positive numbers round to zero
|
|
439
|
-
const pos_result = f(0.3);
|
|
440
|
-
try expect(math.isPositiveZero(pos_result));
|
|
441
|
-
|
|
442
|
-
// Small negative numbers round to negative zero
|
|
443
|
-
const neg_result = f(-0.3);
|
|
444
|
-
try expect(math.isNegativeZero(neg_result));
|
|
445
|
-
|
|
446
|
-
// Exact half rounds to nearest even (banker's rounding)
|
|
447
|
-
try expectEqual(@as(T, 2.0), f(2.5));
|
|
448
|
-
try expectEqual(@as(T, 4.0), f(3.5));
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
test "rint" {
|
|
452
|
-
try testRint(f32);
|
|
453
|
-
try testRint(f64);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
367
|
fn tanh(x: f64) callconv(.c) f64 {
|
|
457
368
|
return math.tanh(x);
|
|
458
369
|
}
|
package/c/search.zig
CHANGED
|
@@ -9,6 +9,7 @@ comptime {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/// Not defined in `std.c` because C headers don't either.
|
|
12
13
|
const Node = extern struct {
|
|
13
14
|
next: ?*Node,
|
|
14
15
|
prev: ?*Node,
|
|
@@ -38,30 +39,3 @@ fn remque(element: *anyopaque) callconv(.c) void {
|
|
|
38
39
|
if (e.next) |next| next.prev = e.prev;
|
|
39
40
|
if (e.prev) |prev| prev.next = e.next;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
test "insque and remque" {
|
|
43
|
-
var first = Node{ .next = null, .prev = null };
|
|
44
|
-
var second = Node{ .next = null, .prev = null };
|
|
45
|
-
var third = Node{ .next = null, .prev = null };
|
|
46
|
-
|
|
47
|
-
insque(&first, null);
|
|
48
|
-
try std.testing.expectEqual(@as(?*Node, null), first.next);
|
|
49
|
-
try std.testing.expectEqual(@as(?*Node, null), first.prev);
|
|
50
|
-
|
|
51
|
-
insque(&second, &first);
|
|
52
|
-
try std.testing.expectEqual(@as(?*Node, &second), first.next);
|
|
53
|
-
try std.testing.expectEqual(@as(?*Node, &first), second.prev);
|
|
54
|
-
|
|
55
|
-
insque(&third, &first);
|
|
56
|
-
try std.testing.expectEqual(@as(?*Node, &third), first.next);
|
|
57
|
-
try std.testing.expectEqual(@as(?*Node, &second), third.next);
|
|
58
|
-
try std.testing.expectEqual(@as(?*Node, &first), third.prev);
|
|
59
|
-
try std.testing.expectEqual(@as(?*Node, &third), second.prev);
|
|
60
|
-
|
|
61
|
-
remque(&third);
|
|
62
|
-
try std.testing.expectEqual(@as(?*Node, &second), first.next);
|
|
63
|
-
try std.testing.expectEqual(@as(?*Node, &first), second.prev);
|
|
64
|
-
|
|
65
|
-
remque(&second);
|
|
66
|
-
try std.testing.expectEqual(@as(?*Node, null), first.next);
|
|
67
|
-
}
|
package/c/stdlib/drand48.zig
CHANGED
|
@@ -90,60 +90,3 @@ fn srand48(seedval: c_long) callconv(.c) void {
|
|
|
90
90
|
const xi = (@as(u32, @truncate(@as(c_ulong, @bitCast(seedval)))) << 16) | 0x330E;
|
|
91
91
|
lcg = .init(xi, default_multiplier, default_addend);
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
test erand48 {
|
|
95
|
-
var xsubi: [3]c_ushort = .{ 37174, 64810, 11603 };
|
|
96
|
-
|
|
97
|
-
try std.testing.expectApproxEqAbs(0.8965, erand48(&xsubi), 0.0005);
|
|
98
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 22537, 47966, 58735 }, &xsubi);
|
|
99
|
-
|
|
100
|
-
try std.testing.expectApproxEqAbs(0.3375, erand48(&xsubi), 0.0005);
|
|
101
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 37344, 32911, 22119 }, &xsubi);
|
|
102
|
-
|
|
103
|
-
try std.testing.expectApproxEqAbs(0.6475, erand48(&xsubi), 0.0005);
|
|
104
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 23659, 29872, 42445 }, &xsubi);
|
|
105
|
-
|
|
106
|
-
try std.testing.expectApproxEqAbs(0.5005, erand48(&xsubi), 0.0005);
|
|
107
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 31642, 7875, 32802 }, &xsubi);
|
|
108
|
-
|
|
109
|
-
try std.testing.expectApproxEqAbs(0.5065, erand48(&xsubi), 0.0005);
|
|
110
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 64669, 14399, 33170 }, &xsubi);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
test jrand48 {
|
|
114
|
-
var xsubi: [3]c_ushort = .{ 25175, 11052, 45015 };
|
|
115
|
-
|
|
116
|
-
try std.testing.expectEqual(1699503220, jrand48(&xsubi));
|
|
117
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 2326, 23668, 25932 }, &xsubi);
|
|
118
|
-
|
|
119
|
-
try std.testing.expectEqual(-992276007, jrand48(&xsubi));
|
|
120
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 41577, 4569, 50395 }, &xsubi);
|
|
121
|
-
|
|
122
|
-
try std.testing.expectEqual(-19535776, jrand48(&xsubi));
|
|
123
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 31936, 59488, 65237 }, &xsubi);
|
|
124
|
-
|
|
125
|
-
try std.testing.expectEqual(79438377, jrand48(&xsubi));
|
|
126
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 40395, 8745, 1212 }, &xsubi);
|
|
127
|
-
|
|
128
|
-
try std.testing.expectEqual(-1258917728, jrand48(&xsubi));
|
|
129
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 37242, 28832, 46326 }, &xsubi);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
test nrand48 {
|
|
133
|
-
var xsubi: [3]c_ushort = .{ 546, 33817, 23389 };
|
|
134
|
-
|
|
135
|
-
try std.testing.expectEqual(914920692, nrand48(&xsubi));
|
|
136
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 29829, 10728, 27921 }, &xsubi);
|
|
137
|
-
|
|
138
|
-
try std.testing.expectEqual(754104482, nrand48(&xsubi));
|
|
139
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 6828, 28997, 23013 }, &xsubi);
|
|
140
|
-
|
|
141
|
-
try std.testing.expectEqual(609453945, nrand48(&xsubi));
|
|
142
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 58183, 3826, 18599 }, &xsubi);
|
|
143
|
-
|
|
144
|
-
try std.testing.expectEqual(1878644360, nrand48(&xsubi));
|
|
145
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 36678, 44304, 57331 }, &xsubi);
|
|
146
|
-
|
|
147
|
-
try std.testing.expectEqual(2114923686, nrand48(&xsubi));
|
|
148
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 58585, 22861, 64542 }, &xsubi);
|
|
149
|
-
}
|
package/c/stdlib.zig
CHANGED
|
@@ -294,103 +294,3 @@ fn bsearch(key: *const anyopaque, base: *const anyopaque, n: usize, size: usize,
|
|
|
294
294
|
}
|
|
295
295
|
return null;
|
|
296
296
|
}
|
|
297
|
-
|
|
298
|
-
test abs {
|
|
299
|
-
const val: c_int = -10;
|
|
300
|
-
try std.testing.expectEqual(10, abs(val));
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
test labs {
|
|
304
|
-
const val: c_long = -10;
|
|
305
|
-
try std.testing.expectEqual(10, labs(val));
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
test llabs {
|
|
309
|
-
const val: c_longlong = -10;
|
|
310
|
-
try std.testing.expectEqual(10, llabs(val));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
test div {
|
|
314
|
-
const expected: div_t = .{ .quot = 5, .rem = 5 };
|
|
315
|
-
try std.testing.expectEqual(expected, div(55, 10));
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
test ldiv {
|
|
319
|
-
const expected: ldiv_t = .{ .quot = -6, .rem = 2 };
|
|
320
|
-
try std.testing.expectEqual(expected, ldiv(38, -6));
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
test lldiv {
|
|
324
|
-
const expected: lldiv_t = .{ .quot = 1, .rem = 2 };
|
|
325
|
-
try std.testing.expectEqual(expected, lldiv(5, 3));
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
test atoi {
|
|
329
|
-
try std.testing.expectEqual(0, atoi(@ptrCast("stop42true")));
|
|
330
|
-
try std.testing.expectEqual(42, atoi(@ptrCast("42true")));
|
|
331
|
-
try std.testing.expectEqual(-1, atoi(@ptrCast("-01")));
|
|
332
|
-
try std.testing.expectEqual(1, atoi(@ptrCast("+001")));
|
|
333
|
-
try std.testing.expectEqual(100, atoi(@ptrCast(" 100")));
|
|
334
|
-
try std.testing.expectEqual(500, atoi(@ptrCast("000000000000500")));
|
|
335
|
-
try std.testing.expectEqual(1111, atoi(@ptrCast("0000000000001111_0000")));
|
|
336
|
-
try std.testing.expectEqual(0, atoi(@ptrCast("0xAA")));
|
|
337
|
-
try std.testing.expectEqual(700, atoi(@ptrCast("700B")));
|
|
338
|
-
try std.testing.expectEqual(32453, atoi(@ptrCast("+32453more")));
|
|
339
|
-
try std.testing.expectEqual(std.math.maxInt(c_int), atoi(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_int)}))));
|
|
340
|
-
try std.testing.expectEqual(std.math.minInt(c_int), atoi(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_int)}))));
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
test atol {
|
|
344
|
-
try std.testing.expectEqual(0, atol(@ptrCast("stop42true")));
|
|
345
|
-
try std.testing.expectEqual(42, atol(@ptrCast("42true")));
|
|
346
|
-
try std.testing.expectEqual(-1, atol(@ptrCast("-01")));
|
|
347
|
-
try std.testing.expectEqual(1, atol(@ptrCast("+001")));
|
|
348
|
-
try std.testing.expectEqual(100, atol(@ptrCast(" 100")));
|
|
349
|
-
try std.testing.expectEqual(500, atol(@ptrCast("000000000000500")));
|
|
350
|
-
try std.testing.expectEqual(1111, atol(@ptrCast("0000000000001111_0000")));
|
|
351
|
-
try std.testing.expectEqual(0, atol(@ptrCast("0xAA")));
|
|
352
|
-
try std.testing.expectEqual(700, atol(@ptrCast("700B")));
|
|
353
|
-
try std.testing.expectEqual(32453, atol(@ptrCast("+32453more")));
|
|
354
|
-
try std.testing.expectEqual(std.math.maxInt(c_long), atol(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_long)}))));
|
|
355
|
-
try std.testing.expectEqual(std.math.minInt(c_long), atol(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_long)}))));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
test atoll {
|
|
359
|
-
try std.testing.expectEqual(0, atoll(@ptrCast("stop42true")));
|
|
360
|
-
try std.testing.expectEqual(42, atoll(@ptrCast("42true")));
|
|
361
|
-
try std.testing.expectEqual(-1, atoll(@ptrCast("-01")));
|
|
362
|
-
try std.testing.expectEqual(1, atoll(@ptrCast("+001")));
|
|
363
|
-
try std.testing.expectEqual(100, atoll(@ptrCast(" 100")));
|
|
364
|
-
try std.testing.expectEqual(500, atoll(@ptrCast("000000000000500")));
|
|
365
|
-
try std.testing.expectEqual(1111, atoll(@ptrCast("0000000000001111_0000")));
|
|
366
|
-
try std.testing.expectEqual(0, atoll(@ptrCast("0xAA")));
|
|
367
|
-
try std.testing.expectEqual(700, atoll(@ptrCast("700B")));
|
|
368
|
-
try std.testing.expectEqual(32453, atoll(@ptrCast(" +32453more")));
|
|
369
|
-
try std.testing.expectEqual(std.math.maxInt(c_longlong), atoll(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_longlong)}))));
|
|
370
|
-
try std.testing.expectEqual(std.math.minInt(c_longlong), atoll(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_longlong)}))));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// FIXME: We cannot test strtol, strtoll, strtoul, etc.. here as it must modify errno and libc is not linked in tests
|
|
374
|
-
|
|
375
|
-
test bsearch {
|
|
376
|
-
const Comparison = struct {
|
|
377
|
-
pub fn compare(a: *const anyopaque, b: *const anyopaque) callconv(.c) c_int {
|
|
378
|
-
const a_u16: *const u16 = @ptrCast(@alignCast(a));
|
|
379
|
-
const b_u16: *const u16 = @ptrCast(@alignCast(b));
|
|
380
|
-
|
|
381
|
-
return switch (std.math.order(a_u16.*, b_u16.*)) {
|
|
382
|
-
.gt => 1,
|
|
383
|
-
.eq => 0,
|
|
384
|
-
.lt => -1,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
const items: []const u16 = &.{ 0, 5, 7, 9, 10, 200, 512, 768 };
|
|
390
|
-
|
|
391
|
-
try std.testing.expectEqual(@as(?*anyopaque, null), bsearch(&@as(u16, 2000), items.ptr, items.len, @sizeOf(u16), Comparison.compare));
|
|
392
|
-
|
|
393
|
-
for (items) |*value| {
|
|
394
|
-
try std.testing.expectEqual(@as(*const anyopaque, value), bsearch(value, items.ptr, items.len, @sizeOf(u16), Comparison.compare));
|
|
395
|
-
}
|
|
396
|
-
}
|
package/c/string.zig
CHANGED
|
@@ -290,10 +290,3 @@ fn mempcpy(noalias dst: *anyopaque, noalias src: *const anyopaque, len: usize) c
|
|
|
290
290
|
@memcpy(dst_bytes[0..len], src_bytes[0..len]);
|
|
291
291
|
return dst_bytes + len;
|
|
292
292
|
}
|
|
293
|
-
|
|
294
|
-
test strncmp {
|
|
295
|
-
try std.testing.expect(strncmp(@ptrCast("a"), @ptrCast("b"), 1) < 0);
|
|
296
|
-
try std.testing.expect(strncmp(@ptrCast("a"), @ptrCast("c"), 1) < 0);
|
|
297
|
-
try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
|
|
298
|
-
try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0);
|
|
299
|
-
}
|
package/c/strings.zig
CHANGED
|
@@ -81,41 +81,3 @@ fn __strncasecmp_l(a: [*:0]const c_char, b: [*:0]const c_char, n: usize, locale:
|
|
|
81
81
|
_ = locale;
|
|
82
82
|
return strncasecmp(a, b, n);
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
test bzero {
|
|
86
|
-
var array: [10]u8 = [_]u8{ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
|
|
87
|
-
var a = std.mem.zeroes([array.len]u8);
|
|
88
|
-
a[9] = '0';
|
|
89
|
-
bzero(&array[0], 9);
|
|
90
|
-
try std.testing.expect(std.mem.eql(u8, &array, &a));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
test firstBitSet {
|
|
94
|
-
try std.testing.expectEqual(0, firstBitSet(usize, 0));
|
|
95
|
-
|
|
96
|
-
for (0..@bitSizeOf(usize)) |i| {
|
|
97
|
-
const bit = @as(usize, 1) << @intCast(i);
|
|
98
|
-
|
|
99
|
-
try std.testing.expectEqual(i + 1, firstBitSet(usize, bit));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
test strcasecmp {
|
|
104
|
-
try std.testing.expect(strcasecmp(@ptrCast("a"), @ptrCast("b")) < 0);
|
|
105
|
-
try std.testing.expect(strcasecmp(@ptrCast("b"), @ptrCast("a")) > 0);
|
|
106
|
-
try std.testing.expect(strcasecmp(@ptrCast("A"), @ptrCast("b")) < 0);
|
|
107
|
-
try std.testing.expect(strcasecmp(@ptrCast("b"), @ptrCast("A")) > 0);
|
|
108
|
-
try std.testing.expect(strcasecmp(@ptrCast("A"), @ptrCast("A")) == 0);
|
|
109
|
-
try std.testing.expect(strcasecmp(@ptrCast("B"), @ptrCast("b")) == 0);
|
|
110
|
-
try std.testing.expect(strcasecmp(@ptrCast("bb"), @ptrCast("AA")) > 0);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
test strncasecmp {
|
|
114
|
-
try std.testing.expect(strncasecmp(@ptrCast("a"), @ptrCast("b"), 1) < 0);
|
|
115
|
-
try std.testing.expect(strncasecmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
|
|
116
|
-
try std.testing.expect(strncasecmp(@ptrCast("A"), @ptrCast("b"), 1) < 0);
|
|
117
|
-
try std.testing.expect(strncasecmp(@ptrCast("b"), @ptrCast("A"), 1) > 0);
|
|
118
|
-
try std.testing.expect(strncasecmp(@ptrCast("A"), @ptrCast("A"), 1) == 0);
|
|
119
|
-
try std.testing.expect(strncasecmp(@ptrCast("B"), @ptrCast("b"), 1) == 0);
|
|
120
|
-
try std.testing.expect(strncasecmp(@ptrCast("bb"), @ptrCast("AA"), 2) > 0);
|
|
121
|
-
}
|
package/c/unistd.zig
CHANGED
|
@@ -21,6 +21,8 @@ comptime {
|
|
|
21
21
|
symbol(&chrootLinux, "chroot");
|
|
22
22
|
symbol(&ctermidLinux, "ctermid");
|
|
23
23
|
symbol(&dupLinux, "dup");
|
|
24
|
+
symbol(&dup2Linux, "dup2");
|
|
25
|
+
symbol(&dup3Linux, "dup3");
|
|
24
26
|
|
|
25
27
|
symbol(&getegidLinux, "getegid");
|
|
26
28
|
symbol(&geteuidLinux, "geteuid");
|
|
@@ -101,6 +103,31 @@ fn dupLinux(fd: c_int) callconv(.c) c_int {
|
|
|
101
103
|
return errno(linux.dup(fd));
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
fn dup2Linux(old: c_int, new: c_int) callconv(.c) c_int {
|
|
107
|
+
const busy: usize = @bitCast(-@as(isize, @intFromEnum(linux.E.BUSY)));
|
|
108
|
+
var res = busy;
|
|
109
|
+
while (res == busy) res = linux.dup2(old, new);
|
|
110
|
+
return errno(res);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn dup3Linux(old: c_int, new: c_int, flags: c_int) callconv(.c) c_int {
|
|
114
|
+
const busy: usize = @bitCast(-@as(isize, @intFromEnum(linux.E.BUSY)));
|
|
115
|
+
var res = busy;
|
|
116
|
+
|
|
117
|
+
if (@hasField(linux.SYS, "dup3")) {
|
|
118
|
+
while (res == busy) res = linux.dup3(old, new, @intCast(flags));
|
|
119
|
+
} else if (@hasField(linux.SYS, "dup2")) {
|
|
120
|
+
const cloexec: c_int = @bitCast(linux.O{ .CLOEXEC = true });
|
|
121
|
+
const inval: usize = @bitCast(-@as(isize, @intFromEnum(linux.E.INVAL)));
|
|
122
|
+
if (old == new or (flags & ~cloexec != 0)) return errno(inval);
|
|
123
|
+
while (res == busy) res = linux.dup2(old, new);
|
|
124
|
+
_ = if (res >= 0 and (flags & cloexec == cloexec)) linux.fcntl(new, linux.F.SETFD, linux.FD_CLOEXEC);
|
|
125
|
+
} else {
|
|
126
|
+
return errno(@bitCast(-@as(isize, @intFromEnum(linux.E.NOSYS))));
|
|
127
|
+
}
|
|
128
|
+
return errno(res);
|
|
129
|
+
}
|
|
130
|
+
|
|
104
131
|
fn getegidLinux() callconv(.c) linux.gid_t {
|
|
105
132
|
return linux.getegid();
|
|
106
133
|
}
|
|
@@ -206,32 +233,6 @@ fn swab(noalias src_ptr: *const anyopaque, noalias dest_ptr: *anyopaque, n: isiz
|
|
|
206
233
|
}
|
|
207
234
|
}
|
|
208
235
|
|
|
209
|
-
test swab {
|
|
210
|
-
var a: [4]u8 = undefined;
|
|
211
|
-
@memset(a[0..], '\x00');
|
|
212
|
-
swab("abcd", &a, 4);
|
|
213
|
-
try std.testing.expectEqualSlices(u8, "badc", &a);
|
|
214
|
-
|
|
215
|
-
// Partial copy
|
|
216
|
-
@memset(a[0..], '\x00');
|
|
217
|
-
swab("abcd", &a, 2);
|
|
218
|
-
try std.testing.expectEqualSlices(u8, "ba\x00\x00", &a);
|
|
219
|
-
|
|
220
|
-
// n < 1
|
|
221
|
-
@memset(a[0..], '\x00');
|
|
222
|
-
swab("abcd", &a, 0);
|
|
223
|
-
try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a);
|
|
224
|
-
swab("abcd", &a, -1);
|
|
225
|
-
try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a);
|
|
226
|
-
|
|
227
|
-
// Odd n
|
|
228
|
-
@memset(a[0..], '\x00');
|
|
229
|
-
swab("abcd", &a, 1);
|
|
230
|
-
try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a);
|
|
231
|
-
swab("abcd", &a, 3);
|
|
232
|
-
try std.testing.expectEqualSlices(u8, "ba\x00\x00", &a);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
236
|
fn close(fd: std.c.fd_t) callconv(.c) c_int {
|
|
236
237
|
const signed: isize = @bitCast(linux.close(fd));
|
|
237
238
|
if (signed < 0) {
|
package/c.zig
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
//! bundled libcs.
|
|
3
3
|
//!
|
|
4
4
|
//! mingw-w64 libc is not fully statically linked, so some symbols don't need
|
|
5
|
-
//! to be exported.
|
|
6
|
-
//! dependency on msvcrt dll even when linking libc and targeting Windows.
|
|
5
|
+
//! to be exported.
|
|
7
6
|
|
|
8
7
|
const builtin = @import("builtin");
|
|
9
8
|
const std = @import("std");
|
package/compiler_rt/cos.zig
CHANGED
|
@@ -173,8 +173,6 @@ pub fn cosq(x: f128) callconv(.c) f128 {
|
|
|
173
173
|
|
|
174
174
|
pub fn cosl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
175
175
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
176
|
-
16 => return cosh(x),
|
|
177
|
-
32 => return cosf(x),
|
|
178
176
|
64 => return cos(x),
|
|
179
177
|
80 => return cosx(x),
|
|
180
178
|
128 => return cosq(x),
|
package/compiler_rt/exp.zig
CHANGED
|
@@ -198,8 +198,6 @@ const expq = @import("exp_f128.zig").exp;
|
|
|
198
198
|
|
|
199
199
|
pub fn expl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
200
200
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
201
|
-
16 => return __exph(x),
|
|
202
|
-
32 => return expf(x),
|
|
203
201
|
64 => return exp(x),
|
|
204
202
|
80 => return __expx(x),
|
|
205
203
|
128 => return expq(x),
|
package/compiler_rt/exp2.zig
CHANGED
|
@@ -165,8 +165,6 @@ pub const exp2q = @import("exp_f128.zig").exp2;
|
|
|
165
165
|
|
|
166
166
|
pub fn exp2l(x: c_longdouble) callconv(.c) c_longdouble {
|
|
167
167
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
168
|
-
16 => return __exp2h(x),
|
|
169
|
-
32 => return exp2f(x),
|
|
170
168
|
64 => return exp2(x),
|
|
171
169
|
80 => return __exp2x(x),
|
|
172
170
|
128 => return exp2q(x),
|
package/compiler_rt/fabs.zig
CHANGED
|
@@ -38,8 +38,6 @@ pub fn fabsq(a: f128) callconv(.c) f128 {
|
|
|
38
38
|
|
|
39
39
|
pub fn fabsl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
40
40
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
41
|
-
16 => return __fabsh(x),
|
|
42
|
-
32 => return fabsf(x),
|
|
43
41
|
64 => return fabs(x),
|
|
44
42
|
80 => return __fabsx(x),
|
|
45
43
|
128 => return fabsq(x),
|
package/compiler_rt/fma.zig
CHANGED
|
@@ -151,8 +151,6 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.c) f128 {
|
|
|
151
151
|
|
|
152
152
|
pub fn fmal(x: c_longdouble, y: c_longdouble, z: c_longdouble) callconv(.c) c_longdouble {
|
|
153
153
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
154
|
-
16 => return __fmah(x, y, z),
|
|
155
|
-
32 => return fmaf(x, y, z),
|
|
156
154
|
64 => return fma(x, y, z),
|
|
157
155
|
80 => return __fmax(x, y, z),
|
|
158
156
|
128 => return fmaq(x, y, z),
|
package/compiler_rt/fmax.zig
CHANGED
|
@@ -39,8 +39,6 @@ pub fn fmaxq(x: f128, y: f128) callconv(.c) f128 {
|
|
|
39
39
|
|
|
40
40
|
pub fn fmaxl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
41
41
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
42
|
-
16 => return __fmaxh(x, y),
|
|
43
|
-
32 => return fmaxf(x, y),
|
|
44
42
|
64 => return fmax(x, y),
|
|
45
43
|
80 => return __fmaxx(x, y),
|
|
46
44
|
128 => return fmaxq(x, y),
|
package/compiler_rt/fmin.zig
CHANGED
|
@@ -39,8 +39,6 @@ pub fn fminq(x: f128, y: f128) callconv(.c) f128 {
|
|
|
39
39
|
|
|
40
40
|
pub fn fminl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
41
41
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
42
|
-
16 => return __fminh(x, y),
|
|
43
|
-
32 => return fminf(x, y),
|
|
44
42
|
64 => return fmin(x, y),
|
|
45
43
|
80 => return __fminx(x, y),
|
|
46
44
|
128 => return fminq(x, y),
|
package/compiler_rt/fmod.zig
CHANGED
|
@@ -251,8 +251,6 @@ pub fn fmodq(a: f128, b: f128) callconv(.c) f128 {
|
|
|
251
251
|
|
|
252
252
|
pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.c) c_longdouble {
|
|
253
253
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
254
|
-
16 => return __fmodh(a, b),
|
|
255
|
-
32 => return fmodf(a, b),
|
|
256
254
|
64 => return fmod(a, b),
|
|
257
255
|
80 => return __fmodx(a, b),
|
|
258
256
|
128 => return fmodq(a, b),
|