From 2e1ff80dab0cee0f197dccc9c5dd2f3b9afdb168 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 20 Aug 2020 21:34:34 +0100 Subject: init --- common.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 common.c (limited to 'common.c') diff --git a/common.c b/common.c new file mode 100644 index 0000000..106fc7a --- /dev/null +++ b/common.c @@ -0,0 +1,33 @@ +#include + +#include "common.h" +#include "pack.h" + +size_t getsize(char c) +{ + switch (c) { + case 'b': case 'B': + case 'x': + return 1; + case 'h': case 'H': + case 'i': case 'I': + return 2; + case 'l': case 'L': + case 'f': + return 4; + case 'q': case 'Q': + case 'd': + return 8; + case 's': default: return (size_t)-1; + } +} + +const char *pack_strerror(enum pack_status status) +{ + switch (status) { + case PACK_OK: return "Success"; + case PACK_FMTINVAL: return "Invalid format parameter"; + case PACK_TOOSMALL: return "Buffer too small"; + default: return "Invalid Status"; + } +} -- cgit v1.2.3-54-g00ecf