diff options
-rw-r--r-- | pack.c | 12 | ||||
-rw-r--r-- | pack.h | 4 | ||||
-rw-r--r-- | unpack.c | 20 |
3 files changed, 18 insertions, 18 deletions
@@ -12,21 +12,21 @@ #include "pack.h" #include "trace.h" -static void write_val(unsigned char *buf, size_t size, enum pack_endian e, uintmax_t val) +static void write_val(unsigned char *dest, size_t size, enum pack_endian e, uintmax_t val) { for (size_t i = 0; i < size; i++) - buf[i] = (val >> (e == PACK_ENDIAN_LITTLE ? i : size - i - 1) * 8) & 0xff; + dest[i] = (val >> (e == PACK_ENDIAN_LITTLE ? i : size - i - 1) * 8) & 0xff; } -enum pack_status pack(void *buf_, size_t size, const char *fmt, ...) +enum pack_status pack(void *dest_, size_t size, const char *fmt, ...) { enum pack_endian endianness = PACK_ENDIAN_BIG; - unsigned char *buf = buf_; + unsigned char *dest = dest_; enum pack_status ret = PACK_OK; size_t offset = 0; va_list ap; - tr_call("pack(%p, %" PRIuSIZE ", %s, ...)", (void *)buf, size, fmt); + tr_call("pack(%p, %" PRIuSIZE ", %s, ...)", (void *)dest, size, fmt); va_start(ap, fmt); @@ -62,7 +62,7 @@ enum pack_status pack(void *buf_, size_t size, const char *fmt, ...) v.unsigned_ = n; } tr_debug("val.u: %" PRIuMAX, v.unsigned_); - write_val(&buf[offset], s, endianness, v.unsigned_); + write_val(&dest[offset], s, endianness, v.unsigned_); offset += s; } @@ -55,8 +55,8 @@ struct pack_args { }; enum pack_status pack(void *dest, size_t size, const char *fmt, ...); -enum pack_status unpack(const void *buf, size_t size, const char *fmt, ...); -enum pack_status unpack_struct(const void *buf, size_t size, const struct pack_args *args, void *dest); +enum pack_status unpack(const void *src, size_t size, const char *fmt, ...); +enum pack_status unpack_struct(const void *src, size_t size, const struct pack_args *args, void *dest); const char *pack_strerror(enum pack_status status); @@ -27,12 +27,12 @@ struct dest { size_t count; }; -static uintmax_t read_val(const unsigned char *buf, size_t size, enum pack_endian e) +static uintmax_t read_val(const unsigned char *src, size_t size, enum pack_endian e) { uintmax_t val = 0; for (size_t i = 0; i < size; i++) { - val |= (uintmax_t)(buf[i] & 0xff) << (e == PACK_ENDIAN_LITTLE ? i : size - i - 1) * 8; + val |= (uintmax_t)(src[i] & 0xff) << (e == PACK_ENDIAN_LITTLE ? i : size - i - 1) * 8; } return val; @@ -100,15 +100,15 @@ static void read_fields(struct dest dest, const void *src_, enum pack_endian end } } -enum pack_status unpack(const void *buf_, size_t size, const char *fmt, ...) +enum pack_status unpack(const void *src_, size_t size, const char *fmt, ...) { enum pack_endian endianness = PACK_ENDIAN_BIG; - const unsigned char *buf = buf_; + const unsigned char *src = src_; enum pack_status ret = PACK_OK; size_t offset = 0; va_list ap; - tr_call("unpack(%p, %" PRIuSIZE ", %s, ...)", (const void *)buf, size, fmt); + tr_call("unpack(%p, %" PRIuSIZE ", %s, ...)", (const void *)src, size, fmt); va_start(ap, fmt); @@ -155,7 +155,7 @@ enum pack_status unpack(const void *buf_, size_t size, const char *fmt, ...) SET_AND_GOTO(ret, PACK_TOOSMALL, stop); if (dest.type != PACK_TYPE_PADDING) - read_fields(dest, &buf[offset], endianness); + read_fields(dest, &src[offset], endianness); offset += s * dest.count; } @@ -166,15 +166,15 @@ stop: return ret; } -enum pack_status unpack_struct(const void *buf_, size_t size, +enum pack_status unpack_struct(const void *src_, size_t size, const struct pack_args *args, void *dest_) { - const unsigned char *buf = buf_; + const unsigned char *src = src_; char *dest = dest_; size_t offset = 0; tr_call("unpack_struct(%p, %" PRIuSIZE ", %p, %p)", \ - (const void *)buf, size, (const void *)args, (const void *)dest); + (const void *)src, size, (const void *)args, (const void *)dest); tr_debug("args->endian: %s, args->fields: %p, args->num_fields: %" PRIuSIZE, args->endian == PACK_ENDIAN_BIG ? "big" : "little", @@ -217,7 +217,7 @@ enum pack_status unpack_struct(const void *buf_, size_t size, if (size - offset < s * field.count) return PACK_TOOSMALL; if (f->type != PACK_TYPE_PADDING) - read_fields(field, &buf[offset], args->endian); + read_fields(field, &src[offset], args->endian); offset += s * field.count; #undef FIELD |