最初コミット
諏訪子 <suwako@076.moe>、2026-06-14 15:56
コミット 0019636df9f9bd9c9f79b2de33f938ab058e5632
・ファイルを見る
3個のファイル、+79 -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-c (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,10 @@ | ||
| 1 | +# UUID (C言語版) | |
| 2 | + | |
| 3 | +```sh | |
| 4 | +$ cc -O3 uuid.c -o uuid -static | |
| 5 | +``` | |
| 6 | + | |
| 7 | +Windowsの場合: | |
| 8 | +```ps | |
| 9 | +cl.exe uuid.c /link bcrypt.lib /out:uuid.exe | |
| 10 | +``` |
追加
uuid.c
| @@ -0,0 +1,48 @@ | ||
| 1 | +#include <stdio.h> | |
| 2 | +#include <stdint.h> | |
| 3 | + | |
| 4 | +#if defined(_WIN64) | |
| 5 | +#ifndef WIN32_LEAN_AND_MEAN | |
| 6 | +#define WIN32_LEAN_AND_MEAN | |
| 7 | +#endif | |
| 8 | +#ifndef NOMINMAX | |
| 9 | +#define NOMINMAX | |
| 10 | +#endif | |
| 11 | +#include <windows.h> | |
| 12 | +#include <bcrypt.h> | |
| 13 | +#endif | |
| 14 | + | |
| 15 | +int main(void) { | |
| 16 | +#if defined(_WIN64) | |
| 17 | + BYTE buf[16]; | |
| 18 | + NTSTATUS data = BCryptGenRandom(NULL, buf, sizeof(buf), | |
| 19 | + BCRYPT_USE_SYSTEM_PREFERRED_RNG); | |
| 20 | + if (data != STATUS_SUCCESS) { | |
| 21 | + printf("エラー\n"); | |
| 22 | + return 1; | |
| 23 | + } | |
| 24 | +#else | |
| 25 | + FILE *fp = fopen("/dev/urandom", "rb"); | |
| 26 | + if (!fp) { | |
| 27 | + printf("エラー\n"); | |
| 28 | + return 1; | |
| 29 | + } | |
| 30 | + uint8_t data[16]; | |
| 31 | + fread(data, 1, sizeof(data), fp); | |
| 32 | + fclose(fp); | |
| 33 | +#endif | |
| 34 | + | |
| 35 | + data[6] = (data[6] & 0x0F) | 0x40; | |
| 36 | + data[8] = (data[8] & 0x3F) | 0x80; | |
| 37 | + char out[37]; | |
| 38 | + snprintf(out, 37, | |
| 39 | + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | |
| 40 | + data[0], data[1], data[2], data[3], | |
| 41 | + data[4], data[5], | |
| 42 | + data[6], data[7], | |
| 43 | + data[8], data[9], | |
| 44 | + data[10], data[11], data[12], data[13], data[14], data[15]); | |
| 45 | + printf("%s\n", out); | |
| 46 | + | |
| 47 | + return 0; | |
| 48 | +} |