aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-05-29 05:51:12 +0000
committerRob Landley <rob@landley.net>2006-05-29 05:51:12 +0000
commitbba7f08d2788bc9bc30a7a60fdfd873a73fead9a (patch)
treed2f6adda7dc120be2aa64c7a984f12c8ecf608f2
parent97551974485a8680299560af8863023dfb9634af (diff)
downloadbusybox-w32-bba7f08d2788bc9bc30a7a60fdfd873a73fead9a.tar.gz
busybox-w32-bba7f08d2788bc9bc30a7a60fdfd873a73fead9a.tar.bz2
busybox-w32-bba7f08d2788bc9bc30a7a60fdfd873a73fead9a.zip
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.
-rw-r--r--archival/libunarchive/decompress_unlzma.c6
-rw-r--r--include/platform.h21
-rw-r--r--libbb/md5.c21
-rw-r--r--miscutils/hdparm.c12
4 files changed, 29 insertions, 31 deletions
diff --git a/archival/libunarchive/decompress_unlzma.c b/archival/libunarchive/decompress_unlzma.c
index 7ae343f0f..fa7b37c37 100644
--- a/archival/libunarchive/decompress_unlzma.c
+++ b/archival/libunarchive/decompress_unlzma.c
@@ -121,10 +121,8 @@ int unlzma(int src_fd, int dst_fd)
121 pos_state_mask = (1 << pb) - 1; 121 pos_state_mask = (1 << pb) - 1;
122 literal_pos_mask = (1 << lp) - 1; 122 literal_pos_mask = (1 << lp) - 1;
123 123
124#if BB_BIG_ENDIAN 124 header.dict_size = SWAP_LE32(header.dict_size);
125 header.dict_size = bswap_32(header.dict_size); 125 header.dst_size = SWAP_LE64(header.dst_size);
126 header.dst_size = bswap_64(header.dst_size);
127#endif
128 126
129 if (header.dict_size == 0) 127 if (header.dict_size == 0)
130 header.dict_size = 1; 128 header.dict_size = 1;
diff --git a/include/platform.h b/include/platform.h
index d684c2dda..10c1d7d86 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -48,11 +48,6 @@
48# define __const const 48# define __const const
49#endif 49#endif
50 50
51#ifndef __THROW
52# define __THROW
53#endif
54
55
56#ifndef ATTRIBUTE_UNUSED 51#ifndef ATTRIBUTE_UNUSED
57# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 52# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
58#endif /* ATTRIBUTE_UNUSED */ 53#endif /* ATTRIBUTE_UNUSED */
@@ -118,6 +113,22 @@
118# define BB_LITTLE_ENDIAN 1 113# define BB_LITTLE_ENDIAN 1
119#endif 114#endif
120 115
116#if BB_BIG_ENDIAN
117#define SWAP_BE16(x) x
118#define SWAP_BE32(x) x
119#define SWAP_BE64(x) x
120#define SWAP_LE16(x) bswap_16(x)
121#define SWAP_LE32(x) bswap_32(x)
122#define SWAP_LE64(x) bswap_64(x)
123#else
124#define SWAP_BE16(x) bswap_16(x)
125#define SWAP_BE32(x) bswap_32(x)
126#define SWAP_BE64(x) bswap_64(x)
127#define SWAP_LE16(x) x
128#define SWAP_LE32(x) x
129#define SWAP_LE64(x) x
130#endif
131
121/* ---- Networking ------------------------------------------ */ 132/* ---- Networking ------------------------------------------ */
122#ifndef __APPLE__ 133#ifndef __APPLE__
123# include <arpa/inet.h> 134# include <arpa/inet.h>
diff --git a/libbb/md5.c b/libbb/md5.c
index 584f5fe6f..58be40b6a 100644
--- a/libbb/md5.c
+++ b/libbb/md5.c
@@ -27,15 +27,6 @@
27# define MD5_SIZE_VS_SPEED CONFIG_MD5_SIZE_VS_SPEED 27# define MD5_SIZE_VS_SPEED CONFIG_MD5_SIZE_VS_SPEED
28# endif 28# endif
29 29
30/* Handle endian-ness */
31# if !BB_BIG_ENDIAN
32# define SWAP(n) (n)
33# elif defined(bswap_32)
34# define SWAP(n) bswap_32(n)
35# else
36# define SWAP(n) ((n << 24) | ((n&0xFF00)<<8) | ((n&0xFF0000)>>8) | (n>>24))
37# endif
38
39/* Initialize structure containing state of computation. 30/* Initialize structure containing state of computation.
40 * (RFC 1321, 3.3: Step 3) 31 * (RFC 1321, 3.3: Step 3)
41 */ 32 */
@@ -132,7 +123,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
132 uint32_t temp; 123 uint32_t temp;
133 124
134 for (i = 0; i < 16; i++) { 125 for (i = 0; i < 16; i++) {
135 cwp[i] = SWAP(words[i]); 126 cwp[i] = SWAP_LE32(words[i]);
136 } 127 }
137 words += 16; 128 words += 16;
138 129
@@ -224,7 +215,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
224# define OP(a, b, c, d, s, T) \ 215# define OP(a, b, c, d, s, T) \
225 do \ 216 do \
226 { \ 217 { \
227 a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ 218 a += FF (b, c, d) + (*cwp++ = SWAP_LE32(*words)) + T; \
228 ++words; \ 219 ++words; \
229 CYCLIC (a, s); \ 220 CYCLIC (a, s); \
230 a += b; \ 221 a += b; \
@@ -455,10 +446,10 @@ void *md5_end(void *resbuf, md5_ctx_t *ctx)
455 * IMPORTANT: On some systems it is required that RESBUF is correctly 446 * IMPORTANT: On some systems it is required that RESBUF is correctly
456 * aligned for a 32 bits value. 447 * aligned for a 32 bits value.
457 */ 448 */
458 ((uint32_t *) resbuf)[0] = SWAP(ctx->A); 449 ((uint32_t *) resbuf)[0] = SWAP_LE32(ctx->A);
459 ((uint32_t *) resbuf)[1] = SWAP(ctx->B); 450 ((uint32_t *) resbuf)[1] = SWAP_LE32(ctx->B);
460 ((uint32_t *) resbuf)[2] = SWAP(ctx->C); 451 ((uint32_t *) resbuf)[2] = SWAP_LE32(ctx->C);
461 ((uint32_t *) resbuf)[3] = SWAP(ctx->D); 452 ((uint32_t *) resbuf)[3] = SWAP_LE32(ctx->D);
462 453
463 return resbuf; 454 return resbuf;
464} 455}
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index ea73701c3..55ed2f6ff 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -26,7 +26,6 @@
26#include <getopt.h> 26#include <getopt.h>
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/hdreg.h> 28#include <linux/hdreg.h>
29#include <asm/byteorder.h>
30 29
31#if BB_BIG_ENDIAN && !defined(__USE_XOPEN) 30#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
32# define __USE_XOPEN 31# define __USE_XOPEN
@@ -2007,9 +2006,9 @@ static void process_dev(char *devname)
2007 args1[0] = WIN_IDENTIFY; 2006 args1[0] = WIN_IDENTIFY;
2008 args1[3] = 1; 2007 args1[3] = 1;
2009 if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) { 2008 if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) {
2010 for (i=0; i<(sizeof args1)/2; i+=2) 2009 uint16_t *ptr = (uint16_t *)args1;
2011 __le16_to_cpus((uint16_t *)(&args1[i])); 2010 for (i=0; i<sizeof(args1)/2; i++) ptr[i] = SWAP_LE16(ptr[i]);
2012 identify((void *)&args1[4]); 2011 identify((void *)(ptr+2));
2013 } 2012 }
2014 } 2013 }
2015#endif 2014#endif
@@ -2057,7 +2056,7 @@ static int fromhex(unsigned char c)
2057 2056
2058static void identify_from_stdin(void) 2057static void identify_from_stdin(void)
2059{ 2058{
2060 unsigned short sbuf[800]; 2059 uint16_t sbuf[800];
2061 unsigned char buf[1600], *b = (unsigned char *)buf; 2060 unsigned char buf[1600], *b = (unsigned char *)buf;
2062 int i, count = read(0, buf, 1280); 2061 int i, count = read(0, buf, 1280);
2063 2062
@@ -2066,8 +2065,7 @@ static void identify_from_stdin(void)
2066 2065
2067 for (i = 0; count >= 4; ++i) 2066 for (i = 0; count >= 4; ++i)
2068 { 2067 {
2069 sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]); 2068 sbuf[i] = SWAP_LE16((fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]));
2070 __le16_to_cpus((uint16_t *)(&sbuf[i]));
2071 b += 5; 2069 b += 5;
2072 count -= 5; 2070 count -= 5;
2073 } 2071 }