From fb4f617201be5ffa847f92058c2551cf63405d4f Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Fri, 25 Feb 2011 09:40:17 +0000 Subject: [PATCH] Fix a bunch of trivial whitespace mistakes and update the miniobj.h file before the real work starts. --- .../fifolog/fifolog_create/fifolog_create.c | 4 ++-- .../fifolog/fifolog_reader/fifolog_reader.c | 2 +- .../fifolog/fifolog_writer/fifolog_writer.c | 2 +- usr.sbin/fifolog/lib/fifolog.h | 8 ++++---- usr.sbin/fifolog/lib/fifolog_create.c | 2 +- usr.sbin/fifolog/lib/fifolog_int.c | 4 ++-- usr.sbin/fifolog/lib/fifolog_reader.c | 10 +++++----- usr.sbin/fifolog/lib/fifolog_write_poll.c | 18 +++++++++--------- usr.sbin/fifolog/lib/miniobj.h | 18 +++++++++++++----- 9 files changed, 38 insertions(+), 30 deletions(-) diff --git a/usr.sbin/fifolog/fifolog_create/fifolog_create.c b/usr.sbin/fifolog/fifolog_create/fifolog_create.c index 5e91db1276bd..470c64cf97ad 100644 --- a/usr.sbin/fifolog/fifolog_create/fifolog_create.c +++ b/usr.sbin/fifolog/fifolog_create/fifolog_create.c @@ -78,11 +78,11 @@ main(int argc, char * const *argv) } argc -= optind; argv += optind; - if (argc != 1) + if (argc != 1) usage(); if (size != 0 && reccnt != 0 && recsize != 0) { /* N N N */ - if (size != reccnt * recsize) + if (size != reccnt * recsize) errx(1, "Inconsistent -l, -r and -s values"); } else if (size != 0 && reccnt != 0 && recsize == 0) { /* N N Z */ if (size % reccnt) diff --git a/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c b/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c index 7178082a8702..73fc50dd9fac 100644 --- a/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c +++ b/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c @@ -156,7 +156,7 @@ main(int argc, char * const *argv) errx(1, "Begin time not before End time"); fl = fifolog_reader_open(argv[0]); - + if (!strcmp(opt_o, "-")) fo = stdout; else { diff --git a/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c b/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c index 346297faa069..5c6aa6857f2a 100644 --- a/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c +++ b/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c @@ -76,7 +76,7 @@ main(int argc, char * const *argv) } argc -= optind; argv += optind; - if (argc != 1) + if (argc != 1) usage(); if (z_opt > 9) diff --git a/usr.sbin/fifolog/lib/fifolog.h b/usr.sbin/fifolog/lib/fifolog.h index 14374ace9818..0575a46e73fb 100644 --- a/usr.sbin/fifolog/lib/fifolog.h +++ b/usr.sbin/fifolog/lib/fifolog.h @@ -68,7 +68,7 @@ * present in these records as well: * 5 32be time_t containing POSIX's understanding of UTC. * - * These fields are immediately followed by the inner layer payload as + * These fields are immediately followed by the inner layer payload as * described below, which has variable length. * * If the inner layer payload is shorter than the available space in @@ -95,10 +95,10 @@ * * The inner layer: * ---------------- - * The inner layer contains data identification and to the second - * timestamping (the timestamp in the outer layer only marks the + * The inner layer contains data identification and to the second + * timestamping (the timestamp in the outer layer only marks the * first possible timestamp for content in the SYNC record). - * + * * offset type contents * -------------------------------------------------------------- * 0 32be ident diff --git a/usr.sbin/fifolog/lib/fifolog_create.c b/usr.sbin/fifolog/lib/fifolog_create.c index 68f8cef5f9d5..32f68866f67b 100644 --- a/usr.sbin/fifolog/lib/fifolog_create.c +++ b/usr.sbin/fifolog/lib/fifolog_create.c @@ -91,7 +91,7 @@ fifolog_create(const char *fn, off_t size, unsigned recsize) if (size == 0 && S_ISREG(st.st_mode)) size = st.st_size; - if (size == 0) + if (size == 0) size = recsize * (off_t)(24*60*60); if (S_ISREG(st.st_mode) && ftruncate(fd, size) < 0) diff --git a/usr.sbin/fifolog/lib/fifolog_int.c b/usr.sbin/fifolog/lib/fifolog_int.c index f87fd8204533..d16e1b77b469 100644 --- a/usr.sbin/fifolog/lib/fifolog_int.c +++ b/usr.sbin/fifolog/lib/fifolog_int.c @@ -66,7 +66,7 @@ fifo_zfree(voidpf opaque __unused, voidpf address) * Return value is NULL for success or a error description string to * be augmented by errno if non-zero. * - * The second function is just an error-handling wrapper around the + * The second function is just an error-handling wrapper around the * first which, does the actual work. */ @@ -88,7 +88,7 @@ fifolog_int_open_i(struct fifolog_file *f, const char *fname, int mode) if (i != 0) { i = fstat(f->fd, &st); - if (!S_ISREG(st.st_mode)) + if (!S_ISREG(st.st_mode)) return ("Neither disk nor regular file"); f->recsize = 512; f->logsize = st.st_size; diff --git a/usr.sbin/fifolog/lib/fifolog_reader.c b/usr.sbin/fifolog/lib/fifolog_reader.c index d7475ed7f799..5843a813d0e8 100644 --- a/usr.sbin/fifolog/lib/fifolog_reader.c +++ b/usr.sbin/fifolog/lib/fifolog_reader.c @@ -48,7 +48,7 @@ struct fifolog_reader { #define FIFOLOG_READER_MAGIC 0x1036d139 struct fifolog_file *ff; unsigned olen; - unsigned char *obuf; + unsigned char *obuf; time_t now; }; @@ -75,7 +75,7 @@ fifolog_reader_open(const char *fname) i = inflateInit(fr->ff->zs); assert(i == Z_OK); - fr->magic = FIFOLOG_READER_MAGIC; + fr->magic = FIFOLOG_READER_MAGIC; return (fr); } @@ -144,7 +144,7 @@ fifolog_reader_seek(const struct fifolog_reader *fr, time_t t0) e = fifolog_reader_findsync(fr->ff, &o); if (e == 0) return (0); /* empty fifolog */ - assert(e == 1); + assert(e == 1); assert(fr->ff->recbuf[4] & FIFOLOG_FLG_SYNC); seq = be32dec(fr->ff->recbuf); @@ -297,7 +297,7 @@ fifolog_reader_process(struct fifolog_reader *fr, off_t from, fifolog_reader_ren zs->avail_out, fr->olen); exit (250); #else - + i = Z_OK; #endif } @@ -312,7 +312,7 @@ fifolog_reader_process(struct fifolog_reader *fr, off_t from, fifolog_reader_ren if (zs->avail_out != fr->olen) { q = fr->obuf + (fr->olen - zs->avail_out); p = fifolog_reader_chop(fr, func, priv); - if (p < q) + if (p < q) (void)memmove(fr->obuf, p, q - p); zs->avail_out = fr->olen - (q - p); zs->next_out = fr->obuf + (q - p); diff --git a/usr.sbin/fifolog/lib/fifolog_write_poll.c b/usr.sbin/fifolog/lib/fifolog_write_poll.c index abb015bc8e60..6dee5e09235e 100644 --- a/usr.sbin/fifolog/lib/fifolog_write_poll.c +++ b/usr.sbin/fifolog/lib/fifolog_write_poll.c @@ -52,12 +52,12 @@ const char *fifolog_write_statnames[] = { -[FIFOLOG_PT_BYTES_PRE] = "Bytes before compression", -[FIFOLOG_PT_BYTES_POST] = "Bytes after compression", -[FIFOLOG_PT_WRITES] = "Writes", -[FIFOLOG_PT_FLUSH] = "Flushes", -[FIFOLOG_PT_SYNC] = "Syncs", -[FIFOLOG_PT_RUNTIME] = "Runtime" + [FIFOLOG_PT_BYTES_PRE] = "Bytes before compression", + [FIFOLOG_PT_BYTES_POST] = "Bytes after compression", + [FIFOLOG_PT_WRITES] = "Writes", + [FIFOLOG_PT_FLUSH] = "Flushes", + [FIFOLOG_PT_SYNC] = "Syncs", + [FIFOLOG_PT_RUNTIME] = "Runtime" }; /* @@ -182,7 +182,7 @@ fifolog_write_output(struct fifolog_writer *f, int fl, time_t now) return (0); - if (h + l < (long)f->ff->recsize && fl == Z_NO_FLUSH) + if (h + l < (long)f->ff->recsize && fl == Z_NO_FLUSH) return (0); w = f->ff->recsize - l; @@ -258,7 +258,7 @@ fprintf(stderr, "Z len %3d fin %d now %ld fl %d ai %u ao %u\n", #ifdef DBG if (i || f->ff->zs->avail_in) -fprintf(stderr, "fl = %d, i = %d ai = %u ao = %u fx=%02x\n", fl, i, +fprintf(stderr, "fl = %d, i = %d ai = %u ao = %u fx=%02x\n", fl, i, f->ff->zs->avail_in, f->ff->zs->avail_out, f->flag); #endif @@ -321,7 +321,7 @@ fifolog_write_bytes(struct fifolog_writer *f, uint32_t id, time_t now, const voi if (now != f->last) { id |= FIFOLOG_TIMESTAMP; f->last = now; - } + } /* Emit instance+flag */ be32enc(buf, id); diff --git a/usr.sbin/fifolog/lib/miniobj.h b/usr.sbin/fifolog/lib/miniobj.h index a8053166886c..dd79be1fabdb 100644 --- a/usr.sbin/fifolog/lib/miniobj.h +++ b/usr.sbin/fifolog/lib/miniobj.h @@ -26,11 +26,11 @@ * $FreeBSD$ */ -#define ALLOC_OBJ(to, type_magic) \ +#define ALLOC_OBJ(to, type_magic) \ do { \ (to) = calloc(sizeof *(to), 1); \ - assert((to) != NULL); \ - (to)->magic = (type_magic); \ + if ((to) != NULL) \ + (to)->magic = (type_magic); \ } while (0) #define FREE_OBJ(to) \ @@ -39,6 +39,9 @@ free(to); \ } while (0) +#define VALID_OBJ(ptr, type_magic) \ + ((ptr) != NULL && (ptr)->magic == (type_magic)) + #define CHECK_OBJ(ptr, type_magic) \ do { \ assert((ptr)->magic == type_magic); \ @@ -50,6 +53,12 @@ assert((ptr)->magic == type_magic); \ } while (0) +#define CHECK_OBJ_ORNULL(ptr, type_magic) \ + do { \ + if ((ptr) != NULL) \ + assert((ptr)->magic == type_magic); \ + } while (0) + #define CAST_OBJ(to, from, type_magic) \ do { \ (to) = (from); \ @@ -57,10 +66,9 @@ CHECK_OBJ((to), (type_magic)); \ } while (0) -#define CAST_OBJ_NOTNULL(to, from, type_magic) \ +#define CAST_OBJ_NOTNULL(to, from, type_magic) \ do { \ (to) = (from); \ assert((to) != NULL); \ CHECK_OBJ((to), (type_magic)); \ } while (0) -