From 810a5d762ec2f1bdce027ec79177062cfda53f4f Mon Sep 17 00:00:00 2001 From: charnier Date: Tue, 5 May 1998 06:13:47 +0000 Subject: [PATCH] Add usage() and rcsid. Remove unused #include. -Wall. --- usr.bin/mktemp/mktemp.1 | 9 +++++---- usr.bin/mktemp/mktemp.c | 37 ++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/usr.bin/mktemp/mktemp.1 b/usr.bin/mktemp/mktemp.1 index 0ea4ebfb394..10976943728 100644 --- a/usr.bin/mktemp/mktemp.1 +++ b/usr.bin/mktemp/mktemp.1 @@ -47,7 +47,7 @@ .Op Ar template ... .Sh DESCRIPTION The -.Nm mktemp +.Nm utility takes each of the given file name templates and overwrites a portion of it to create a file name. This file name is unique and suitable for use by the application. The template may be @@ -113,8 +113,8 @@ reasons it is suggested that .Nm be used instead. .Sh OPTIONS -.Bl -tag -width indent The available options are as follows: +.Bl -tag -width indent .It Fl d Make a directory instead of a file. .It Fl q @@ -132,7 +132,7 @@ Operate in mode. The temp file will be unlinked before .Nm exits. This is slightly better than -.Fn mktemp 3 +.Xr mktemp 3 but still introduces a race condition. Use of this option is not encouraged. .El @@ -178,5 +178,6 @@ A utility appeared in .Ox 2.1 . This implementation has been written independently based on the man page. -This man page is taken from OpenBSD. +This man page is taken from +.Bx Open . .\" Our stupid .Ox macro won't allow me to use .Ox alone. diff --git a/usr.bin/mktemp/mktemp.c b/usr.bin/mktemp/mktemp.c index 964fe972a16..381872d45ee 100644 --- a/usr.bin/mktemp/mktemp.c +++ b/usr.bin/mktemp/mktemp.c @@ -23,7 +23,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ */ /* @@ -35,27 +34,31 @@ * more like the OpenBSD version - which was first to publish the interface. */ -#include +#include +#include #include #include -#include -#include -#include #include +#include + +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif /* not lint */ + +static void usage __P((void)); int main(int argc, char **argv) { int c, fd, ret; - char *usage = "[-d] [-q] [-t prefix] [-u] [template ...]"; char *tmpdir, *prefix; - char *prog; char *name; int dflag, qflag, tflag, uflag; ret = dflag = qflag = tflag = uflag = 0; + prefix = "mktemp"; name = NULL; - prog = argv[0]; /* XXX basename(argv[0]) */ while ((c = getopt(argc, argv, "dqt:u")) != -1) switch (c) { @@ -77,8 +80,7 @@ main(int argc, char **argv) break; default: - fprintf(stderr, "Usage: %s %s\n", prog, usage); - return (1); + usage(); } argc -= optind; @@ -86,8 +88,6 @@ main(int argc, char **argv) if (tflag) { tmpdir = getenv("TMPDIR"); - if (prefix == NULL) - prefix = "mktemp"; /* shouldn't happen, but.. */ if (tmpdir == NULL) asprintf(&name, "%s%s.XXXXXXXX", _PATH_TMP, prefix); else @@ -97,11 +97,10 @@ main(int argc, char **argv) if (qflag) return (1); else - err(1, "cannot generate template"); + errx(1, "cannot generate template"); } } else if (argc < 1) { - fprintf(stderr, "Usage: %s %s\n", prog, usage); - return (1); + usage(); } /* generate all requested files */ @@ -141,3 +140,11 @@ main(int argc, char **argv) } return (ret); } + +static void +usage() +{ + fprintf(stderr, + "usage: mktemp [-d] [-q] [-t prefix] [-u] [template ...]\n"); + exit (1); +} -- 2.45.2