clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -43,68 +43,51 @@
static char databuf[DATA_MAXSIZE];
static char readbuf[DATA_MAXSIZE];
static
void
prepdata(unsigned code, unsigned seq, char *buf, off_t len)
{
char smallbuf[32];
char letter;
size_t slen;
static void prepdata(unsigned code, unsigned seq, char *buf, off_t len) {
char smallbuf[32];
char letter;
size_t slen;
snprintf(smallbuf, sizeof(smallbuf), "%u@%u\n", seq, code);
slen = strlen(smallbuf);
snprintf(smallbuf, sizeof(smallbuf), "%u@%u\n", seq, code);
slen = strlen(smallbuf);
while (len >= slen) {
memcpy(buf, smallbuf, slen);
buf += slen;
len -= slen;
}
if (len > 1) {
letter = 'A' + (code + seq) % 26;
memset(buf, letter, len - 1);
buf += len - 1;
}
if (len > 0) {
*buf = '\n';
}
while (len >= slen) {
memcpy(buf, smallbuf, slen);
buf += slen;
len -= slen;
}
if (len > 1) {
letter = 'A' + (code + seq) % 26;
memset(buf, letter, len - 1);
buf += len - 1;
}
if (len > 0) {
*buf = '\n';
}
}
static
int
matches_at(size_t start, size_t len)
{
if (!memcmp(databuf + start, readbuf + start, len)) {
return 1;
}
return 0;
static int matches_at(size_t start, size_t len) {
if (!memcmp(databuf + start, readbuf + start, len)) {
return 1;
}
return 0;
}
static
int
byte_at(size_t start, size_t len, unsigned char val)
{
size_t i;
static int byte_at(size_t start, size_t len, unsigned char val) {
size_t i;
for (i=0; i<len; i++) {
if ((unsigned char)readbuf[start + i] != val) {
return 0;
}
}
return 1;
for (i = 0; i < len; i++) {
if ((unsigned char)readbuf[start + i] != val) {
return 0;
}
}
return 1;
}
static
int
zero_at(size_t start, size_t len)
{
return byte_at(start, len, 0);
}
static int zero_at(size_t start, size_t len) { return byte_at(start, len, 0); }
static
int
poison_at(size_t start, size_t len)
{
return byte_at(start, len, POISON_VAL);
static int poison_at(size_t start, size_t len) {
return byte_at(start, len, POISON_VAL);
}
/*
@@ -119,109 +102,93 @@ poison_at(size_t start, size_t len)
* CHECKSTART is the offset into the write region where we begin checking.
* CHECKLEN is the length of the region we check.
*/
int
data_matches(const char *namestr, off_t regionoffset,
unsigned code, unsigned seq, off_t zerostart, off_t len,
off_t checkstart, off_t checklen)
{
int ret;
off_t where;
size_t howmuch;
off_t absend, slop;
int data_matches(const char *namestr, off_t regionoffset, unsigned code,
unsigned seq, off_t zerostart, off_t len, off_t checkstart,
off_t checklen) {
int ret;
off_t where;
size_t howmuch;
off_t absend, slop;
assert(len <= DATA_MAXSIZE);
assert(checklen > 0);
assert(checklen <= len);
assert(checkstart >= 0 && checkstart < len);
assert(checkstart + checklen <= len);
assert(zerostart >= 0);
assert(zerostart <= len);
assert(len <= DATA_MAXSIZE);
assert(checklen > 0);
assert(checklen <= len);
assert(checkstart >= 0 && checkstart < len);
assert(checkstart + checklen <= len);
assert(zerostart >= 0);
assert(zerostart <= len);
prepdata(code, seq, databuf, len);
prepdata(code, seq, databuf, len);
ret = 1;
while (checklen > 0) {
/* check one block at a time */
where = checkstart;
howmuch = BLOCKSIZE;
/* no more than is left to do */
if (howmuch > checklen) {
howmuch = checklen;
}
/* if we stick over a block boundary, stop there */
absend = regionoffset + where + howmuch;
slop = absend % BLOCKSIZE;
if (slop != 0 && slop < howmuch) {
howmuch -= slop;
}
/* if we go past the zerostart point, stop there */
if (where < zerostart && where + howmuch > zerostart) {
howmuch = zerostart - where;
}
assert(howmuch > 0);
ret = 1;
while (checklen > 0) {
/* check one block at a time */
where = checkstart;
howmuch = BLOCKSIZE;
/* no more than is left to do */
if (howmuch > checklen) {
howmuch = checklen;
}
/* if we stick over a block boundary, stop there */
absend = regionoffset + where + howmuch;
slop = absend % BLOCKSIZE;
if (slop != 0 && slop < howmuch) {
howmuch -= slop;
}
/* if we go past the zerostart point, stop there */
if (where < zerostart && where + howmuch > zerostart) {
howmuch = zerostart - where;
}
assert(howmuch > 0);
if (matches_at(where, howmuch)) {
/* nothing */
}
else if (zero_at(where, howmuch)) {
if (where >= zerostart) {
printf("WARNING: file %s range %lld-%lld is "
"zeroed\n",
namestr, regionoffset + where,
regionoffset + where + howmuch);
}
else {
ret = 0;
}
}
else if (poison_at(where, howmuch)) {
if (where >= zerostart) {
printf("ERROR: file %s range %lld-%lld is "
"poisoned\n",
namestr, regionoffset + where,
regionoffset + where + howmuch);
}
else {
ret = 0;
}
}
else {
ret = 0;
}
if (matches_at(where, howmuch)) {
/* nothing */
} else if (zero_at(where, howmuch)) {
if (where >= zerostart) {
printf("WARNING: file %s range %lld-%lld is "
"zeroed\n",
namestr, regionoffset + where, regionoffset + where + howmuch);
} else {
ret = 0;
}
} else if (poison_at(where, howmuch)) {
if (where >= zerostart) {
printf("ERROR: file %s range %lld-%lld is "
"poisoned\n",
namestr, regionoffset + where, regionoffset + where + howmuch);
} else {
ret = 0;
}
} else {
ret = 0;
}
checkstart += howmuch;
checklen -= howmuch;
}
return ret;
checkstart += howmuch;
checklen -= howmuch;
}
return ret;
}
void
data_check(const char *namestr, off_t regionoffset,
unsigned code, unsigned seq, off_t zerostart, off_t len,
off_t checkstart, off_t checklen)
{
assert(zerostart >= 0);
assert(zerostart <= len);
void data_check(const char *namestr, off_t regionoffset, unsigned code,
unsigned seq, off_t zerostart, off_t len, off_t checkstart,
off_t checklen) {
assert(zerostart >= 0);
assert(zerostart <= len);
if (!data_matches(namestr, regionoffset,
code, seq, zerostart, len, checkstart, checklen)) {
printf("ERROR: file %s range %lld-%lld contains garbage\n",
namestr, regionoffset + checkstart,
regionoffset + checkstart + checklen);
}
if (!data_matches(namestr, regionoffset, code, seq, zerostart, len,
checkstart, checklen)) {
printf("ERROR: file %s range %lld-%lld contains garbage\n", namestr,
regionoffset + checkstart, regionoffset + checkstart + checklen);
}
}
void *
data_map(unsigned code, unsigned seq, off_t len)
{
assert(len <= DATA_MAXSIZE);
prepdata(code, seq, databuf, len);
return databuf;
void *data_map(unsigned code, unsigned seq, off_t len) {
assert(len <= DATA_MAXSIZE);
prepdata(code, seq, databuf, len);
return databuf;
}
void *
data_mapreadbuf(off_t len)
{
assert(len <= DATA_MAXSIZE);
return readbuf;
void *data_mapreadbuf(off_t len) {
assert(len <= DATA_MAXSIZE);
return readbuf;
}