aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-08-08 04:34:55 +0100
committerTomasz Kramkowski <tk@the-tk.com>2021-08-08 05:01:00 +0100
commit7b213a99c973f16d0150c42dbd5dba1c95180982 (patch)
tree01a371d43109791130a470221f9c540b3ccd047d
parentbd0969cb8af8b1e34931e06489de0343bbfa9a69 (diff)
downloadpack-7b213a99c973f16d0150c42dbd5dba1c95180982.tar.gz
pack-7b213a99c973f16d0150c42dbd5dba1c95180982.tar.xz
pack-7b213a99c973f16d0150c42dbd5dba1c95180982.zip
add the PACK_TYPE_COUNT pack_type
-rw-r--r--pack.h1
-rw-r--r--unpack.c3
2 files changed, 3 insertions, 1 deletions
diff --git a/pack.h b/pack.h
index daf0699..7fd54a5 100644
--- a/pack.h
+++ b/pack.h
@@ -34,6 +34,7 @@ enum pack_type {
PACK_TYPE_FLOAT = 'f',
PACK_TYPE_DOUBLE = 'd',
PACK_TYPE_PADDING = 'x',
+ PACK_TYPE_COUNT = '*',
};
enum pack_endian {
diff --git a/unpack.c b/unpack.c
index 836faf3..8fd1d94 100644
--- a/unpack.c
+++ b/unpack.c
@@ -95,6 +95,7 @@ static void read_fields(struct dest dest, const void *src_, enum pack_endian end
case PACK_TYPE_FLOAT: dest.ptr.f[i] = val.f; break;
case PACK_TYPE_DOUBLE: dest.ptr.d[i] = val.d; break;
case PACK_TYPE_PADDING: break;
+ case PACK_TYPE_COUNT: return;
}
}
}
@@ -125,7 +126,7 @@ enum pack_status unpack(const void *buf_, size_t size, const char *fmt, ...)
SET_AND_GOTO(ret, PACK_FMTINVAL, stop);
dest.count = c;
i += end - &fmt[i];
- } else if (fmt[i] == '*') {
+ } else if (fmt[i] == PACK_TYPE_COUNT) {
dest.count = va_arg(ap, size_t);
i++;
}