aboutsummaryrefslogtreecommitdiffstats
path: root/common.c
blob: 0176d094f0a09d361a4c8030833a11a16f7aff4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * Copyright (C) 2020  Tomasz Kramkowski <tk@the-tk.com>
 * SPDX-License-Identifier: MIT
 */
#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";
	}
}