git: cfc57d7dbe5b - main - mktemp: add some GNU-compatible long options
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 31 Oct 2022 03:56:02 UTC
The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=cfc57d7dbe5bff175ef6d508fecd6779c0a0d656 commit cfc57d7dbe5bff175ef6d508fecd6779c0a0d656 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2022-10-31 03:55:46 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2022-10-31 03:55:46 +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. Differential Revision: https://reviews.freebsd.org/D37120 --- 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 754cc8da7e4e..9240197e9129 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++;