blob: 73024f46357b34bb7f3bd25c87e1bc2eb6970c6a [file] [log] [blame]
Michal Vasko9e8ac262020-04-07 13:06:45 +02001/**
2 * @file compat.h
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief compatibility functions header
5 *
6 * Copyright (c) 2020 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef _COMPAT_H_
16#define _COMPAT_H_
17
18#include <sys/types.h>
19#include <stdarg.h>
20#include <stdio.h>
21
22#ifndef __WORDSIZE
23# if defined __x86_64__ && !defined __ILP32__
24# define __WORDSIZE 64
25# else
26# define __WORDSIZE 32
27# endif
28#endif
29
30#ifndef __INT64_C
31# if __WORDSIZE == 64
32# define __INT64_C(c) c ## L
33# define __UINT64_C(c) c ## UL
34# else
35# define __INT64_C(c) c ## LL
36# define __UINT64_C(c) c ## ULL
37# endif
38#endif
39
40#cmakedefine HAVE_VDPRINTF
41#cmakedefine HAVE_ASPRINTF
42#cmakedefine HAVE_VASPRINTF
43#cmakedefine HAVE_STRNDUP
44#cmakedefine HAVE_GETLINE
45#cmakedefine HAVE_GET_CURRENT_DIR_NAME
46
47#define bswap64(val) \
48 ( (((val) >> 56) & 0x00000000000000FF) | (((val) >> 40) & 0x000000000000FF00) | \
49 (((val) >> 24) & 0x0000000000FF0000) | (((val) >> 8) & 0x00000000FF000000) | \
50 (((val) << 8) & 0x000000FF00000000) | (((val) << 24) & 0x0000FF0000000000) | \
51 (((val) << 40) & 0x00FF000000000000) | (((val) << 56) & 0xFF00000000000000) )
52
53#undef le64toh
54#undef htole64
55
Michal Vasko652eaa62020-04-21 14:11:21 +020056#cmakedefine IS_BIG_ENDIAN
Michal Vasko9e8ac262020-04-07 13:06:45 +020057
Michal Vasko652eaa62020-04-21 14:11:21 +020058#ifdef IS_BIG_ENDIAN
Michal Vasko9e8ac262020-04-07 13:06:45 +020059# define le64toh(x) bswap64(x)
60# define htole64(x) bswap64(x)
Michal Vasko652eaa62020-04-21 14:11:21 +020061#else
62# define le64toh(x) (x)
63# define htole64(x) (x)
Michal Vasko9e8ac262020-04-07 13:06:45 +020064#endif
65
66#ifndef MAP_ANONYMOUS
67#define MAP_ANONYMOUS MAP_ANON
68#endif /* !MAP_ANONYMOUS */
69
70#ifndef HAVE_VDPRINTF
71int vdprintf(int fd, const char *format, va_list ap);
72#endif
73
74#ifndef HAVE_ASPRINTF
75int asprintf(char **strp, const char *fmt, ...);
76#endif
77
78#ifndef HAVE_VASPRINTF
79int vasprintf(char **strp, const char *fmt, va_list ap);
80#endif
81
82#ifndef HAVE_STRNDUP
83char *strndup(const char *s, size_t n);
84#endif
85
86#ifndef HAVE_GETLINE
87ssize_t getline(char **lineptr, size_t *n, FILE *stream);
88#endif
89
90#ifndef HAVE_GET_CURRENT_DIR_NAME
91char *get_current_dir_name(void);
92#endif
93
94#endif /* _COMPAT_H_ */