diff options
Diffstat (limited to 'common.c')
-rw-r--r-- | common.c | 33 |
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"; + } +} |