Mercurial > code
changeset 115:1d0e5580d402
Reduce code for cosmetic
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 13 Feb 2012 19:46:22 +0100 |
parents | bb2694382675 |
children | 268566dcc2c4 |
files | pack.c |
diffstat | 1 files changed, 12 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/pack.c Mon Feb 13 18:06:07 2012 +0100 +++ b/pack.c Mon Feb 13 19:46:22 2012 +0100 @@ -38,9 +38,9 @@ static size_t pack_getsize(char); static ConvertFn pack_getconvert_by_tok(char); static ConvertFn pack_getconvert_by_size(size_t); -static void pack_convert16(void *); -static void pack_convert32(void *); -static void pack_convert64(void *); +static void pack_convert16(uint16_t *); +static void pack_convert32(uint32_t *); +static void pack_convert64(uint64_t *); static void pack_write_one(int, FILE *, uint64_t, size_t); static void pack_write_multiple(int, FILE *, uint8_t *, int, size_t); @@ -61,10 +61,10 @@ size_t tocopy; /* size */ ConvertFn convert; /* conversion function */ } sizes[] = { - { 'c', sizeof (uint8_t), NULL }, - { 's', sizeof (uint16_t), &pack_convert16 }, - { 'i', sizeof (uint32_t), &pack_convert32 }, - { 'l', sizeof (uint64_t), &pack_convert64 } + { 'c', sizeof (uint8_t), NULL }, + { 's', sizeof (uint16_t), (ConvertFn)pack_convert16 }, + { 'i', sizeof (uint32_t), (ConvertFn)pack_convert32 }, + { 'l', sizeof (uint64_t), (ConvertFn)pack_convert64 } }; /* @@ -95,7 +95,7 @@ do { \ if (p[1] == '[') { \ if (p[2] != ']') \ - nelem = (int) strtol(p + 2, NULL, 10); \ + nelem = (int)strtol(p + 2, NULL, 10); \ else if (p[2] == ']') \ nelem = va_arg(ap, int); \ \ @@ -164,26 +164,20 @@ */ static void -pack_convert16(void *obj) +pack_convert16(uint16_t *x) { - uint16_t *x = obj; - *x = pack_swap16(*x); } static void -pack_convert32(void *obj) +pack_convert32(uint32_t *x) { - uint32_t *x = obj; - *x = pack_swap32(*x); } static void -pack_convert64(void *obj) +pack_convert64(uint64_t *x) { - uint64_t *x = obj; - *x = pack_swap64(*x); } @@ -405,7 +399,7 @@ /* Convert if needed */ convert = pack_getconvert_by_tok(tok); if (ptype != PACK_HOST_BYTEORDER && convert != NULL) - convert((char *) ptr + (tocopy * i)); + convert((char *)ptr + (tocopy * i)); } }