diff options
author | Denys Vlasenko | 2022-05-01 01:58:57 +0200 |
---|---|---|
committer | Denys Vlasenko | 2022-05-01 01:58:57 +0200 |
commit | fb4546c7af3d1d2f11fb7851b56104f5580f328f (patch) | |
tree | 7e8491e1354f00dee8bb3a19b153d2adfa66d295 /util-linux | |
parent | d5bd2e57a7be6c34393c52aa5e7ac2a8937da8d3 (diff) | |
download | busybox-fb4546c7af3d1d2f11fb7851b56104f5580f328f.zip busybox-fb4546c7af3d1d2f11fb7851b56104f5580f328f.tar.gz |
seedrng: code shrink
function old new delta
seedrng_main 994 982 -12
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/seedrng.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index c07bf84..3074e9a 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c @@ -164,25 +164,27 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) { const char *seed_dir; int fd, dfd; + int i; + unsigned opts; uint8_t new_seed[MAX_SEED_LEN]; size_t new_seed_len; - bool new_seed_creditable, skip_credit; + bool new_seed_creditable; struct timespec timestamp; sha256_ctx_t hash; enum { - OPT_d = (1 << 0), - OPT_n = (1 << 1) + OPT_n = (1 << 0), /* must be 1 */ + OPT_d = (1 << 1), }; #if ENABLE_LONG_OPTS static const char longopts[] ALIGN1 = - "seed-dir\0" Required_argument "d" "skip-credit\0" No_argument "n" + "seed-dir\0" Required_argument "d" ; #endif seed_dir = DEFAULT_SEED_DIR; - skip_credit = getopt32long(argv, "d:n", longopts, &seed_dir) & OPT_n; + opts = getopt32long(argv, "nd:", longopts, &seed_dir); umask(0077); if (getuid() != 0) bb_simple_error_msg_and_die(bb_msg_you_must_be_root); @@ -209,10 +211,10 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) clock_gettime(CLOCK_BOOTTIME, ×tamp); sha256_hash(&hash, ×tamp, sizeof(timestamp)); - for (int i = 1; i < 3; ++i) { - seed_from_file_if_exists(i == 1 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME, + for (i = 0; i <= 1; i++) { + seed_from_file_if_exists(i == 0 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME, dfd, - /* credit? */ i == 1 ? false : !skip_credit, + /* credit? */ (opts ^ OPT_n) & i, /* 0, then 1 unless -n */ &hash); } |