]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GenUUID/vtoy_gen_uuid.c
1.0.23 release
[Ventoy.git] / GenUUID / vtoy_gen_uuid.c
1 /******************************************************************************
2 * vtoy_gen_uuid.c
3 *
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27
28 int main()
29 {
30 int i;
31 int fd;
32 unsigned char uuid[16];
33
34 fd = open("/dev/random", O_RDONLY);
35 if (fd < 0)
36 {
37 srand(time(NULL));
38 for (i = 0; i < 16; i++)
39 {
40 uuid[i] = (unsigned char)(rand());
41 }
42 }
43 else
44 {
45 read(fd, uuid, 16);
46 }
47
48 fwrite(uuid, 1, 16, stdout);
49 return 0;
50 }