[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35715 - in gnunet/src: include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35715 - in gnunet/src: include util |
Date: |
Thu, 7 May 2015 14:15:24 +0200 |
Author: tg
Date: 2015-05-07 14:15:24 +0200 (Thu, 07 May 2015)
New Revision: 35715
Modified:
gnunet/src/include/gnunet_common.h
gnunet/src/util/common_endian.c
Log:
add GNUNET_(hton|ntoh).*_signed() functions
Modified: gnunet/src/include/gnunet_common.h
===================================================================
--- gnunet/src/include/gnunet_common.h 2015-05-07 12:15:16 UTC (rev 35714)
+++ gnunet/src/include/gnunet_common.h 2015-05-07 12:15:24 UTC (rev 35715)
@@ -655,37 +655,125 @@
/* ************************* endianess conversion ****************** */
/**
- * Convert unsigned 64-bit integer to host-byte-order.
- * @param n the value in network byte order
- * @return the same value in host byte order
+ * Convert unsigned 64-bit integer to network byte order.
+ *
+ * @param n
+ * The value in host byte order.
+ *
+ * @return The same value in network byte order.
*/
uint64_t
-GNUNET_ntohll (uint64_t n);
+GNUNET_htonll (uint64_t n);
+
/**
- * Convert unsigned 64-bit integer to network-byte-order.
- * @param n the value in host byte order
- * @return the same value in network byte order
+ * Convert unsigned 64-bit integer to host byte order.
+ *
+ * @param n
+ * The value in network byte order.
+ *
+ * @return The same value in host byte order.
*/
uint64_t
-GNUNET_htonll (uint64_t n);
+GNUNET_ntohll (uint64_t n);
+
/**
- * Convert double to network-byte-order.
- * @param d the value in network byte order
- * @return the same value in host byte order
+ * Convert double to network byte order.
+ *
+ * @param d
+ * The value in network byte order.
+ *
+ * @return The same value in host byte order.
*/
double
GNUNET_hton_double (double d);
+
/**
- * Convert double to host-byte-order
- * @param d the value in network byte order
- * @return the same value in host byte order
+ * Convert double to host byte order
+ *
+ * @param d
+ * The value in network byte order.
+ *
+ * @return The same value in host byte order.
*/
double
GNUNET_ntoh_double (double d);
+
+/**
+ * Convert signed 64-bit integer to network byte order.
+ *
+ * @param n
+ * The value in host byte order.
+ *
+ * @return The same value in network byte order.
+ */
+uint64_t
+GNUNET_htonll_signed (int64_t n);
+
+
+/**
+ * Convert signed 64-bit integer to host byte order.
+ *
+ * @param n
+ * The value in network byte order.
+ *
+ * @return The same value in host byte order.
+ */
+int64_t
+GNUNET_ntohll_signed (uint64_t n);
+
+
+/**
+ * Convert signed 32-bit integer to network byte order.
+ *
+ * @param n
+ * The value in host byte order.
+ *
+ * @return The same value in network byte order.
+ */
+uint32_t
+GNUNET_htonl_signed (int32_t n);
+
+
+/**
+ * Convert signed 32-bit integer to host byte order.
+ *
+ * @param n
+ * The value in network byte order.
+ *
+ * @return The same value in host byte order.
+ */
+int32_t
+GNUNET_ntohl_signed (uint32_t n);
+
+
+/**
+ * Convert signed 16-bit integer to network byte order.
+ *
+ * @param n
+ * The value in host byte order.
+ *
+ * @return The same value in network byte order.
+ */
+uint16_t
+GNUNET_htons_signed (int16_t n);
+
+
+/**
+ * Convert signed 16-bit integer to host byte order.
+ *
+ * @param n
+ * The value in network byte order.
+ *
+ * @return The same value in host byte order.
+ */
+int16_t
+GNUNET_ntohs_signed (uint16_t n);
+
+
/* ************************* allocation functions ****************** */
/**
Modified: gnunet/src/util/common_endian.c
===================================================================
--- gnunet/src/util/common_endian.c 2015-05-07 12:15:16 UTC (rev 35714)
+++ gnunet/src/util/common_endian.c 2015-05-07 12:15:24 UTC (rev 35715)
@@ -22,6 +22,7 @@
* @file util/common_endian.c
* @brief endian conversion helpers
* @author Christian Grothoff
+ * @author Gabor X Toth
*/
#include "platform.h"
@@ -29,25 +30,27 @@
#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__)
+
uint64_t
-GNUNET_ntohll (uint64_t n)
+GNUNET_htonll (uint64_t n)
{
#if __BYTE_ORDER == __BIG_ENDIAN
return n;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
- return (((uint64_t) ntohl (n)) << 32) + ntohl (n >> 32);
+ return (((uint64_t) htonl (n)) << 32) + htonl (n >> 32);
#else
#error byteorder undefined
#endif
}
+
uint64_t
-GNUNET_htonll (uint64_t n)
+GNUNET_ntohll (uint64_t n)
{
#if __BYTE_ORDER == __BIG_ENDIAN
return n;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
- return (((uint64_t) htonl (n)) << 32) + htonl (n >> 32);
+ return (((uint64_t) ntohl (n)) << 32) + ntohl (n >> 32);
#else
#error byteorder undefined
#endif
@@ -90,5 +93,47 @@
}
+uint64_t
+GNUNET_htonll_signed (int64_t n)
+{
+ return GNUNET_htonll (n - INT64_MIN);
+}
+
+int64_t
+GNUNET_ntohll_signed (uint64_t n)
+{
+ return GNUNET_ntohll (n) + INT64_MIN;
+}
+
+
+uint32_t
+GNUNET_htonl_signed (int32_t n)
+{
+ return htonl (n - INT32_MIN);
+}
+
+
+int32_t
+GNUNET_ntohl_signed (uint32_t n)
+{
+ return ntohl (n) + INT32_MIN;
+}
+
+
+uint16_t
+GNUNET_htons_signed (int16_t n)
+{
+ return htons (n - INT16_MIN);
+}
+
+
+int16_t
+GNUNET_ntohs_signed (uint16_t n)
+{
+ return ntohs (n) + INT16_MIN;
+}
+
+
+
/* end of common_endian.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35715 - in gnunet/src: include util,
gnunet <=