From nobody Mon Mar 06 21:18:36 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PVrzJ5WWrz3wPHY; Mon, 6 Mar 2023 21:18:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PVrzJ3p80z3BmM; Mon, 6 Mar 2023 21:18:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678137516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lGCVX0xQ+H4OQ54osRYPfStuXwm+00nRrC5TidCyXFs=; b=Az5AbDcgXyzp/kUz+SQJYj7SmpdcwxyPkOuMoMSXjdKehL0EEW7ioHM8rdnao1JBMAuDfo eXEt135RjjrxqjUy5Q2k0tAPcRbemMQd+6/cqXU8pMhxY6px/E3bqdkMJpbHf+NnWmE6fc Sm9MiQmu7iryM6NUosBNQILTASWG6+mHuzJOv4sfTvidIMP76uowiB6l/UlXhUHS5900x1 bz3Ab5o40qhPv0qaf8b0z49Wgn+ee+RY45ztjH3d1zZF6tC5uPu9g56vlsvvU98XLnij0Q EScBLH3D5FIltyD8+xHEs2JBnKEzRFA55aloqhBVPoBweP9bf2igbP6QKiEzoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678137516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lGCVX0xQ+H4OQ54osRYPfStuXwm+00nRrC5TidCyXFs=; b=VDO+SLVJNc7F6RFrc7VAvdFWZ72yEmTT8xIg5iwrQPHCGGWx8QhVPJrF5QdWvMlmCZsLdW dKrXo9uOtlUAL/7DICRI47Igzz+aKzDRaNSOAbJpnsG2gZbNhyvSDiA+giRMs959nytbXZ wv5whoac6Nb46uhh3l6me+498k0zOtcaAUDrbTw+P4+1sG0HMwVpmyoLJGt72Ez7YNef2n jPxUBJwLwOs8k2XI/qJyF52bXAVQ3CdGxG47lcj6M18asIDIVZm5h5paasLJOXE4AwsNei A6CAQAyfxJw5tQ0OPXS3Lc5jrWJ2C+UR1h9NrSIPIwyL+w1a8iHPd4+XowbruA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678137516; a=rsa-sha256; cv=none; b=Ijik1NDxYmJhPQv13jrJgEeovyKj4Q5B0SGi7KAdYYddE0aOW/VqQ/Xn/J/xWGF3dHYVhS DucCs9JqZPTVyR6ZDb5xiHx7f6SUKDwwCsaEuyJFpbE7cjiO4Y5cwGWHX9VC5aYkydllXf YskGN6l6rggY/ljS63TArh9Zf9/55fHogZ9dGuPCl+LHM44DS2HtjXa0DaQ5ULM8zxh7IB nNV09rjQsqvzt5+u14/wIo5ZOrFNrJj7WDi9SfjPyAJfsSQ+jG7dvo5eysAkBy5ywvooHS 2o8RVQUDQ0+LplMwdi8Eby+OItP/uP/Pn4+a+goDsF1g2f6RxAcM5dTcmKhVSg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PVrzJ2mRZzHlM; Mon, 6 Mar 2023 21:18:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 326LIaJA084967; Mon, 6 Mar 2023 21:18:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 326LIaD4084966; Mon, 6 Mar 2023 21:18:36 GMT (envelope-from git) Date: Mon, 6 Mar 2023 21:18:36 GMT Message-Id: <202303062118.326LIaD4084966@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: c4f59f056c1e - releng/13.2 - uuidgen: add -c for compact uuid List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.2 X-Git-Reftype: branch X-Git-Commit: c4f59f056c1e9adc64bcea3f5db56a2c33f39dcf Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.2 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=c4f59f056c1e9adc64bcea3f5db56a2c33f39dcf commit c4f59f056c1e9adc64bcea3f5db56a2c33f39dcf Author: Baptiste Daroussin AuthorDate: 2023-02-28 10:29:51 +0000 Commit: Baptiste Daroussin CommitDate: 2023-03-06 21:18:00 +0000 uuidgen: add -c for compact uuid It generates the uuid string but without the hyphen Approved by: re (cperciva) MFC After: 3 days Reviews by: tcberner Differential Revision: https://reviews.freebsd.org/D38820 (cherry picked from commit b2b294f27cf4618d6f7510007b41882860a080b9) (cherry picked from commit 0ba66872bea87abdf13660d5a7946769fd7b118f) (cherry picked from commit 4cd30c640db978355cf2da666e2749189babda5e) --- bin/uuidgen/uuidgen.1 | 5 ++++- bin/uuidgen/uuidgen.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/bin/uuidgen/uuidgen.1 b/bin/uuidgen/uuidgen.1 index 83326e3a189a..6d373cf3de41 100644 --- a/bin/uuidgen/uuidgen.1 +++ b/bin/uuidgen/uuidgen.1 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 23, 2012 +.Dd March 1, 2023 .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 @@ instructs 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 option controls 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 index 061907f57109..6dcfdde92a5f 100644 --- a/bin/uuidgen/uuidgen.c +++ b/bin/uuidgen/uuidgen.c @@ -46,6 +46,31 @@ usage(void) 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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);