git: 53310486d884 - stable/13 - mktemp: add some GNU-compatible long options

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sun, 13 Nov 2022 05:38:06 UTC
The branch stable/13 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=53310486d884157e13ad77e72d42511a2a005f37

commit 53310486d884157e13ad77e72d42511a2a005f37
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2022-10-31 03:55:46 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2022-11-13 05:37:06 +0000

    mktemp: add some GNU-compatible long options
    
    GNU maketemp has long options for -d, -q, and -u, so let's add these
    now for compatibility.
    
    Reviewed by:    emaste, imp, wosch
    Sponsored by:   Klara, Inc.
    
    (cherry picked from commit cfc57d7dbe5bff175ef6d508fecd6779c0a0d656)
---
 usr.bin/mktemp/mktemp.1 |  8 ++++----
 usr.bin/mktemp/mktemp.c | 10 +++++++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/usr.bin/mktemp/mktemp.1 b/usr.bin/mktemp/mktemp.1
index c8d7f6232632..469d4f6097d0 100644
--- a/usr.bin/mktemp/mktemp.1
+++ b/usr.bin/mktemp/mktemp.1
@@ -28,7 +28,7 @@
 .\" From: $OpenBSD: mktemp.1,v 1.8 1998/03/19 06:13:37 millert Exp $
 .\" $FreeBSD$
 .\"
-.Dd December 30, 2005
+.Dd August 4, 2022
 .Dt MKTEMP 1
 .Os
 .Sh NAME
@@ -132,9 +132,9 @@ be used instead.
 .Sh OPTIONS
 The available options are as follows:
 .Bl -tag -width indent
-.It Fl d
+.It Fl d , Fl -directory
 Make a directory instead of a file.
-.It Fl q
+.It Fl q , Fl -quiet
 Fail silently if an error occurs.
 This is useful if
 a script does not want error output to go to standard error.
@@ -144,7 +144,7 @@ Generate a template (using the supplied
 and
 .Ev TMPDIR
 if set) to create a filename template.
-.It Fl u
+.It Fl u , Fl -dry-run
 Operate in
 .Dq unsafe
 mode.
diff --git a/usr.bin/mktemp/mktemp.c b/usr.bin/mktemp/mktemp.c
index 0b320e8c5c85..dc92de2961d0 100644
--- a/usr.bin/mktemp/mktemp.c
+++ b/usr.bin/mktemp/mktemp.c
@@ -37,6 +37,7 @@
  */
 
 #include <err.h>
+#include <getopt.h>
 #include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -50,6 +51,13 @@ static const char rcsid[] =
 
 static void usage(void);
 
+static const struct option long_opts[] = {
+	{"directory",	no_argument,	NULL,	'd'},
+	{"quiet",	no_argument,	NULL,	'q'},
+	{"dry-run",	no_argument,	NULL,	'u'},
+	{NULL,		no_argument,	NULL,	0},
+};
+
 int
 main(int argc, char **argv)
 {
@@ -63,7 +71,7 @@ main(int argc, char **argv)
 	prefix = "mktemp";
 	name = NULL;
 
-	while ((c = getopt(argc, argv, "dqt:u")) != -1)
+	while ((c = getopt_long(argc, argv, "dqt:u", long_opts, NULL)) != -1)
 		switch (c) {
 		case 'd':
 			dflag++;