svn commit: trunk/busybox: archival/libunarchive include libbb misc etc...

landley at busybox.net landley at busybox.net
Mon May 29 05:51:14 UTC 2006


Author: landley
Date: 2006-05-28 22:51:12 -0700 (Sun, 28 May 2006)
New Revision: 15215

Log:
Add SWAP_LE?? and SWAP_BE?? macros, and make things use them.  Converts values
to/from little endian or big endian, which is a NOP if that's what the current
platform already is.


Modified:
   trunk/busybox/archival/libunarchive/decompress_unlzma.c
   trunk/busybox/include/platform.h
   trunk/busybox/libbb/md5.c
   trunk/busybox/miscutils/hdparm.c


Changeset:
Modified: trunk/busybox/archival/libunarchive/decompress_unlzma.c
===================================================================
--- trunk/busybox/archival/libunarchive/decompress_unlzma.c	2006-05-29 05:21:29 UTC (rev 15214)
+++ trunk/busybox/archival/libunarchive/decompress_unlzma.c	2006-05-29 05:51:12 UTC (rev 15215)
@@ -121,10 +121,8 @@
 	pos_state_mask = (1 << pb) - 1;
 	literal_pos_mask = (1 << lp) - 1;
 
-#if BB_BIG_ENDIAN
-	header.dict_size = bswap_32(header.dict_size);
-	header.dst_size = bswap_64(header.dst_size);
-#endif
+	header.dict_size = SWAP_LE32(header.dict_size);
+	header.dst_size = SWAP_LE64(header.dst_size);
 
 	if (header.dict_size == 0)
 		header.dict_size = 1;

Modified: trunk/busybox/include/platform.h
===================================================================
--- trunk/busybox/include/platform.h	2006-05-29 05:21:29 UTC (rev 15214)
+++ trunk/busybox/include/platform.h	2006-05-29 05:51:12 UTC (rev 15215)
@@ -48,11 +48,6 @@
 # define __const const
 #endif
 
-#ifndef __THROW
-# define __THROW
-#endif
-
-
 #ifndef ATTRIBUTE_UNUSED
 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
 #endif /* ATTRIBUTE_UNUSED */
@@ -118,6 +113,22 @@
 # define BB_LITTLE_ENDIAN 1
 #endif
 
+#if BB_BIG_ENDIAN
+#define SWAP_BE16(x) x
+#define SWAP_BE32(x) x
+#define SWAP_BE64(x) x
+#define SWAP_LE16(x) bswap_16(x)
+#define SWAP_LE32(x) bswap_32(x)
+#define SWAP_LE64(x) bswap_64(x)
+#else
+#define SWAP_BE16(x) bswap_16(x)
+#define SWAP_BE32(x) bswap_32(x)
+#define SWAP_BE64(x) bswap_64(x)
+#define SWAP_LE16(x) x
+#define SWAP_LE32(x) x
+#define SWAP_LE64(x) x
+#endif
+
 /* ---- Networking ------------------------------------------ */
 #ifndef __APPLE__
 # include <arpa/inet.h>

Modified: trunk/busybox/libbb/md5.c
===================================================================
--- trunk/busybox/libbb/md5.c	2006-05-29 05:21:29 UTC (rev 15214)
+++ trunk/busybox/libbb/md5.c	2006-05-29 05:51:12 UTC (rev 15215)
@@ -27,15 +27,6 @@
 # define MD5_SIZE_VS_SPEED CONFIG_MD5_SIZE_VS_SPEED
 # endif
 
-/* Handle endian-ness */
-# if !BB_BIG_ENDIAN
-#  define SWAP(n) (n)
-# elif defined(bswap_32)
-#  define SWAP(n) bswap_32(n)
-# else
-#  define SWAP(n) ((n << 24) | ((n&0xFF00)<<8) | ((n&0xFF0000)>>8) | (n>>24))
-# endif
-
 /* Initialize structure containing state of computation.
  * (RFC 1321, 3.3: Step 3)
  */
@@ -132,7 +123,7 @@
 		uint32_t temp;
 
 		for (i = 0; i < 16; i++) {
-			cwp[i] = SWAP(words[i]);
+			cwp[i] = SWAP_LE32(words[i]);
 		}
 		words += 16;
 
@@ -224,7 +215,7 @@
 #  define OP(a, b, c, d, s, T)	\
       do	\
 	{	\
-	  a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T;	\
+	  a += FF (b, c, d) + (*cwp++ = SWAP_LE32(*words)) + T; \
 	  ++words;	\
 	  CYCLIC (a, s);	\
 	  a += b;	\
@@ -455,10 +446,10 @@
 	 * IMPORTANT: On some systems it is required that RESBUF is correctly
 	 * aligned for a 32 bits value.
 	 */
-	((uint32_t *) resbuf)[0] = SWAP(ctx->A);
-	((uint32_t *) resbuf)[1] = SWAP(ctx->B);
-	((uint32_t *) resbuf)[2] = SWAP(ctx->C);
-	((uint32_t *) resbuf)[3] = SWAP(ctx->D);
+	((uint32_t *) resbuf)[0] = SWAP_LE32(ctx->A);
+	((uint32_t *) resbuf)[1] = SWAP_LE32(ctx->B);
+	((uint32_t *) resbuf)[2] = SWAP_LE32(ctx->C);
+	((uint32_t *) resbuf)[3] = SWAP_LE32(ctx->D);
 
 	return resbuf;
 }

Modified: trunk/busybox/miscutils/hdparm.c
===================================================================
--- trunk/busybox/miscutils/hdparm.c	2006-05-29 05:21:29 UTC (rev 15214)
+++ trunk/busybox/miscutils/hdparm.c	2006-05-29 05:51:12 UTC (rev 15215)
@@ -26,7 +26,6 @@
 #include <getopt.h>
 #include <linux/types.h>
 #include <linux/hdreg.h>
-#include <asm/byteorder.h>
 
 #if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
 # define __USE_XOPEN
@@ -2007,9 +2006,9 @@
 		args1[0] = WIN_IDENTIFY;
 		args1[3] = 1;
 		if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) {
-			for (i=0; i<(sizeof args1)/2; i+=2)
-				__le16_to_cpus((uint16_t *)(&args1[i]));
-			identify((void *)&args1[4]);
+			uint16_t *ptr = (uint16_t *)args1;
+			for (i=0; i<sizeof(args1)/2; i++) ptr[i] = SWAP_LE16(ptr[i]);
+			identify((void *)(ptr+2));
 		}
 	}
 #endif
@@ -2057,7 +2056,7 @@
 
 static void identify_from_stdin(void)
 {
-	unsigned short sbuf[800];
+	uint16_t sbuf[800];
 	unsigned char  buf[1600], *b = (unsigned char *)buf;
 	int i, count = read(0, buf, 1280);
 
@@ -2066,8 +2065,7 @@
 
 	for (i = 0; count >= 4; ++i)
 	{
-		sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]);
-		__le16_to_cpus((uint16_t *)(&sbuf[i]));
+		sbuf[i] = SWAP_LE16((fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]));
 		b += 5;
 		count -= 5;
 	}




More information about the busybox-cvs mailing list