aboutsummaryrefslogtreecommitdiff
path: root/src/util/common_endian.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/common_endian.c')
-rw-r--r--src/util/common_endian.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/src/util/common_endian.c b/src/util/common_endian.c
deleted file mode 100644
index d69cc1da5..000000000
--- a/src/util/common_endian.c
+++ /dev/null
@@ -1,104 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2006, 2012 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file util/common_endian.c
23 * @brief endian conversion helpers
24 * @author Christian Grothoff
25 * @author Gabor X Toth
26 */
27
28#include "platform.h"
29#include "gnunet_crypto_lib.h"
30
31#define LOG(kind, ...) GNUNET_log_from (kind, "util-common-endian", __VA_ARGS__)
32
33
34#ifndef htonbe64
35uint64_t
36GNUNET_htonll (uint64_t n)
37{
38#if __BYTE_ORDER == __BIG_ENDIAN
39 return n;
40#elif __BYTE_ORDER == __LITTLE_ENDIAN
41 return (((uint64_t) htonl (n)) << 32) + htonl (n >> 32);
42#else
43 #error byteorder undefined
44#endif
45}
46
47
48#endif
49
50
51#ifndef be64toh
52uint64_t
53GNUNET_ntohll (uint64_t n)
54{
55#if __BYTE_ORDER == __BIG_ENDIAN
56 return n;
57#elif __BYTE_ORDER == __LITTLE_ENDIAN
58 return (((uint64_t) ntohl (n)) << 32) + ntohl (n >> 32);
59#else
60 #error byteorder undefined
61#endif
62}
63
64
65#endif
66
67
68/**
69 * Convert double to network-byte-order.
70 * @param d the value in network byte order
71 * @return the same value in host byte order
72 */
73double
74GNUNET_hton_double (double d)
75{
76 double res;
77 uint64_t *in = (uint64_t *) &d;
78 uint64_t *out = (uint64_t *) &res;
79
80 out[0] = GNUNET_htonll (in[0]);
81
82 return res;
83}
84
85
86/**
87 * Convert double to host-byte-order
88 * @param d the value in network byte order
89 * @return the same value in host byte order
90 */
91double
92GNUNET_ntoh_double (double d)
93{
94 double res;
95 uint64_t *in = (uint64_t *) &d;
96 uint64_t *out = (uint64_t *) &res;
97
98 out[0] = GNUNET_ntohll (in[0]);
99
100 return res;
101}
102
103
104/* end of common_endian.c */