aboutsummaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2020-08-20 21:34:34 +0100
committerTomasz Kramkowski <tk@the-tk.com>2020-08-20 21:34:34 +0100
commit2e1ff80dab0cee0f197dccc9c5dd2f3b9afdb168 (patch)
treebfe7ad4524a3ae1665e30c2ccb1ce838fbabf0d9 /common.c
downloadpack-2e1ff80dab0cee0f197dccc9c5dd2f3b9afdb168.tar.gz
pack-2e1ff80dab0cee0f197dccc9c5dd2f3b9afdb168.tar.xz
pack-2e1ff80dab0cee0f197dccc9c5dd2f3b9afdb168.zip
init
Diffstat (limited to 'common.c')
-rw-r--r--common.c33
1 files changed, 33 insertions, 0 deletions
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 <stddef.h>
+
+#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";
+ }
+}