summaryrefslogtreecommitdiffstats
path: root/src/internal.h
blob: f0cc2e19f116702a1abb131fcb3f6efbeb020e63 (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
#ifndef INTERNAL_H
#define INTERNAL_H 1

#include "config.h"
#ifdef HAVE_VISIBILITY_HIDDEN
#	define __visible	__attribute__((visibility("default")))
#	define EXPORT_SYMBOL(x)	typeof(x) (x) __visible
#else
#	define EXPORT_SYMBOL
#endif

#include <endian.h>
#if !defined(htobe64)
#	include <byteswap.h>
#	if __BYTE_ORDER == __LITTLE_ENDIAN
#		define htobe64(x) __bswap_64(x)
#		define betoh64(x) __bswap_64(x)
#	else
#		define htobe64(x) (x)
#		define betoh64(x) (x)
#	endif
#endif

#define SNPRINTF_CHECK(ret, rem, offset, len)			\
do {								\
	if (ret < 0)						\
		return ret;					\
	len += ret;						\
	if (ret > rem)						\
		ret = rem;					\
	offset += ret;						\
	rem -= ret;						\
} while (0)

#endif