aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
blob: f22f5882f54892a7d0e3fb582f24cb72e2ad86a8 (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
/*
 * 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))

#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