aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
blob: abef5afea23f67d35e7bb7897b8f10245b1358ed (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
38
39
40
41
42
43
44
/*
 * Copyright (C) 2020-2021  Tomasz Kramkowski <tk@the-tk.com>
 * SPDX-License-Identifier: MIT
 */
#ifndef PACK_COMMON_H
#define PACK_COMMON_H

#include <limits.h>
#include <stddef.h>

#include "pack.h"

#define BITMASK(n) (UINTMAX_MAX >> (sizeof (uintmax_t) * CHAR_BIT - n))

#define SET_AND_GOTO(what, to, where) \
	do { (what) = (to); goto where; } while (0);

#ifndef PRIuSIZE
   #ifdef _WIN32
      #ifdef _WIN64
         #define PRIuSIZE PRIu64
      #else
         #define PRIuSIZE PRIu32
      #endif
   #else
      #define PRIuSIZE "zu"
   #endif
#endif

#define ITYPE_MACROS \
	T(SCHAR,  signed,   char,      int) \
	T(UCHAR,  unsigned, char,      int) \
	T(SHORT,  signed,   short,     int) \
	T(USHORT, unsigned, short,     int) \
	T(INT,    signed,   int,       int) \
	T(UINT,   unsigned, int,       int) \
	T(LONG,   signed,   long,      long) \
	T(ULONG,  unsigned, long,      long) \
	T(LLONG,  signed,   long long, long long) \
	T(ULLONG, unsigned, long long, long long)

size_t getsize(enum pack_type t);

#endif // !PACK_COMMON_H