Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107557673
D38820.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D38820.diff
View Options
diff --git a/bin/uuidgen/uuidgen.1 b/bin/uuidgen/uuidgen.1
--- a/bin/uuidgen/uuidgen.1
+++ b/bin/uuidgen/uuidgen.1
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 23, 2012
+.Dd March 1, 2024
.Dt UUIDGEN 1
.Os
.Sh NAME
@@ -34,6 +34,7 @@
.Nm
.Op Fl 1
.Op Fl r
+.Op Fl c
.Op Fl n Ar count
.Op Fl o Ar filename
.Sh DESCRIPTION
@@ -53,6 +54,8 @@
to not generate them in batch, but one at a time.
.It Fl r
This option controls creation of random UUID (version 4).
+.It Fl c
+This options contols creation of compact UUID (without hyphen).
.It Fl n
This option controls the number of identifiers generated.
By default, multiple identifiers are generated in batch.
diff --git a/bin/uuidgen/uuidgen.c b/bin/uuidgen/uuidgen.c
--- a/bin/uuidgen/uuidgen.c
+++ b/bin/uuidgen/uuidgen.c
@@ -46,6 +46,31 @@
exit(1);
}
+static void
+uuid_to_compact_string(const uuid_t *u, char **s, uint32_t *status)
+{
+ uuid_t nil;
+
+ if (status != NULL)
+ *status = uuid_s_ok;
+
+ if (s == NULL)
+ return;
+
+ if (u == NULL) {
+ u = &nil;
+ uuid_create_nil(&nil, NULL);
+ }
+
+ asprintf(s, "%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x",
+ u->time_low, u->time_mid, u->time_hi_and_version,
+ u->clock_seq_hi_and_reserved, u->clock_seq_low, u->node[0],
+ u->node[1], u->node[2], u->node[3], u->node[4], u->node[5]);
+
+ if (*s == NULL && status != NULL)
+ *status = uuid_s_no_memory;
+}
+
static int
uuidgen_v4(struct uuid *store, int count)
{
@@ -85,16 +110,20 @@
uuid_t *store, *uuid;
char *p;
int ch, count, i, iterate, status, version;
+ void (*tostring)(const uuid_t *, char **, uint32_t *) = uuid_to_string;
count = -1; /* no count yet */
fp = stdout; /* default output file */
iterate = 0; /* not one at a time */
version = 1; /* create uuid v1 by default */
- while ((ch = getopt(argc, argv, "1rn:o:")) != -1)
+ while ((ch = getopt(argc, argv, "1crn:o:")) != -1)
switch (ch) {
case '1':
iterate = 1;
break;
+ case 'c':
+ tostring = uuid_to_compact_string;
+ break;
case 'r':
version = 4;
break;
@@ -162,7 +191,7 @@
uuid = store;
while (count--) {
- uuid_to_string(uuid++, &p, &status);
+ tostring(uuid++, &p, &status);
if (status != uuid_s_ok)
err(1, "cannot stringify a UUID");
fprintf(fp, "%s\n", p);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 16, 9:36 PM (21 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15829410
Default Alt Text
D38820.diff (2 KB)
Attached To
Mode
D38820: uuidgen: add -c for compact uuid
Attached
Detach File
Event Timeline
Log In to Comment