Add usage() and rcsid. Remove unused #include. -Wall.
This commit is contained in:
parent
18a4860185
commit
953cc90b5d
@ -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.
|
||||
|
@ -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 <sys/types.h>
|
||||
#include <err.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <paths.h>
|
||||
#include <err.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user