aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r--src/include/gnunet_common.h64
1 files changed, 37 insertions, 27 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 9bcd99c7b..9fa3de37d 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006-2021 GNUnet e.V. 3 Copyright (C) 2006-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @file include/gnunet_common.h 26 * @file include/gnunet_common.h
23 * @brief commonly used definitions; globals in this file 27 * @brief commonly used definitions; globals in this file
24 * are exempt from the rule that the module name ("common") 28 * are exempt from the rule that the module name ("common")
@@ -36,28 +40,38 @@
36#ifndef GNUNET_COMMON_H 40#ifndef GNUNET_COMMON_H
37#define GNUNET_COMMON_H 41#define GNUNET_COMMON_H
38 42
43#include "gnunet_config.h"
44
45#include <stdbool.h>
39#include <stdlib.h> 46#include <stdlib.h>
40#if HAVE_SYS_SOCKET_H
41#include <sys/socket.h> 47#include <sys/socket.h>
42#endif 48#include <sys/un.h>
43#if HAVE_NETINET_IN_H
44#include <netinet/in.h> 49#include <netinet/in.h>
45#endif 50#include <arpa/inet.h>
46#ifdef HAVE_STDINT_H
47#include <stdint.h> 51#include <stdint.h>
48#endif
49#ifdef HAVE_STDARG_H
50#include <stdarg.h> 52#include <stdarg.h>
51#endif
52#ifdef HAVE_SYS_TYPES_H
53#include <sys/types.h> 53#include <sys/types.h>
54#endif
55#ifdef HAVE_SYS_SOCKET_H
56#include <sys/socket.h>
57#endif
58 54
55#if defined(__FreeBSD__)
56
57#include <sys/endian.h>
58#define bswap_32(x) bswap32(x)
59#define bswap_64(x) bswap64(x)
60
61#elif defined(__OpenBSD__)
62
63#define bswap_32(x) swap32(x)
64#define bswap_64(x) swap64(x)
65
66#elif defined(__NetBSD__)
59 67
60#ifdef HAVE_BYTESWAP_H 68#include <machine/bswap.h>
69#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
70#define bswap_32(x) bswap32(x)
71#define bswap_64(x) bswap64(x)
72#endif
73
74#elif defined(__linux__) || defined(GNU)
61#include <byteswap.h> 75#include <byteswap.h>
62#endif 76#endif
63 77
@@ -132,12 +146,6 @@ enum GNUNET_GenericReturnValue
132#endif 146#endif
133 147
134/** 148/**
135 * wrap va_arg for enums
136 */
137#define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
138
139
140/**
141 * @ingroup logging 149 * @ingroup logging
142 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source 150 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source
143 * tree where gnunet_config.h is unavailable 151 * tree where gnunet_config.h is unavailable
@@ -150,8 +158,7 @@ enum GNUNET_GenericReturnValue
150 * Endian operations 158 * Endian operations
151 */ 159 */
152 160
153#if __BYTE_ORDER == __LITTLE_ENDIAN 161#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
154#ifdef HAVE_BYTESWAP_H
155#define BYTE_SWAP_16(x) bswap_16 (x) 162#define BYTE_SWAP_16(x) bswap_16 (x)
156#define BYTE_SWAP_32(x) bswap_32 (x) 163#define BYTE_SWAP_32(x) bswap_32 (x)
157#define BYTE_SWAP_64(x) bswap_64 (x) 164#define BYTE_SWAP_64(x) bswap_64 (x)
@@ -170,6 +177,7 @@ enum GNUNET_GenericReturnValue
170 56)) 177 56))
171#endif 178#endif
172 179
180#if __BYTE_ORDER == __LITTLE_ENDIAN
173#define GNUNET_htobe16(x) BYTE_SWAP_16 (x) 181#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
174#define GNUNET_htole16(x) (x) 182#define GNUNET_htole16(x) (x)
175#define GNUNET_be16toh(x) BYTE_SWAP_16 (x) 183#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
@@ -667,7 +675,7 @@ GNUNET_log_skip (int n, int check_reset);
667 * @param logfile change logging to logfile (use NULL to keep stderr) 675 * @param logfile change logging to logfile (use NULL to keep stderr)
668 * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened 676 * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened
669 */ 677 */
670int 678enum GNUNET_GenericReturnValue
671GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); 679GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
672 680
673 681
@@ -980,7 +988,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
980 } while (0) 988 } while (0)
981 989
982 990
983#if HAVE_STATIC_ASSERT 991#ifdef _Static_assert
984/** 992/**
985 * Assertion to be checked (if supported by C compiler) at 993 * Assertion to be checked (if supported by C compiler) at
986 * compile time, otherwise checked at runtime and resulting 994 * compile time, otherwise checked at runtime and resulting
@@ -1506,7 +1514,7 @@ GNUNET_is_zero_ (const void *a,
1506 * will be updated to reflect the new address. The TYPE of 1514 * will be updated to reflect the new address. The TYPE of
1507 * arr is important since size is the number of elements and 1515 * arr is important since size is the number of elements and
1508 * not the size in bytes 1516 * not the size in bytes
1509 * @param len the number of elements in the existing vector (number 1517 * @param len2 the number of elements in the existing vector (number
1510 * of elements to copy over), will be updated with the new 1518 * of elements to copy over), will be updated with the new
1511 * array size 1519 * array size
1512 1520
@@ -1739,7 +1747,7 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg);
1739 * Set the async scope for the current thread. 1747 * Set the async scope for the current thread.
1740 * 1748 *
1741 * @param aid the async scope identifier 1749 * @param aid the async scope identifier
1742 * @param old_scope[out] location to save the old scope 1750 * @param[out] old_scope location to save the old scope
1743 */ 1751 */
1744void 1752void
1745GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, 1753GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid,
@@ -1861,3 +1869,5 @@ enum GNUNET_SCHEDULER_Priority
1861#endif 1869#endif
1862 1870
1863#endif /* GNUNET_COMMON_H */ 1871#endif /* GNUNET_COMMON_H */
1872
1873/** @} */ /* end of group addition */