@zigc/lib 0.16.0 → 0.17.0-dev.135

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.
Files changed (268) hide show
  1. package/c/fcntl.zig +6 -1
  2. package/c/inttypes.zig +0 -10
  3. package/c/math.zig +46 -122
  4. package/c/pthread.zig +57 -0
  5. package/c/search.zig +1 -27
  6. package/c/stdlib/drand48.zig +0 -57
  7. package/c/stdlib.zig +0 -100
  8. package/c/string.zig +20 -7
  9. package/c/strings.zig +0 -38
  10. package/c/unistd.zig +27 -26
  11. package/c/wchar.zig +10 -0
  12. package/c.zig +2 -2
  13. package/compiler/aro/aro/CodeGen.zig +5 -6
  14. package/compiler/aro/aro/Compilation.zig +17 -14
  15. package/compiler/aro/aro/Driver.zig +14 -13
  16. package/compiler/aro/aro/Parser.zig +20 -15
  17. package/compiler/aro/aro/Pragma.zig +3 -2
  18. package/compiler/aro/aro/Preprocessor.zig +9 -6
  19. package/compiler/aro/aro/pragmas/message.zig +3 -2
  20. package/compiler/aro/aro/text_literal.zig +3 -2
  21. package/compiler/aro/assembly_backend/x86_64.zig +4 -4
  22. package/compiler/build_runner.zig +0 -2
  23. package/compiler/reduce/Walk.zig +7 -7
  24. package/compiler/test_runner.zig +2 -2
  25. package/compiler/translate-c/Translator.zig +6 -2
  26. package/compiler/translate-c/main.zig +1 -1
  27. package/compiler_rt/cos.zig +0 -2
  28. package/compiler_rt/divmodei4.zig +40 -17
  29. package/compiler_rt/exp.zig +1 -6
  30. package/compiler_rt/exp2.zig +1 -6
  31. package/compiler_rt/exp_f128.zig +377 -0
  32. package/compiler_rt/fabs.zig +0 -2
  33. package/compiler_rt/fma.zig +0 -2
  34. package/compiler_rt/fmax.zig +0 -2
  35. package/compiler_rt/fmin.zig +0 -2
  36. package/compiler_rt/fmod.zig +0 -2
  37. package/compiler_rt/limb64.zig +876 -15
  38. package/compiler_rt/log.zig +0 -2
  39. package/compiler_rt/log10.zig +0 -2
  40. package/compiler_rt/log2.zig +0 -2
  41. package/compiler_rt/mulXi3.zig +1 -1
  42. package/compiler_rt/round.zig +0 -2
  43. package/compiler_rt/sin.zig +0 -2
  44. package/compiler_rt/sincos.zig +0 -2
  45. package/compiler_rt/sqrt.zig +0 -2
  46. package/compiler_rt/ssp.zig +1 -1
  47. package/compiler_rt/tan.zig +0 -2
  48. package/compiler_rt/trunc.zig +0 -2
  49. package/compiler_rt/udivmodei4.zig +28 -0
  50. package/fuzzer.zig +2 -0
  51. package/libc/include/aarch64-linux-any/asm/hwcap.h +1 -0
  52. package/libc/include/aarch64-linux-any/asm/unistd_64.h +1 -0
  53. package/libc/include/any-linux-any/asm-generic/errno.h +2 -0
  54. package/libc/include/any-linux-any/asm-generic/unistd.h +4 -1
  55. package/libc/include/any-linux-any/drm/amdgpu_drm.h +20 -6
  56. package/libc/include/any-linux-any/drm/amdxdna_accel.h +8 -0
  57. package/libc/include/any-linux-any/drm/drm_fourcc.h +6 -6
  58. package/libc/include/any-linux-any/drm/panfrost_drm.h +75 -1
  59. package/libc/include/any-linux-any/drm/panthor_drm.h +154 -3
  60. package/libc/include/any-linux-any/drm/rocket_accel.h +74 -24
  61. package/libc/include/any-linux-any/drm/xe_drm.h +89 -6
  62. package/libc/include/any-linux-any/linux/android/binder.h +1 -1
  63. package/libc/include/any-linux-any/linux/bpf.h +28 -0
  64. package/libc/include/any-linux-any/linux/btrfs.h +1 -0
  65. package/libc/include/any-linux-any/linux/btrfs_tree.h +32 -2
  66. package/libc/include/any-linux-any/linux/dma-buf.h +1 -0
  67. package/libc/include/any-linux-any/linux/dpll.h +1 -0
  68. package/libc/include/any-linux-any/linux/elf.h +2 -0
  69. package/libc/include/any-linux-any/linux/ethtool.h +21 -5
  70. package/libc/include/any-linux-any/linux/fs.h +1 -0
  71. package/libc/include/any-linux-any/linux/hyperv.h +1 -1
  72. package/libc/include/any-linux-any/linux/idxd.h +134 -134
  73. package/libc/include/any-linux-any/linux/if_alg.h +1 -1
  74. package/libc/include/any-linux-any/linux/if_link.h +1 -0
  75. package/libc/include/any-linux-any/linux/input-event-codes.h +4 -0
  76. package/libc/include/any-linux-any/linux/io_uring/bpf_filter.h +68 -0
  77. package/libc/include/any-linux-any/linux/io_uring/query.h +5 -1
  78. package/libc/include/any-linux-any/linux/io_uring.h +33 -2
  79. package/libc/include/any-linux-any/linux/iommufd.h +39 -0
  80. package/libc/include/any-linux-any/linux/kfd_ioctl.h +13 -3
  81. package/libc/include/any-linux-any/linux/kfd_sysfs.h +2 -1
  82. package/libc/include/any-linux-any/linux/kvm.h +30 -6
  83. package/libc/include/any-linux-any/linux/landlock.h +22 -8
  84. package/libc/include/any-linux-any/linux/magic.h +1 -0
  85. package/libc/include/any-linux-any/linux/mempolicy.h +3 -0
  86. package/libc/include/any-linux-any/linux/mount.h +11 -2
  87. package/libc/include/any-linux-any/linux/mptcp_pm.h +1 -1
  88. package/libc/include/any-linux-any/linux/mshv.h +2 -0
  89. package/libc/include/any-linux-any/linux/netfilter_bridge.h +5 -4
  90. package/libc/include/any-linux-any/linux/netfilter_ipv4.h +4 -5
  91. package/libc/include/any-linux-any/linux/netfilter_ipv6.h +3 -4
  92. package/libc/include/any-linux-any/linux/nfs.h +1 -1
  93. package/libc/include/any-linux-any/linux/nfsd_netlink.h +1 -0
  94. package/libc/include/any-linux-any/linux/nilfs2_api.h +2 -2
  95. package/libc/include/any-linux-any/linux/nilfs2_ondisk.h +97 -66
  96. package/libc/include/any-linux-any/linux/nl80211.h +104 -3
  97. package/libc/include/any-linux-any/linux/pci.h +7 -0
  98. package/libc/include/any-linux-any/linux/pci_regs.h +65 -6
  99. package/libc/include/any-linux-any/linux/pcitest.h +1 -0
  100. package/libc/include/any-linux-any/linux/perf_event.h +24 -3
  101. package/libc/include/any-linux-any/linux/pkt_sched.h +1 -0
  102. package/libc/include/any-linux-any/linux/prctl.h +30 -0
  103. package/libc/include/any-linux-any/linux/rseq.h +62 -5
  104. package/libc/include/any-linux-any/linux/shm.h +0 -1
  105. package/libc/include/any-linux-any/linux/stddef.h +4 -0
  106. package/libc/include/any-linux-any/linux/sysctl.h +1 -2
  107. package/libc/include/any-linux-any/linux/taskstats.h +12 -1
  108. package/libc/include/any-linux-any/linux/tcp.h +23 -3
  109. package/libc/include/any-linux-any/linux/typelimits.h +8 -0
  110. package/libc/include/any-linux-any/linux/ublk_cmd.h +120 -1
  111. package/libc/include/any-linux-any/linux/v4l2-controls.h +63 -0
  112. package/libc/include/any-linux-any/linux/vbox_vmmdev_types.h +2 -2
  113. package/libc/include/any-linux-any/linux/vduse.h +80 -5
  114. package/libc/include/any-linux-any/linux/version.h +3 -3
  115. package/libc/include/any-linux-any/linux/vfio.h +4 -0
  116. package/libc/include/any-linux-any/linux/videodev2.h +3 -0
  117. package/libc/include/any-linux-any/linux/virtio_ring.h +1 -2
  118. package/libc/include/any-linux-any/linux/vmclock-abi.h +20 -0
  119. package/libc/include/any-linux-any/rdma/bnxt_re-abi.h +16 -0
  120. package/libc/include/any-linux-any/rdma/ib_user_ioctl_cmds.h +16 -0
  121. package/libc/include/any-linux-any/rdma/mana-abi.h +3 -0
  122. package/libc/include/any-linux-any/scsi/scsi_bsg_ufs.h +8 -9
  123. package/libc/include/any-linux-any/sound/sof/tokens.h +6 -0
  124. package/libc/include/arc-linux-any/asm/swab.h +0 -63
  125. package/libc/include/arc-linux-any/asm/unistd_32.h +1 -0
  126. package/libc/include/arm-linux-any/asm/ptrace.h +0 -9
  127. package/libc/include/arm-linux-any/asm/unistd-eabi.h +1 -0
  128. package/libc/include/arm-linux-any/asm/unistd-oabi.h +1 -0
  129. package/libc/include/csky-linux-any/asm/unistd_32.h +1 -0
  130. package/libc/include/hexagon-linux-any/asm/unistd_32.h +1 -0
  131. package/libc/include/loongarch-linux-any/asm/hwcap.h +1 -0
  132. package/libc/include/loongarch-linux-any/asm/kvm.h +1 -0
  133. package/libc/include/loongarch-linux-any/asm/kvm_para.h +1 -0
  134. package/libc/include/loongarch-linux-any/asm/unistd_32.h +2 -0
  135. package/libc/include/loongarch-linux-any/asm/unistd_64.h +2 -0
  136. package/libc/include/m68k-linux-any/asm/unistd_32.h +1 -0
  137. package/libc/include/mips-linux-any/asm/errno.h +2 -0
  138. package/libc/include/mips-linux-any/asm/unistd_n32.h +1 -0
  139. package/libc/include/mips-linux-any/asm/unistd_n64.h +1 -0
  140. package/libc/include/mips-linux-any/asm/unistd_o32.h +1 -0
  141. package/libc/include/powerpc-linux-any/asm/unistd_32.h +1 -0
  142. package/libc/include/powerpc-linux-any/asm/unistd_64.h +1 -0
  143. package/libc/include/riscv-linux-any/asm/hwprobe.h +4 -0
  144. package/libc/include/riscv-linux-any/asm/kvm.h +3 -0
  145. package/libc/include/riscv-linux-any/asm/ptrace.h +37 -0
  146. package/libc/include/riscv-linux-any/asm/sigcontext.h +1 -0
  147. package/libc/include/riscv-linux-any/asm/unistd_32.h +1 -0
  148. package/libc/include/riscv-linux-any/asm/unistd_64.h +1 -0
  149. package/libc/include/s390x-linux-any/asm/unistd_64.h +1 -0
  150. package/libc/include/sparc-linux-any/asm/errno.h +2 -0
  151. package/libc/include/sparc-linux-any/asm/ioctls.h +4 -4
  152. package/libc/include/sparc-linux-any/asm/unistd_32.h +2 -0
  153. package/libc/include/sparc-linux-any/asm/unistd_64.h +2 -0
  154. package/libc/include/x86-linux-any/asm/auxvec.h +0 -4
  155. package/libc/include/x86-linux-any/asm/kvm.h +13 -8
  156. package/libc/include/x86-linux-any/asm/svm.h +16 -16
  157. package/libc/include/x86-linux-any/asm/unistd_32.h +1 -0
  158. package/libc/include/x86-linux-any/asm/unistd_64.h +1 -0
  159. package/libc/include/x86-linux-any/asm/unistd_x32.h +1 -0
  160. package/libc/include/xtensa-linux-any/asm/unistd_32.h +1 -0
  161. package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
  162. package/package.json +1 -1
  163. package/std/Build/Cache.zig +6 -6
  164. package/std/Build/Step/Compile.zig +0 -1
  165. package/std/Build/Step/Run.zig +2 -2
  166. package/std/Build/Step.zig +2 -4
  167. package/std/Build/WebServer.zig +2 -2
  168. package/std/Build.zig +0 -3
  169. package/std/Io/Dir.zig +7 -2
  170. package/std/Io/Dispatch.zig +3 -13
  171. package/std/Io/File/Writer.zig +8 -6
  172. package/std/Io/Reader.zig +8 -9
  173. package/std/Io/Semaphore.zig +112 -17
  174. package/std/Io/Terminal.zig +1 -1
  175. package/std/Io/Threaded.zig +171 -37
  176. package/std/Io/Uring.zig +13 -15
  177. package/std/Io/Writer.zig +46 -42
  178. package/std/Io/net.zig +11 -11
  179. package/std/Io.zig +90 -26
  180. package/std/SemanticVersion.zig +1 -1
  181. package/std/Target/Query.zig +2 -2
  182. package/std/Target.zig +50 -5
  183. package/std/array_hash_map.zig +9 -18
  184. package/std/builtin.zig +4 -0
  185. package/std/c/haiku.zig +3 -0
  186. package/std/c/serenity.zig +1 -6
  187. package/std/c.zig +89 -7
  188. package/std/compress/flate/Decompress.zig +2 -3
  189. package/std/compress/zstd/Decompress.zig +2 -4
  190. package/std/crypto/Certificate.zig +13 -1
  191. package/std/crypto/ascon.zig +75 -33
  192. package/std/crypto/codecs/asn1/Oid.zig +12 -1
  193. package/std/crypto/codecs/base64_hex_ct.zig +2 -4
  194. package/std/crypto/ml_kem.zig +2 -9
  195. package/std/crypto/tls/Client.zig +79 -4
  196. package/std/crypto/tls.zig +1 -1
  197. package/std/crypto.zig +1 -0
  198. package/std/debug/Pdb.zig +1 -1
  199. package/std/debug.zig +4 -3
  200. package/std/fmt.zig +8 -3
  201. package/std/fs/path.zig +6 -4
  202. package/std/heap/BufferFirstAllocator.zig +165 -0
  203. package/std/heap.zig +2 -126
  204. package/std/http/Client.zig +21 -24
  205. package/std/http.zig +3 -4
  206. package/std/json/Scanner.zig +2 -2
  207. package/std/os/emscripten.zig +1 -1
  208. package/std/os/linux/IoUring.zig +2 -0
  209. package/std/os/linux/aarch64.zig +41 -12
  210. package/std/os/linux/arc.zig +173 -0
  211. package/std/os/linux/arm.zig +41 -12
  212. package/std/os/linux/hexagon.zig +33 -11
  213. package/std/os/linux/loongarch32.zig +41 -13
  214. package/std/os/linux/loongarch64.zig +41 -12
  215. package/std/os/linux/m68k.zig +41 -13
  216. package/std/os/linux/mips.zig +67 -36
  217. package/std/os/linux/mips64.zig +60 -29
  218. package/std/os/linux/mipsn32.zig +60 -29
  219. package/std/os/linux/or1k.zig +41 -12
  220. package/std/os/linux/powerpc.zig +41 -12
  221. package/std/os/linux/powerpc64.zig +41 -12
  222. package/std/os/linux/riscv32.zig +41 -12
  223. package/std/os/linux/riscv64.zig +41 -12
  224. package/std/os/linux/s390x.zig +44 -7
  225. package/std/os/linux/sparc64.zig +83 -52
  226. package/std/os/linux/syscalls.zig +26 -1
  227. package/std/os/linux/thumb.zig +52 -36
  228. package/std/os/linux/x32.zig +41 -12
  229. package/std/os/linux/x86.zig +42 -13
  230. package/std/os/linux/x86_64.zig +41 -12
  231. package/std/os/linux.zig +412 -436
  232. package/std/os/uefi/tables/boot_services.zig +9 -8
  233. package/std/os.zig +41 -0
  234. package/std/process.zig +1 -1
  235. package/std/sort.zig +3 -3
  236. package/std/zig/Ast/Render.zig +3 -3
  237. package/std/zig/AstGen.zig +44 -98
  238. package/std/zig/AstRlAnnotate.zig +0 -11
  239. package/std/zig/BuiltinFn.zig +0 -32
  240. package/std/zig/LibCInstallation.zig +4 -3
  241. package/std/zig/Parse.zig +7 -7
  242. package/std/zig/WindowsSdk.zig +13 -13
  243. package/std/zig/Zir.zig +50 -63
  244. package/std/zig/ZonGen.zig +6 -5
  245. package/std/zig/llvm/Builder.zig +12 -12
  246. package/std/zig.zig +1 -10
  247. package/std/zip.zig +5 -5
  248. package/zig.h +340 -1
  249. package/libc/include/hexagon-linux-any/asm/signal.h +0 -29
  250. package/libc/include/s390x-linux-any/asm/tape390.h +0 -103
  251. package/libc/mingw/math/fdiml.c +0 -24
  252. package/libc/mingw/winpthreads/spinlock.c +0 -82
  253. package/libc/musl/src/linux/tee.c +0 -8
  254. package/libc/musl/src/math/fdimf.c +0 -10
  255. package/libc/musl/src/math/fdiml.c +0 -18
  256. package/libc/musl/src/string/strdup.c +0 -10
  257. package/libc/musl/src/string/strndup.c +0 -12
  258. package/libc/musl/src/string/wcsdup.c +0 -10
  259. package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
  260. package/libc/musl/src/thread/pthread_spin_init.c +0 -6
  261. package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
  262. package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
  263. package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
  264. package/libc/musl/src/unistd/dup2.c +0 -20
  265. package/libc/musl/src/unistd/dup3.c +0 -26
  266. package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
  267. package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
  268. package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
package/c/fcntl.zig CHANGED
@@ -12,11 +12,12 @@ comptime {
12
12
  symbol(&fallocateLinux, "fallocate");
13
13
  symbol(&posix_fadviseLinux, "posix_fadvise");
14
14
  symbol(&posix_fallocateLinux, "posix_fallocate");
15
+ symbol(&teeLinux, "tee");
15
16
  }
16
17
  }
17
18
 
18
19
  fn fallocateLinux(fd: c_int, mode: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
19
- return errno(linux.fallocate(fd, mode, offset, len));
20
+ return errno(linux.fallocate(fd, @bitCast(mode), offset, len));
20
21
  }
21
22
 
22
23
  fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callconv(.c) c_int {
@@ -26,3 +27,7 @@ fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callc
26
27
  fn posix_fallocateLinux(fd: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
27
28
  return errno(linux.fallocate(fd, 0, offset, len));
28
29
  }
30
+
31
+ fn teeLinux(src: c_int, dest: c_int, len: usize, flags: c_uint) callconv(.c) isize {
32
+ return errno(linux.tee(src, dest, len, flags));
33
+ }
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
 
@@ -45,6 +41,7 @@ comptime {
45
41
  if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
46
42
  symbol(&atanl, "atanl");
47
43
  symbol(&copysignl, "copysignl");
44
+ symbol(&fdiml, "fdiml");
48
45
  symbol(&nanl, "nanl");
49
46
  }
50
47
 
@@ -67,6 +64,7 @@ comptime {
67
64
  symbol(&exp10, "exp10");
68
65
  symbol(&exp10f, "exp10f");
69
66
  symbol(&fdim, "fdim");
67
+ symbol(&fdimf, "fdimf");
70
68
  symbol(&finite, "finite");
71
69
  symbol(&finitef, "finitef");
72
70
  symbol(&frexp, "frexp");
@@ -114,13 +112,9 @@ fn atanf(x: f32) callconv(.c) f32 {
114
112
  }
115
113
 
116
114
  fn atanl(x: c_longdouble) callconv(.c) c_longdouble {
117
- return switch (@typeInfo(@TypeOf(x)).float.bits) {
118
- 16 => math.atan(@as(f16, @floatCast(x))),
119
- 32 => math.atan(@as(f32, @floatCast(x))),
120
- 64 => math.atan(@as(f64, @floatCast(x))),
121
- 80 => math.atan(@as(f80, @floatCast(x))),
122
- 128 => math.atan(@as(f128, @floatCast(x))),
123
- else => unreachable,
115
+ return switch (@typeInfo(c_longdouble).float.bits) {
116
+ 64 => std.c.atan(x),
117
+ else => math.atan(x),
124
118
  };
125
119
  }
126
120
 
@@ -141,7 +135,10 @@ fn copysignf(x: f32, y: f32) callconv(.c) f32 {
141
135
  }
142
136
 
143
137
  fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
144
- return math.copysign(x, y);
138
+ return switch (@typeInfo(c_longdouble).float.bits) {
139
+ 64 => std.c.copysign(x, y),
140
+ else => math.copysign(x, y),
141
+ };
145
142
  }
146
143
 
147
144
  fn cosh(x: f64) callconv(.c) f64 {
@@ -160,25 +157,39 @@ fn exp10f(x: f32) callconv(.c) f32 {
160
157
  return math.pow(f32, 10.0, x);
161
158
  }
162
159
 
163
- fn fdim(x: f64, y: f64) callconv(.c) f64 {
164
- if (math.isNan(x)) {
160
+ fn fdimGeneric(comptime T: type, x: T, y: T) T {
161
+ if (math.isNan(x))
165
162
  return x;
166
- }
167
- if (math.isNan(y)) {
163
+
164
+ if (math.isNan(y))
168
165
  return y;
169
- }
170
- if (x > y) {
166
+
167
+ if (x > y)
171
168
  return x - y;
172
- }
173
169
  return 0;
174
170
  }
175
171
 
172
+ fn fdim(x: f64, y: f64) callconv(.c) f64 {
173
+ return fdimGeneric(f64, x, y);
174
+ }
175
+
176
+ fn fdimf(x: f32, y: f32) callconv(.c) f32 {
177
+ return fdimGeneric(f32, x, y);
178
+ }
179
+
180
+ fn fdiml(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
181
+ return switch (@typeInfo(c_longdouble).float.bits) {
182
+ 64 => std.c.fdim(x, y),
183
+ else => fdimGeneric(c_longdouble, x, y),
184
+ };
185
+ }
186
+
176
187
  fn finite(x: f64) callconv(.c) c_int {
177
- return if (math.isFinite(x)) 1 else 0;
188
+ return @intFromBool(math.isFinite(x));
178
189
  }
179
190
 
180
191
  fn finitef(x: f32) callconv(.c) c_int {
181
- return if (math.isFinite(x)) 1 else 0;
192
+ return @intFromBool(math.isFinite(x));
182
193
  }
183
194
 
184
195
  fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
@@ -209,7 +220,10 @@ fn frexpf(x: f32, e: *c_int) callconv(.c) f32 {
209
220
  }
210
221
 
211
222
  fn frexpl(x: c_longdouble, e: *c_int) callconv(.c) c_longdouble {
212
- return frexpGeneric(c_longdouble, x, e);
223
+ return switch (@typeInfo(c_longdouble).float.bits) {
224
+ 64 => std.c.frexp(x, e),
225
+ else => frexpGeneric(c_longdouble, x, e),
226
+ };
213
227
  }
214
228
 
215
229
  fn hypot(x: f64, y: f64) callconv(.c) f64 {
@@ -221,19 +235,22 @@ fn hypotf(x: f32, y: f32) callconv(.c) f32 {
221
235
  }
222
236
 
223
237
  fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
224
- return math.hypot(x, y);
238
+ return switch (@typeInfo(c_longdouble).float.bits) {
239
+ 64 => std.c.hypot(x, y),
240
+ else => math.hypot(x, y),
241
+ };
225
242
  }
226
243
 
227
244
  fn isnan(x: f64) callconv(.c) c_int {
228
- return if (math.isNan(x)) 1 else 0;
245
+ return @intFromBool(math.isNan(x));
229
246
  }
230
247
 
231
248
  fn isnanf(x: f32) callconv(.c) c_int {
232
- return if (math.isNan(x)) 1 else 0;
249
+ return @intFromBool(math.isNan(x));
233
250
  }
234
251
 
235
252
  fn isnanl(x: c_longdouble) callconv(.c) c_int {
236
- return if (math.isNan(x)) 1 else 0;
253
+ return @intFromBool(math.isNan(x));
237
254
  }
238
255
 
239
256
  fn lrint(x: f64) callconv(.c) c_long {
@@ -277,60 +294,10 @@ fn modff(x: f32, iptr: *f32) callconv(.c) f32 {
277
294
  }
278
295
 
279
296
  fn modfl(x: c_longdouble, iptr: *c_longdouble) callconv(.c) c_longdouble {
280
- return modfGeneric(c_longdouble, x, iptr);
281
- }
282
-
283
- fn testModf(comptime T: type) !void {
284
- // Choose the appropriate `modf` impl to test based on type
285
- const f = switch (T) {
286
- f32 => modff,
287
- f64 => modf,
288
- c_longdouble => modfl,
289
- 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),
290
300
  };
291
-
292
- var int: T = undefined;
293
- const iptr = ∫
294
- const eps_val: comptime_float = @max(1e-6, math.floatEps(T));
295
-
296
- const normal_frac = f(@as(T, 1234.567), iptr);
297
- // Account for precision error
298
- const expected = 1234.567 - @as(T, 1234);
299
- try expectApproxEqAbs(expected, normal_frac, eps_val);
300
- try expectApproxEqRel(@as(T, 1234.0), iptr.*, eps_val);
301
-
302
- // When `x` is a NaN, NaN is returned and `*iptr` is set to NaN
303
- const nan_frac = f(math.nan(T), iptr);
304
- try expect(math.isNan(nan_frac));
305
- try expect(math.isNan(iptr.*));
306
-
307
- // When `x` is positive infinity, +0 is returned and `*iptr` is set to
308
- // positive infinity
309
- const pos_zero_frac = f(math.inf(T), iptr);
310
- try expect(math.isPositiveZero(pos_zero_frac));
311
- try expect(math.isPositiveInf(iptr.*));
312
-
313
- // When `x` is negative infinity, -0 is returned and `*iptr` is set to
314
- // negative infinity
315
- const neg_zero_frac = f(-math.inf(T), iptr);
316
- try expect(math.isNegativeZero(neg_zero_frac));
317
- try expect(math.isNegativeInf(iptr.*));
318
-
319
- // Return -0 when `x` is a negative integer
320
- const nz_frac = f(@as(T, -1000.0), iptr);
321
- try expect(math.isNegativeZero(nz_frac));
322
- try expectEqual(@as(T, -1000.0), iptr.*);
323
-
324
- // Return +0 when `x` is a positive integer
325
- const pz_frac = f(@as(T, 1000.0), iptr);
326
- try expect(math.isPositiveZero(pz_frac));
327
- try expectEqual(@as(T, 1000.0), iptr.*);
328
- }
329
-
330
- test "modf" {
331
- try testModf(f32);
332
- try testModf(f64);
333
- try testModf(c_longdouble);
334
301
  }
335
302
 
336
303
  fn nan(_: [*:0]const c_char) callconv(.c) f64 {
@@ -397,49 +364,6 @@ fn rintf(x: f32) callconv(.c) f32 {
397
364
  return y;
398
365
  }
399
366
 
400
- fn testRint(comptime T: type) !void {
401
- const f = switch (T) {
402
- f32 => rintf,
403
- f64 => rint,
404
- else => @compileError("rint not implemented for" ++ @typeName(T)),
405
- };
406
-
407
- // Positive numbers round correctly
408
- try expectEqual(@as(T, 42.0), f(42.2));
409
- try expectEqual(@as(T, 42.0), f(41.8));
410
-
411
- // Negative numbers round correctly
412
- try expectEqual(@as(T, -6.0), f(-5.9));
413
- try expectEqual(@as(T, -6.0), f(-6.1));
414
-
415
- // No rounding needed test
416
- try expectEqual(@as(T, 5.0), f(5.0));
417
- try expectEqual(@as(T, -10.0), f(-10.0));
418
- try expectEqual(@as(T, 0.0), f(0.0));
419
-
420
- // Very large numbers return unchanged
421
- const large: T = 9007199254740992.0; // 2^53
422
- try expectEqual(large, f(large));
423
- try expectEqual(-large, f(-large));
424
-
425
- // Small positive numbers round to zero
426
- const pos_result = f(0.3);
427
- try expect(math.isPositiveZero(pos_result));
428
-
429
- // Small negative numbers round to negative zero
430
- const neg_result = f(-0.3);
431
- try expect(math.isNegativeZero(neg_result));
432
-
433
- // Exact half rounds to nearest even (banker's rounding)
434
- try expectEqual(@as(T, 2.0), f(2.5));
435
- try expectEqual(@as(T, 4.0), f(3.5));
436
- }
437
-
438
- test "rint" {
439
- try testRint(f32);
440
- try testRint(f64);
441
- }
442
-
443
367
  fn tanh(x: f64) callconv(.c) f64 {
444
368
  return math.tanh(x);
445
369
  }
package/c/pthread.zig ADDED
@@ -0,0 +1,57 @@
1
+ const builtin = @import("builtin");
2
+
3
+ const std = @import("std");
4
+ const c = std.c;
5
+
6
+ const symbol = @import("../c.zig").symbol;
7
+
8
+ comptime {
9
+ if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC() or builtin.target.isMinGW()) {
10
+ symbol(&pthread_spin_init, "pthread_spin_init");
11
+ symbol(&pthread_spin_destroy, "pthread_spin_destroy");
12
+ symbol(&pthread_spin_trylock, "pthread_spin_trylock");
13
+ symbol(&pthread_spin_lock, "pthread_spin_lock");
14
+ symbol(&pthread_spin_unlock, "pthread_spin_unlock");
15
+ }
16
+ }
17
+
18
+ const SpinLock = enum(c.pthread_spinlock_t) {
19
+ unlocked = if (builtin.target.isMinGW()) -1 else 0,
20
+ locked = if (builtin.target.isMinGW()) 0 else @intFromEnum(c.E.BUSY),
21
+ };
22
+
23
+ fn pthread_spin_init(s: *c.pthread_spinlock_t, pshared: c_int) callconv(.c) c_int {
24
+ _ = pshared;
25
+ const spin: *SpinLock = @ptrCast(s);
26
+ spin.* = .unlocked;
27
+ return 0;
28
+ }
29
+
30
+ fn pthread_spin_destroy(s: *c.pthread_spinlock_t) callconv(.c) c_int {
31
+ const spin: *SpinLock = @ptrCast(s);
32
+ spin.* = undefined;
33
+ return 0;
34
+ }
35
+
36
+ fn pthread_spin_trylock(s: *c.pthread_spinlock_t) callconv(.c) c_int {
37
+ const spin: *SpinLock = @ptrCast(s);
38
+ return if (@cmpxchgStrong(SpinLock, spin, .unlocked, .locked, .acquire, .monotonic)) |_| @intFromEnum(c.E.BUSY) else 0;
39
+ }
40
+
41
+ fn pthread_spin_lock(s: *c.pthread_spinlock_t) callconv(.c) c_int {
42
+ const spin: *SpinLock = @ptrCast(s);
43
+ if (builtin.single_threaded and @atomicLoad(SpinLock, spin, .monotonic) == .locked) return @intFromEnum(c.E.DEADLK);
44
+
45
+ while (@cmpxchgWeak(SpinLock, spin, .unlocked, .locked, .acquire, .monotonic)) |_| {
46
+ std.atomic.spinLoopHint();
47
+ }
48
+ return 0;
49
+ }
50
+
51
+ fn pthread_spin_unlock(s: *c.pthread_spinlock_t) callconv(.c) c_int {
52
+ const spin: *SpinLock = @ptrCast(s);
53
+
54
+ // "The results are undefined if the lock is not held by the calling thread"
55
+ std.debug.assert(@atomicRmw(SpinLock, spin, .Xchg, .unlocked, .release) == .locked);
56
+ return 0;
57
+ }
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
- }
@@ -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
@@ -1,6 +1,7 @@
1
1
  const builtin = @import("builtin");
2
2
  const std = @import("std");
3
3
  const symbol = @import("../c.zig").symbol;
4
+ const c = std.c;
4
5
 
5
6
  comptime {
6
7
  if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
@@ -24,6 +25,8 @@ comptime {
24
25
  symbol(&strpbrk, "strpbrk");
25
26
  symbol(&strstr, "strstr");
26
27
  symbol(&strtok, "strtok");
28
+ symbol(&strdup, "strdup");
29
+ symbol(&strndup, "strndup");
27
30
  // strlen is in compiler_rt
28
31
 
29
32
  symbol(&strtok_r, "strtok_r");
@@ -164,6 +167,23 @@ fn strtok(noalias maybe_str: ?[*:0]c_char, noalias values: [*:0]const c_char) ca
164
167
  return strtok_r(maybe_str, values, &state.str);
165
168
  }
166
169
 
170
+ fn strdup(str: [*:0]const c_char) callconv(.c) ?[*:0]c_char {
171
+ const len = std.mem.len(str);
172
+ const d_opaque = c.malloc(len + 1) orelse return null;
173
+ const d: [*]c_char = @ptrCast(d_opaque);
174
+ @memcpy(d[0 .. len + 1], str[0 .. len + 1]);
175
+ return @ptrCast(d);
176
+ }
177
+
178
+ fn strndup(str: [*:0]const c_char, n: usize) callconv(.c) ?[*:0]c_char {
179
+ const len = strnlen(str, n);
180
+ const d_opaque = c.malloc(len + 1) orelse return null;
181
+ const d: [*]c_char = @ptrCast(d_opaque);
182
+ @memcpy(d[0..len], str[0..len]);
183
+ d[len] = 0;
184
+ return @ptrCast(d);
185
+ }
186
+
167
187
  // strlen is in compiler_rt
168
188
 
169
189
  fn strtok_r(noalias maybe_str: ?[*:0]c_char, noalias values: [*:0]const c_char, noalias state: *?[*:0]c_char) callconv(.c) ?[*:0]c_char {
@@ -290,10 +310,3 @@ fn mempcpy(noalias dst: *anyopaque, noalias src: *const anyopaque, len: usize) c
290
310
  @memcpy(dst_bytes[0..len], src_bytes[0..len]);
291
311
  return dst_bytes + len;
292
312
  }
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
- }