stew

a monorepo of some sort
Log | Files | Refs

commit 42fd665a4cce3cc0123263270a84ae69b0b35f5d
parent 1aa158f02842a44910960564e50f068ee5ab7f29
Author: Renev Pavel <an2qzavok@gmail.com>
Date:   Fri, 28 Oct 2022 11:05:56 +0000

src/uuid

Diffstat:
Asrc/uuid/6.out | 0
Asrc/uuid/mkfile | 7+++++++
Asrc/uuid/uuid.6 | 0
Asrc/uuid/uuid.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/src/uuid/6.out b/src/uuid/6.out Binary files differ. diff --git a/src/uuid/mkfile b/src/uuid/mkfile @@ -0,0 +1,7 @@ +</$objtype/mkfile + +BIN= +TARG=uuid +OFILES=uuid.$O + +</sys/src/cmd/mkone diff --git a/src/uuid/uuid.6 b/src/uuid/uuid.6 Binary files differ. diff --git a/src/uuid/uuid.c b/src/uuid/uuid.c @@ -0,0 +1,50 @@ +#include <u.h> +#include <libc.h> +#include <libsec.h> + +/* + * simple random uuid generator + */ + +struct UUID { + u32int tl; // time_low + u16int tm; // time_mid + u16int th; // time_hi_and_version + u8int sh; // clock_seq_hi_and_reserved + u8int sl; // clock_seq_low + u8int nd[6]; // node +} uuid; + +void +usage(void) +{ + fprint(2, "usage: %s\n", argv0); + exits("usage"); +} + +void +main(int argc, char **argv) +{ + ARGBEGIN{ + default: + usage(); + } ARGEND + if (argc != 0) usage(); + + genrandom((uchar *)(&uuid), sizeof(uuid)); + + // mask 1001 1111, data 0010 0000 + uuid.sh = uuid.sh & 0x60 | 0x20; + + // mask 0000 1111 1111 1111 + // data 0100 0000 0000 0000 + uuid.th = uuid.th & 0x0fff | 0x4000; + + print("%08ux-%04uhx-%04uhx-%02uhhx%02uhhx-", uuid.tl, uuid.tm, uuid.th, uuid.sh, uuid.sl); + + int i; + + for (i = 0; i < 6; i++) print("%02uhhx", uuid.nd[i]); + + print("\n"); +}