blob: 4a68518ffcb21ef7bdb6fb5159af0ebb53d1f42c (
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-2021 Tomasz Kramkowski <tk@the-tk.com>
* SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include "common.h"
#include "pack.h"
size_t getsize(enum pack_type t)
{
switch (t) {
case PACK_TYPE_SCHAR: case PACK_TYPE_UCHAR:
case PACK_TYPE_PADDING:
return 1;
case PACK_TYPE_SHORT: case PACK_TYPE_USHORT:
case PACK_TYPE_INT: case PACK_TYPE_UINT:
return 2;
case PACK_TYPE_LONG: case PACK_TYPE_ULONG:
case PACK_TYPE_FLOAT:
return 4;
case PACK_TYPE_LLONG: case PACK_TYPE_ULLONG:
case PACK_TYPE_DOUBLE:
return 8;
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";
}
}
|