Add usage() and rcsid. Remove unused #include. -Wall.

This commit is contained in:
Philippe Charnier 1998-05-05 06:13:47 +00:00
parent 14a28dc644
commit d4eaae7abd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=35733
2 changed files with 27 additions and 19 deletions

View File

@ -47,7 +47,7 @@
.Op Ar template ... .Op Ar template ...
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm mktemp .Nm
utility takes each of the given file name templates and overwrites a 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 portion of it to create a file name. This file name is unique
and suitable for use by the application. The template may be and suitable for use by the application. The template may be
@ -113,8 +113,8 @@ reasons it is suggested that
.Nm .Nm
be used instead. be used instead.
.Sh OPTIONS .Sh OPTIONS
.Bl -tag -width indent
The available options are as follows: The available options are as follows:
.Bl -tag -width indent
.It Fl d .It Fl d
Make a directory instead of a file. Make a directory instead of a file.
.It Fl q .It Fl q
@ -132,7 +132,7 @@ Operate in
mode. The temp file will be unlinked before mode. The temp file will be unlinked before
.Nm .Nm
exits. This is slightly better than exits. This is slightly better than
.Fn mktemp 3 .Xr mktemp 3
but still introduces a race condition. Use of this but still introduces a race condition. Use of this
option is not encouraged. option is not encouraged.
.El .El
@ -178,5 +178,6 @@ A
utility appeared in utility appeared in
.Ox 2.1 . .Ox 2.1 .
This implementation has been written independently based on the man page. 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. .\" Our stupid .Ox macro won't allow me to use .Ox alone.

View File

@ -23,7 +23,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $FreeBSD$
*/ */
/* /*
@ -35,27 +34,31 @@
* more like the OpenBSD version - which was first to publish the interface. * more like the OpenBSD version - which was first to publish the interface.
*/ */
#include <sys/types.h> #include <err.h>
#include <paths.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <paths.h>
#include <err.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
static void usage __P((void));
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int c, fd, ret; int c, fd, ret;
char *usage = "[-d] [-q] [-t prefix] [-u] [template ...]";
char *tmpdir, *prefix; char *tmpdir, *prefix;
char *prog;
char *name; char *name;
int dflag, qflag, tflag, uflag; int dflag, qflag, tflag, uflag;
ret = dflag = qflag = tflag = uflag = 0; ret = dflag = qflag = tflag = uflag = 0;
prefix = "mktemp";
name = NULL; name = NULL;
prog = argv[0]; /* XXX basename(argv[0]) */
while ((c = getopt(argc, argv, "dqt:u")) != -1) while ((c = getopt(argc, argv, "dqt:u")) != -1)
switch (c) { switch (c) {
@ -77,8 +80,7 @@ main(int argc, char **argv)
break; break;
default: default:
fprintf(stderr, "Usage: %s %s\n", prog, usage); usage();
return (1);
} }
argc -= optind; argc -= optind;
@ -86,8 +88,6 @@ main(int argc, char **argv)
if (tflag) { if (tflag) {
tmpdir = getenv("TMPDIR"); tmpdir = getenv("TMPDIR");
if (prefix == NULL)
prefix = "mktemp"; /* shouldn't happen, but.. */
if (tmpdir == NULL) if (tmpdir == NULL)
asprintf(&name, "%s%s.XXXXXXXX", _PATH_TMP, prefix); asprintf(&name, "%s%s.XXXXXXXX", _PATH_TMP, prefix);
else else
@ -97,11 +97,10 @@ main(int argc, char **argv)
if (qflag) if (qflag)
return (1); return (1);
else else
err(1, "cannot generate template"); errx(1, "cannot generate template");
} }
} else if (argc < 1) { } else if (argc < 1) {
fprintf(stderr, "Usage: %s %s\n", prog, usage); usage();
return (1);
} }
/* generate all requested files */ /* generate all requested files */
@ -141,3 +140,11 @@ main(int argc, char **argv)
} }
return (ret); return (ret);
} }
static void
usage()
{
fprintf(stderr,
"usage: mktemp [-d] [-q] [-t prefix] [-u] [template ...]\n");
exit (1);
}