Add an -o filename option to have the output written to a file.
This option is present on most uuidgen(1) implementations even though normal file redirection can be used to achieve the same. Submitted by: Hiten Pandya <hiten@unixdaemons.com>
This commit is contained in:
parent
7467400839
commit
349ca981e1
@ -34,14 +34,15 @@
|
||||
.Nm
|
||||
.Op Fl 1
|
||||
.Op Fl n Ar count
|
||||
.Op Fl o Ar filename
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility by default generates a single universally unique identifier (UUID),
|
||||
also known as a globally unique identifier (GUID).
|
||||
The UUID is written to stdout.
|
||||
The following options can be used to change the number of identifiers
|
||||
and the method used:
|
||||
The UUID is written to stdout by default.
|
||||
The following options can be used to change the behaviour of
|
||||
.Nm :
|
||||
.Bl -tag -width indent
|
||||
.It Fl 1
|
||||
This option only has effect if multiple identifiers are to be generated and
|
||||
@ -52,6 +53,10 @@ to not generate them in batch, but one at a time.
|
||||
This option controls the number of identifiers generated.
|
||||
By default, multiple
|
||||
identifiers are generated in batch.
|
||||
.It Fl o
|
||||
Redirect output to
|
||||
.Ar filename
|
||||
instead of stdout.
|
||||
.El
|
||||
.Pp
|
||||
Batched generation yields a dense set of identifiers in such a way that there
|
||||
|
@ -37,20 +37,22 @@ __FBSDID("$FreeBSD$");
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "usage: uuidgen [-1] [-n count]\n");
|
||||
(void)fprintf(stderr, "usage: uuidgen [-1] [-n count] [-o filename]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fp;
|
||||
uuid_t *store, *uuid;
|
||||
char *p;
|
||||
int ch, count, i, iterate;
|
||||
|
||||
count = -1; /* no count yet */
|
||||
fp = stdout; /* default output file */
|
||||
iterate = 0; /* not one at a time */
|
||||
while ((ch = getopt(argc, argv, "1n:")) != -1)
|
||||
while ((ch = getopt(argc, argv, "1n:o:")) != -1)
|
||||
switch (ch) {
|
||||
case '1':
|
||||
iterate = 1;
|
||||
@ -62,6 +64,13 @@ main(int argc, char *argv[])
|
||||
if (*p != 0 || count < 1)
|
||||
usage();
|
||||
break;
|
||||
case 'o':
|
||||
if (fp != stdout)
|
||||
errx(1, "multiple output files not allowed");
|
||||
fp = fopen(optarg, "w");
|
||||
if (fp == NULL)
|
||||
err(1, "fopen");
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
@ -93,10 +102,12 @@ main(int argc, char *argv[])
|
||||
uuid = store;
|
||||
while (count--) {
|
||||
uuid_to_string(uuid++, &p, NULL);
|
||||
printf("%s\n", p);
|
||||
fprintf(fp, "%s\n", p);
|
||||
free(p);
|
||||
}
|
||||
|
||||
free(store);
|
||||
if (fp != stdout)
|
||||
fclose(fp);
|
||||
return (0);
|
||||
}
|
||||
|
@ -34,14 +34,15 @@
|
||||
.Nm
|
||||
.Op Fl 1
|
||||
.Op Fl n Ar count
|
||||
.Op Fl o Ar filename
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility by default generates a single universally unique identifier (UUID),
|
||||
also known as a globally unique identifier (GUID).
|
||||
The UUID is written to stdout.
|
||||
The following options can be used to change the number of identifiers
|
||||
and the method used:
|
||||
The UUID is written to stdout by default.
|
||||
The following options can be used to change the behaviour of
|
||||
.Nm :
|
||||
.Bl -tag -width indent
|
||||
.It Fl 1
|
||||
This option only has effect if multiple identifiers are to be generated and
|
||||
@ -52,6 +53,10 @@ to not generate them in batch, but one at a time.
|
||||
This option controls the number of identifiers generated.
|
||||
By default, multiple
|
||||
identifiers are generated in batch.
|
||||
.It Fl o
|
||||
Redirect output to
|
||||
.Ar filename
|
||||
instead of stdout.
|
||||
.El
|
||||
.Pp
|
||||
Batched generation yields a dense set of identifiers in such a way that there
|
||||
|
@ -37,20 +37,22 @@ __FBSDID("$FreeBSD$");
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "usage: uuidgen [-1] [-n count]\n");
|
||||
(void)fprintf(stderr, "usage: uuidgen [-1] [-n count] [-o filename]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fp;
|
||||
uuid_t *store, *uuid;
|
||||
char *p;
|
||||
int ch, count, i, iterate;
|
||||
|
||||
count = -1; /* no count yet */
|
||||
fp = stdout; /* default output file */
|
||||
iterate = 0; /* not one at a time */
|
||||
while ((ch = getopt(argc, argv, "1n:")) != -1)
|
||||
while ((ch = getopt(argc, argv, "1n:o:")) != -1)
|
||||
switch (ch) {
|
||||
case '1':
|
||||
iterate = 1;
|
||||
@ -62,6 +64,13 @@ main(int argc, char *argv[])
|
||||
if (*p != 0 || count < 1)
|
||||
usage();
|
||||
break;
|
||||
case 'o':
|
||||
if (fp != stdout)
|
||||
errx(1, "multiple output files not allowed");
|
||||
fp = fopen(optarg, "w");
|
||||
if (fp == NULL)
|
||||
err(1, "fopen");
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
@ -93,10 +102,12 @@ main(int argc, char *argv[])
|
||||
uuid = store;
|
||||
while (count--) {
|
||||
uuid_to_string(uuid++, &p, NULL);
|
||||
printf("%s\n", p);
|
||||
fprintf(fp, "%s\n", p);
|
||||
free(p);
|
||||
}
|
||||
|
||||
free(store);
|
||||
if (fp != stdout)
|
||||
fclose(fp);
|
||||
return (0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user