suwako / uuid-zig アーカイブ

このリポジトリはアーカイブされています。読むだけで、プッシュやイシューの変更は出来ません。

最初コミット

諏訪子 <suwako@076.moe>、2026-06-14 16:01
コミット 11c21c05ffed4efd1c977e66f5216f2b8a519168 ・ファイルを見る

3個のファイル、+45 -0

追加 LICENSE.md
@@ -0,0 +1,21 @@
1+# 076 Free License
2+
3+Copyright (c) テクニカル諏訪子
4+
5+Permission is hereby granted to any person obtaining a copy of the software
6+uuid-zig (the "Software") to use, modify, merge, copy, publish, distribute,
7+sublicense, and/or sell copies of the Software, subject to the following conditions:
8+
9+ 1. **Origin Attribution**:
10+ - You must not misrepresent the origin of the Software; you must not claim
11+ you created the original Software.
12+ 2. **Notice Preservation**:
13+ - This license and the above copyright notice must remain intact in all copies
14+ of the source code.
15+
16+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
追加 README.md
@@ -0,0 +1,5 @@
1+# UUID (Zig言語版)
2+
3+```sh
4+$ zig build-exe uuid.zig -Doptimize=ReleaseSmall -static
5+```
追加 uuid.zig
@@ -0,0 +1,19 @@
1+const std = @import("std");
2+
3+pub fn main(init: std.process.Init) !void {
4+ var data: [16]u8 = undefined;
5+ init.io.random(&data);
6+ data[6] = (data[6] & 0x0F) | 0x40;
7+ data[8] = (data[8] & 0x3F) | 0x80;
8+
9+ const hex = std.fmt.bytesToHex(&data, .lower);
10+ const id = try std.fmt.allocPrint(init.gpa, "{s}-{s}-{s}-{s}-{s}", .{
11+ hex[0..8],
12+ hex[8..12],
13+ hex[12..16],
14+ hex[16..20],
15+ hex[20..32],
16+ });
17+ defer init.gpa.free(id);
18+ std.debug.print("{s}\n", .{ id });
19+}