[dovecot-cvs] dovecot/src/lib byteorder.c,1.2,1.3 byteorder.h,1.2,1.3

cras at procontrol.fi cras at procontrol.fi
Mon Aug 18 07:21:25 EEST 2003


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv2937/lib

Modified Files:
	byteorder.c byteorder.h 
Log Message:
Removed the NBO32_BIT* stuff. They don't work well with enums which are
signed integers..



Index: byteorder.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/byteorder.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- byteorder.c	6 Aug 2003 20:13:57 -0000	1.2
+++ byteorder.c	18 Aug 2003 03:21:23 -0000	1.3
@@ -3,48 +3,26 @@
 #include "lib.h"
 #include "byteorder.h"
 
-uint32_t nbo32_bitmasks[32] = {
-	NBO32_BIT0, NBO32_BIT1, NBO32_BIT2, NBO32_BIT3,
-	NBO32_BIT4, NBO32_BIT5, NBO32_BIT6, NBO32_BIT7,
-	NBO32_BIT8, NBO32_BIT9, NBO32_BIT10, NBO32_BIT11,
-	NBO32_BIT12, NBO32_BIT13, NBO32_BIT14, NBO32_BIT15,
-	NBO32_BIT16, NBO32_BIT17, NBO32_BIT18, NBO32_BIT19,
-	NBO32_BIT20, NBO32_BIT21, NBO32_BIT22, NBO32_BIT23,
-	NBO32_BIT24, NBO32_BIT25, NBO32_BIT26, NBO32_BIT27,
-	NBO32_BIT28, NBO32_BIT29, NBO32_BIT30, NBO32_BIT31
-};
-
 #ifndef WORDS_BIGENDIAN
 
-void nbo_to_host(void *data, size_t size)
-{
-	if (size == sizeof(uint32_t)) {
-		uint32_t *num = (uint32_t *) data;
+#define swap64(num) \
+	(((num & 0x00000000000000ffULL) << 56) | \
+	 ((num & 0x000000000000ff00ULL) << 40) | \
+	 ((num & 0x0000000000ff0000ULL) << 24) | \
+	 ((num & 0x00000000ff000000ULL) <<  8) | \
+	 ((num & 0x000000ff00000000ULL) >>  8) | \
+	 ((num & 0x0000ff0000000000ULL) >> 24) | \
+	 ((num & 0x00ff000000000000ULL) >> 40) | \
+	 ((num & 0xff00000000000000ULL) >> 56))
 
-		*num = ntohl(*num);
-	} else if (size == sizeof(uint32_t)*2) {
-		uint32_t *num = (uint32_t *) data;
-		uint32_t temp;
 
-		temp = ntohl(num[0]);
-		num[0] = ntohl(num[1]);
-		num[1] = temp;
-	}
+uint64_t nbo_to_uint64(uint64_t num)
+{
+	return swap64(num);
 }
 
-void host_to_nbo(void *data, size_t size)
+uint64_t uint64_to_nbo(uint64_t num)
 {
-	if (size == sizeof(uint32_t)) {
-		uint32_t *num = (uint32_t *) data;
-
-		*num = htonl(*num);
-	} else if (size == sizeof(uint32_t)*2) {
-		uint32_t *num = (uint32_t *) data;
-		uint32_t temp;
-
-		temp = htonl(num[0]);
-		num[0] = htonl(num[1]);
-		num[1] = temp;
-	}
+	return swap64(num);
 }
 #endif

Index: byteorder.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/byteorder.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- byteorder.h	6 Aug 2003 20:13:57 -0000	1.2
+++ byteorder.h	18 Aug 2003 03:21:23 -0000	1.3
@@ -2,92 +2,19 @@
 #define __BYTEORDER_H
 
 #ifdef WORDS_BIGENDIAN
-
-/* Bits in network byte order */
-#  define NBO32_BIT0	0x00000001
-#  define NBO32_BIT1	0x00000002
-#  define NBO32_BIT2	0x00000004
-#  define NBO32_BIT3	0x00000008
-#  define NBO32_BIT4	0x00000010
-#  define NBO32_BIT5	0x00000020
-#  define NBO32_BIT6	0x00000040
-#  define NBO32_BIT7	0x00000080
-#  define NBO32_BIT8	0x00000100
-#  define NBO32_BIT9	0x00000200
-#  define NBO32_BIT10	0x00000400
-#  define NBO32_BIT11	0x00000800
-#  define NBO32_BIT12	0x00001000
-#  define NBO32_BIT13	0x00002000
-#  define NBO32_BIT14	0x00004000
-#  define NBO32_BIT15	0x00008000
-#  define NBO32_BIT16	0x00010000
-#  define NBO32_BIT17	0x00020000
-#  define NBO32_BIT18	0x00040000
-#  define NBO32_BIT19	0x00080000
-#  define NBO32_BIT20	0x00100000
-#  define NBO32_BIT21	0x00200000
-#  define NBO32_BIT22	0x00400000
-#  define NBO32_BIT23	0x00800000
-#  define NBO32_BIT24	0x01000000
-#  define NBO32_BIT25	0x02000000
-#  define NBO32_BIT26	0x04000000
-#  define NBO32_BIT27	0x08000000
-#  define NBO32_BIT28	0x10000000
-#  define NBO32_BIT29	0x20000000
-#  define NBO32_BIT30	0x40000000
-#  define NBO32_BIT31	0x80000000
-
-#  define nbo_to_host(data, size)
-#  define host_to_nbo(data, size)
 #  define nbo_to_uint32(num) (num)
 #  define uint32_to_nbo(num) (num)
+#  define nbo_to_uint64(num) (num)
+#  define uint64_to_nbo(num) (num)
 #else
 
-/* We support only big endian and little endian. AFAIK PDP-endian is the
-   only third used one but I don't think I need PDP-support for now :) */
 #include <arpa/inet.h>
 
-/* Bits in network byte order */
-#  define NBO32_BIT0	0x01000000
-#  define NBO32_BIT1	0x02000000
-#  define NBO32_BIT2	0x04000000
-#  define NBO32_BIT3	0x08000000
-#  define NBO32_BIT4	0x10000000
-#  define NBO32_BIT5	0x20000000
-#  define NBO32_BIT6	0x40000000
-#  define NBO32_BIT7	0x80000000
-#  define NBO32_BIT8	0x00010000
-#  define NBO32_BIT9	0x00020000
-#  define NBO32_BIT10	0x00040000
-#  define NBO32_BIT11	0x00080000
-#  define NBO32_BIT12	0x00100000
-#  define NBO32_BIT13	0x00200000
-#  define NBO32_BIT14	0x00400000
-#  define NBO32_BIT15	0x00800000
-#  define NBO32_BIT16	0x00000100
-#  define NBO32_BIT17	0x00000200
-#  define NBO32_BIT18	0x00000400
-#  define NBO32_BIT19	0x00000800
-#  define NBO32_BIT20	0x00001000
-#  define NBO32_BIT21	0x00002000
-#  define NBO32_BIT22	0x00004000
-#  define NBO32_BIT23	0x00008000
-#  define NBO32_BIT24	0x00000001
-#  define NBO32_BIT25	0x00000002
-#  define NBO32_BIT26	0x00000004
-#  define NBO32_BIT27	0x00000008
-#  define NBO32_BIT28	0x00000010
-#  define NBO32_BIT29	0x00000020
-#  define NBO32_BIT30	0x00000040
-#  define NBO32_BIT31	0x00000080
-
-void nbo_to_host(void *data, size_t size);
-void host_to_nbo(void *data, size_t size);
-
 #  define nbo_to_uint32(num) ntohl(num)
 #  define uint32_to_nbo(num) htonl(num)
-#endif
 
-extern uint32_t nbo32_bitmasks[32];
+uint64_t nbo_to_uint64(uint64_t num);
+uint64_t uint64_to_nbo(uint64_t num);
+#endif
 
 #endif



More information about the dovecot-cvs mailing list