Remove bcopy(), bzero(), bcmp()

bcopy() has a confusing argument order and is actually a move, not a
copy; they're all deprecated since POSIX.1-2001 and removed in -2008,
and we shim them out to mem*() on Linux anyway

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12996
This commit is contained in:
наб
2022-02-25 14:26:54 +01:00
committed by Brian Behlendorf
parent 1d77d62f5a
commit 861166b027
129 changed files with 990 additions and 1051 deletions
+14 -22
View File
@@ -766,7 +766,7 @@ eval_maps(uint64_t children, int passes, uint64_t *map_seed,
static int
draid_generate(int argc, char *argv[])
{
char filename[MAXPATHLEN];
char filename[MAXPATHLEN] = {0};
uint64_t map_seed;
int c, fd, error, verbose = 0, passes = 1, continuous = 0;
int min_children = VDEV_DRAID_MIN_CHILDREN;
@@ -824,10 +824,9 @@ draid_generate(int argc, char *argv[])
}
}
if (argc > optind) {
bzero(filename, MAXPATHLEN);
if (argc > optind)
strncpy(filename, argv[optind], MAXPATHLEN - 1);
} else {
else {
(void) fprintf(stderr, "A FILE must be specified.\n");
return (1);
}
@@ -926,7 +925,7 @@ restart:
static int
draid_verify(int argc, char *argv[])
{
char filename[MAXPATHLEN];
char filename[MAXPATHLEN] = {0};
int n = 0, c, error, verbose = 1;
int check_ratios = 0;
@@ -956,7 +955,6 @@ draid_verify(int argc, char *argv[])
if (abspath == NULL)
return (ENOMEM);
bzero(filename, MAXPATHLEN);
if (realpath(argv[optind], abspath) != NULL)
strncpy(filename, abspath, MAXPATHLEN - 1);
else
@@ -980,9 +978,8 @@ draid_verify(int argc, char *argv[])
children <= VDEV_DRAID_MAX_CHILDREN;
children++) {
draid_map_t *map;
char key[8];
char key[8] = {0};
bzero(key, 8);
snprintf(key, 8, "%llu", (u_longlong_t)children);
error = alloc_fixed_map(children, &map);
@@ -1126,7 +1123,7 @@ draid_verify(int argc, char *argv[])
static int
draid_dump(int argc, char *argv[])
{
char filename[MAXPATHLEN];
char filename[MAXPATHLEN] = {0};
int c, error, verbose = 1;
int min_children = VDEV_DRAID_MIN_CHILDREN;
int max_children = VDEV_DRAID_MAX_CHILDREN;
@@ -1167,10 +1164,9 @@ draid_dump(int argc, char *argv[])
}
}
if (argc > optind) {
bzero(filename, MAXPATHLEN);
if (argc > optind)
strncpy(filename, argv[optind], MAXPATHLEN - 1);
} else {
else {
(void) fprintf(stderr, "A FILE must be specified.\n");
return (1);
}
@@ -1202,13 +1198,12 @@ draid_dump(int argc, char *argv[])
static int
draid_table(int argc, char *argv[])
{
char filename[MAXPATHLEN];
char filename[MAXPATHLEN] = {0};
int error;
if (argc > optind) {
bzero(filename, MAXPATHLEN);
if (argc > optind)
strncpy(filename, argv[optind], MAXPATHLEN - 1);
} else {
else {
(void) fprintf(stderr, "A FILE must be specified.\n");
return (1);
}
@@ -1221,9 +1216,8 @@ draid_table(int argc, char *argv[])
children++) {
uint64_t seed, checksum, nperms, avg_ratio;
nvlist_t *cfg;
char key[8];
char key[8] = {0};
bzero(key, 8);
snprintf(key, 8, "%llu", (u_longlong_t)children);
error = read_map_key(filename, key, &cfg);
@@ -1317,7 +1311,7 @@ draid_merge_impl(nvlist_t *allcfgs, const char *srcfilename, int *mergedp)
static int
draid_merge(int argc, char *argv[])
{
char filename[MAXPATHLEN];
char filename[MAXPATHLEN] = {0};
int c, error, total_merged = 0, verbose = 0;
nvlist_t *allcfgs;
@@ -1345,7 +1339,6 @@ draid_merge(int argc, char *argv[])
return (1);
}
bzero(filename, MAXPATHLEN);
strncpy(filename, argv[optind], MAXPATHLEN - 1);
optind++;
@@ -1358,10 +1351,9 @@ draid_merge(int argc, char *argv[])
}
while (optind < argc) {
char srcfilename[MAXPATHLEN];
char srcfilename[MAXPATHLEN] = {0};
int merged = 0;
bzero(srcfilename, MAXPATHLEN);
strncpy(srcfilename, argv[optind], MAXPATHLEN - 1);
error = draid_merge_impl(allcfgs, srcfilename, &merged);
@@ -13,12 +13,6 @@
* Copyright (c) 2017 by Delphix. All rights reserved.
*/
/*
* The following is defined so the source can use
* lrand48() and srand48().
*/
#define __EXTENSIONS__
#include <stdint.h>
#include <string.h>
#include "../file_common.h"
@@ -27,7 +21,7 @@
* The following sample was derived from real-world data
* of a production Oracle database.
*/
static uint64_t size_distribution[] = {
static const uint64_t size_distribution[] = {
0,
1499018,
352084,
@@ -87,11 +81,11 @@ fillbuf(char *buf)
break;
}
bcopy(randbuf, buf, BLOCKSZ);
memcpy(buf, randbuf, BLOCKSZ);
if (i == 0)
bzero(buf, BLOCKSZ - 10);
memset(buf, 0, BLOCKSZ - 10);
else if (i < 16)
bzero(buf, BLOCKSZ - i * 512 + 256);
memset(buf, 0, BLOCKSZ - i * 512 + 256);
/*LINTED: E_BAD_PTR_CAST_ALIGN*/
((uint32_t *)buf)[0] = lrand48();
}
@@ -99,8 +93,7 @@ fillbuf(char *buf)
static void
exit_usage(void)
{
(void) printf("usage: ");
(void) printf("randwritecomp <file> [-s] [nwrites]\n");
(void) puts("usage: randwritecomp [-s] file [nwrites]");
exit(EXIT_FAILURE);
}
@@ -160,7 +160,7 @@ main(int argc, char *argv[])
EdonRFinal(&ctx, digest); \
(void) printf("Edon-R-%-6sMessage: " #_m \
"\tResult: ", #mode); \
if (bcmp(digest, testdigest, mode / 8) == 0) { \
if (memcmp(digest, testdigest, mode / 8) == 0) { \
(void) printf("OK\n"); \
} else { \
(void) printf("FAILED!\n"); \
@@ -177,7 +177,7 @@ main(int argc, char *argv[])
double cpb = 0; \
int i; \
struct timeval start, end; \
bzero(block, sizeof (block)); \
memset(block, 0, sizeof (block)); \
(void) gettimeofday(&start, NULL); \
EdonRInit(&ctx, mode); \
for (i = 0; i < 8192; i++) \
@@ -189,7 +189,7 @@ main(int argc, char *argv[])
SHA2Final(digest, &ctx); \
(void) printf("SHA%-9sMessage: " #_m \
"\tResult: ", #mode); \
if (bcmp(digest, testdigest, diglen / 8) == 0) { \
if (memcmp(digest, testdigest, diglen / 8) == 0) { \
(void) printf("OK\n"); \
} else { \
(void) printf("FAILED!\n"); \
@@ -206,7 +206,7 @@ main(int argc, char *argv[])
double cpb = 0; \
int i; \
struct timeval start, end; \
bzero(block, sizeof (block)); \
memset(block, 0, sizeof (block)); \
(void) gettimeofday(&start, NULL); \
SHA2Init(SHA ## mode ## _MECH_INFO_TYPE, &ctx); \
for (i = 0; i < 8192; i++) \
@@ -278,7 +278,7 @@ main(int argc, char *argv[])
(void) Skein ## mode ## _Final(&ctx, digest); \
(void) printf("Skein" #mode "/" #diglen \
"\tMessage: " #_m "\tResult: "); \
if (bcmp(digest, testdigest, diglen / 8) == 0) { \
if (memcmp(digest, testdigest, diglen / 8) == 0) { \
(void) printf("OK\n"); \
} else { \
(void) printf("FAILED!\n"); \
@@ -295,7 +295,7 @@ main(int argc, char *argv[])
double cpb = 0; \
int i; \
struct timeval start, end; \
bzero(block, sizeof (block)); \
memset(block, 0, sizeof (block)); \
(void) gettimeofday(&start, NULL); \
(void) Skein ## mode ## _Init(&ctx, diglen); \
for (i = 0; i < 8192; i++) { \
@@ -174,12 +174,9 @@ static hkdf_tv_t test_vectors[] = {
static void
hexdump(char *str, uint8_t *src, uint_t len)
{
int i;
printf("\t%s\t", str);
for (i = 0; i < len; i++) {
printf("%02x", src[i] & 0xff);
}
for (int i = 0; i < len; i++)
printf("%02hhx", src[i]);
printf("\n");
}
@@ -187,21 +184,21 @@ static int
run_test(int i, hkdf_tv_t *tv)
{
int ret;
uint8_t okey[SHA512_DIGEST_LENGTH];
uint8_t good[SHA512_DIGEST_LENGTH];
printf("TEST %d:\t", i);
ret = hkdf_sha512((uint8_t *)tv->ikm, tv->ikm_len, (uint8_t *)tv->salt,
tv->salt_len, (uint8_t *)tv->info, tv->info_len, okey, tv->okm_len);
tv->salt_len, (uint8_t *)tv->info, tv->info_len, good, tv->okm_len);
if (ret != 0) {
printf("HKDF failed with error code %d\n", ret);
return (ret);
}
if (bcmp(okey, tv->okm, tv->okm_len) != 0) {
if (memcmp(good, tv->okm, tv->okm_len) != 0) {
printf("Output Mismatch\n");
hexdump("Expected:", (uint8_t *)tv->okm, tv->okm_len);
hexdump("Actual: ", okey, tv->okm_len);
hexdump("Actual: ", good, tv->okm_len);
return (1);
}