summaryrefslogtreecommitdiffstats
path: root/apps/rand.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2015-09-04 12:49:06 +0200
committerRichard Levitte <levitte@openssl.org>2015-09-06 01:35:54 +0200
commitbdd58d98467e9f0f6635c1628e1eae304383afb1 (patch)
tree1927fc4a65f8fd8b5705c5c5e0278beabf2c2b28 /apps/rand.c
parentd303b9d85e1888494785f87ebd9bd233e63564a9 (diff)
Change the way apps open their input and output files
The different apps had the liberty to decide whether they would open their input and output files in binary mode or not, which could be confusing if two different apps were handling the same type of file in different ways. The solution is to centralise the decision of low level file organisation, and that the apps would use a selection of formats to state the intent of the file. Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'apps/rand.c')
-rw-r--r--apps/rand.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/apps/rand.c b/apps/rand.c
index a5aa5d9410..315e6be02f 100644
--- a/apps/rand.c
+++ b/apps/rand.c
@@ -87,7 +87,7 @@ int rand_main(int argc, char **argv)
BIO *out = NULL;
char *inrand = NULL, *outfile = NULL, *prog;
OPTION_CHOICE o;
- int base64 = 0, hex = 0, i, num = -1, r, ret = 1;
+ int format = FORMAT_BINARY, i, num = -1, r, ret = 1;
prog = opt_init(argc, argv, rand_options);
while ((o = opt_next()) != OPT_EOF) {
@@ -111,17 +111,17 @@ int rand_main(int argc, char **argv)
inrand = opt_arg();
break;
case OPT_BASE64:
- base64 = 1;
+ format = FORMAT_BASE64;
break;
case OPT_HEX:
- hex = 1;
+ format = FORMAT_TEXT;
break;
}
}
argc = opt_num_rest();
argv = opt_rest();
- if (argc != 1 || (hex && base64))
+ if (argc != 1)
goto opthelp;
if (sscanf(argv[0], "%d", &num) != 1 || num < 0)
goto opthelp;
@@ -134,11 +134,11 @@ int rand_main(int argc, char **argv)
BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
app_RAND_load_files(inrand));
- out = bio_open_default(outfile, base64 ? "w" : "wb");
+ out = bio_open_default(outfile, 'w', format);
if (out == NULL)
goto end;
- if (base64) {
+ if (format == FORMAT_BASE64) {
BIO *b64 = BIO_new(BIO_f_base64());
if (b64 == NULL)
goto end;
@@ -155,7 +155,7 @@ int rand_main(int argc, char **argv)
r = RAND_bytes(buf, chunk);
if (r <= 0)
goto end;
- if (!hex)
+ if (format != FORMAT_TEXT) /* hex */
BIO_write(out, buf, chunk);
else {
for (i = 0; i < chunk; i++)
@@ -163,7 +163,7 @@ int rand_main(int argc, char **argv)
}
num -= chunk;
}
- if (hex)
+ if (format == FORMAT_TEXT)
BIO_puts(out, "\n");
(void)BIO_flush(out);