summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package/deps.mak27
-rw-r--r--src/headers/bits-bendian3
-rw-r--r--src/headers/bits-lendian5
-rw-r--r--src/headers/bits-template1
-rw-r--r--src/libstddjb/uint16_bswap.c9
-rw-r--r--src/libstddjb/uint16_pack.c7
-rw-r--r--src/libstddjb/uint16_pack_big.c7
-rw-r--r--src/libstddjb/uint16_reverse.c1
-rw-r--r--src/libstddjb/uint16_unpack.c8
-rw-r--r--src/libstddjb/uint16_unpack_big.c8
-rw-r--r--src/libstddjb/uint32_bswap.c13
-rw-r--r--src/libstddjb/uint32_pack.c9
-rw-r--r--src/libstddjb/uint32_pack_big.c9
-rw-r--r--src/libstddjb/uint32_reverse.c14
-rw-r--r--src/libstddjb/uint32_unpack.c10
-rw-r--r--src/libstddjb/uint32_unpack_big.c10
-rw-r--r--src/libstddjb/uint64_bswap.c16
-rw-r--r--src/libstddjb/uint64_pack.c12
-rw-r--r--src/libstddjb/uint64_pack_big.c12
-rw-r--r--src/libstddjb/uint64_reverse.c11
-rw-r--r--src/libstddjb/uint64_unpack.c14
-rw-r--r--src/libstddjb/uint64_unpack_big.c14
22 files changed, 121 insertions, 99 deletions
diff --git a/package/deps.mak b/package/deps.mak
index c8c0730..5caeaa4 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -627,37 +627,40 @@ src/libstddjb/ucharn_scan_little.o src/libstddjb/ucharn_scan_little.lo: src/libs
src/libstddjb/ucspi_get.o src/libstddjb/ucspi_get.lo: src/libstddjb/ucspi_get.c src/include/skalibs/env.h
src/libstddjb/uint160_fmt.o src/libstddjb/uint160_fmt.lo: src/libstddjb/uint160_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h
src/libstddjb/uint160_scan.o src/libstddjb/uint160_scan.lo: src/libstddjb/uint160_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h
+src/libstddjb/uint16_bswap.o src/libstddjb/uint16_bswap.lo: src/libstddjb/uint16_bswap.c src/include/skalibs/uint16.h
src/libstddjb/uint16_fmt.o src/libstddjb/uint16_fmt.lo: src/libstddjb/uint16_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h
src/libstddjb/uint16_fmtlist.o src/libstddjb/uint16_fmtlist.lo: src/libstddjb/uint16_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h
-src/libstddjb/uint16_pack.o src/libstddjb/uint16_pack.lo: src/libstddjb/uint16_pack.c src/include/skalibs/bytestr.h src/include/skalibs/uint16.h
-src/libstddjb/uint16_pack_big.o src/libstddjb/uint16_pack_big.lo: src/libstddjb/uint16_pack_big.c src/include/skalibs/bytestr.h src/include/skalibs/uint16.h
+src/libstddjb/uint16_pack.o src/libstddjb/uint16_pack.lo: src/libstddjb/uint16_pack.c src/include/skalibs/uint16.h
+src/libstddjb/uint16_pack_big.o src/libstddjb/uint16_pack_big.lo: src/libstddjb/uint16_pack_big.c src/include/skalibs/uint16.h
src/libstddjb/uint16_reverse.o src/libstddjb/uint16_reverse.lo: src/libstddjb/uint16_reverse.c src/include/skalibs/uint16.h
src/libstddjb/uint16_scan.o src/libstddjb/uint16_scan.lo: src/libstddjb/uint16_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h
src/libstddjb/uint16_scanlist.o src/libstddjb/uint16_scanlist.lo: src/libstddjb/uint16_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h
-src/libstddjb/uint16_unpack.o src/libstddjb/uint16_unpack.lo: src/libstddjb/uint16_unpack.c src/include/skalibs/bytestr.h src/include/skalibs/uint16.h
-src/libstddjb/uint16_unpack_big.o src/libstddjb/uint16_unpack_big.lo: src/libstddjb/uint16_unpack_big.c src/include/skalibs/bytestr.h src/include/skalibs/uint16.h
+src/libstddjb/uint16_unpack.o src/libstddjb/uint16_unpack.lo: src/libstddjb/uint16_unpack.c src/include/skalibs/uint16.h
+src/libstddjb/uint16_unpack_big.o src/libstddjb/uint16_unpack_big.lo: src/libstddjb/uint16_unpack_big.c src/include/skalibs/uint16.h
src/libstddjb/uint320_fmt.o src/libstddjb/uint320_fmt.lo: src/libstddjb/uint320_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h
src/libstddjb/uint320_scan.o src/libstddjb/uint320_scan.lo: src/libstddjb/uint320_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h
+src/libstddjb/uint32_bswap.o src/libstddjb/uint32_bswap.lo: src/libstddjb/uint32_bswap.c src/include/skalibs/uint32.h
src/libstddjb/uint32_fmt.o src/libstddjb/uint32_fmt.lo: src/libstddjb/uint32_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h
src/libstddjb/uint32_fmtlist.o src/libstddjb/uint32_fmtlist.lo: src/libstddjb/uint32_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h
-src/libstddjb/uint32_pack.o src/libstddjb/uint32_pack.lo: src/libstddjb/uint32_pack.c src/include/skalibs/bytestr.h src/include/skalibs/uint32.h
-src/libstddjb/uint32_pack_big.o src/libstddjb/uint32_pack_big.lo: src/libstddjb/uint32_pack_big.c src/include/skalibs/bytestr.h src/include/skalibs/uint32.h
+src/libstddjb/uint32_pack.o src/libstddjb/uint32_pack.lo: src/libstddjb/uint32_pack.c src/include/skalibs/uint32.h
+src/libstddjb/uint32_pack_big.o src/libstddjb/uint32_pack_big.lo: src/libstddjb/uint32_pack_big.c src/include/skalibs/uint32.h
src/libstddjb/uint32_reverse.o src/libstddjb/uint32_reverse.lo: src/libstddjb/uint32_reverse.c src/include/skalibs/uint32.h
src/libstddjb/uint32_scan.o src/libstddjb/uint32_scan.lo: src/libstddjb/uint32_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h
src/libstddjb/uint32_scanlist.o src/libstddjb/uint32_scanlist.lo: src/libstddjb/uint32_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h
-src/libstddjb/uint32_unpack.o src/libstddjb/uint32_unpack.lo: src/libstddjb/uint32_unpack.c src/include/skalibs/bytestr.h src/include/skalibs/uint32.h
-src/libstddjb/uint32_unpack_big.o src/libstddjb/uint32_unpack_big.lo: src/libstddjb/uint32_unpack_big.c src/include/skalibs/bytestr.h src/include/skalibs/uint32.h
+src/libstddjb/uint32_unpack.o src/libstddjb/uint32_unpack.lo: src/libstddjb/uint32_unpack.c src/include/skalibs/uint32.h
+src/libstddjb/uint32_unpack_big.o src/libstddjb/uint32_unpack_big.lo: src/libstddjb/uint32_unpack_big.c src/include/skalibs/uint32.h
src/libstddjb/uint640_fmt.o src/libstddjb/uint640_fmt.lo: src/libstddjb/uint640_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h
src/libstddjb/uint640_scan.o src/libstddjb/uint640_scan.lo: src/libstddjb/uint640_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h
+src/libstddjb/uint64_bswap.o src/libstddjb/uint64_bswap.lo: src/libstddjb/uint64_bswap.c src/include/skalibs/uint64.h
src/libstddjb/uint64_fmt.o src/libstddjb/uint64_fmt.lo: src/libstddjb/uint64_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h
src/libstddjb/uint64_fmtlist.o src/libstddjb/uint64_fmtlist.lo: src/libstddjb/uint64_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h
-src/libstddjb/uint64_pack.o src/libstddjb/uint64_pack.lo: src/libstddjb/uint64_pack.c src/include/skalibs/bytestr.h src/include/skalibs/uint64.h
-src/libstddjb/uint64_pack_big.o src/libstddjb/uint64_pack_big.lo: src/libstddjb/uint64_pack_big.c src/include/skalibs/bytestr.h src/include/skalibs/uint64.h
+src/libstddjb/uint64_pack.o src/libstddjb/uint64_pack.lo: src/libstddjb/uint64_pack.c src/include/skalibs/uint64.h
+src/libstddjb/uint64_pack_big.o src/libstddjb/uint64_pack_big.lo: src/libstddjb/uint64_pack_big.c src/include/skalibs/uint64.h
src/libstddjb/uint64_reverse.o src/libstddjb/uint64_reverse.lo: src/libstddjb/uint64_reverse.c src/include/skalibs/uint64.h
src/libstddjb/uint64_scan.o src/libstddjb/uint64_scan.lo: src/libstddjb/uint64_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h
src/libstddjb/uint64_scanlist.o src/libstddjb/uint64_scanlist.lo: src/libstddjb/uint64_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h
-src/libstddjb/uint64_unpack.o src/libstddjb/uint64_unpack.lo: src/libstddjb/uint64_unpack.c src/include/skalibs/bytestr.h src/include/skalibs/uint64.h
-src/libstddjb/uint64_unpack_big.o src/libstddjb/uint64_unpack_big.lo: src/libstddjb/uint64_unpack_big.c src/include/skalibs/bytestr.h src/include/skalibs/uint64.h
+src/libstddjb/uint64_unpack.o src/libstddjb/uint64_unpack.lo: src/libstddjb/uint64_unpack.c src/include/skalibs/uint64.h
+src/libstddjb/uint64_unpack_big.o src/libstddjb/uint64_unpack_big.lo: src/libstddjb/uint64_unpack_big.c src/include/skalibs/uint64.h
src/libstddjb/uncoe.o src/libstddjb/uncoe.lo: src/libstddjb/uncoe.c src/include/skalibs/djbunix.h
src/libstddjb/unsanitize_read.o src/libstddjb/unsanitize_read.lo: src/libstddjb/unsanitize_read.c src/include/skalibs/allreadwrite.h src/include/skalibs/error.h
src/libstddjb/utc_from_localtm.o src/libstddjb/utc_from_localtm.lo: src/libstddjb/utc_from_localtm.c src/include/skalibs/djbtime.h src/include/skalibs/uint64.h
diff --git a/src/headers/bits-bendian b/src/headers/bits-bendian
index ef57f58..6caf1e7 100644
--- a/src/headers/bits-bendian
+++ b/src/headers/bits-bendian
@@ -1,3 +1,6 @@
#define uint@BITS@_little_endian(s, n) uint@BITS@_reverse((s), (n))
#define uint@BITS@_big_endian(s, n)
+#define uint@BITS@_little(u) uint@BITS@_bswap(u)
+#define uint@BITS@_big(u) (u)
+
diff --git a/src/headers/bits-lendian b/src/headers/bits-lendian
index 278af3e..7528d46 100644
--- a/src/headers/bits-lendian
+++ b/src/headers/bits-lendian
@@ -1,3 +1,6 @@
#define uint@BITS@_little_endian(s, n)
-#define uint@BITS@_big_endian(s, n) uint16_reverse((s), (n))
+#define uint@BITS@_big_endian(s, n) uint@BITS@_reverse((s), (n))
+
+#define uint@BITS@_little(u) (u)
+#define uint@BITS@_big(u) uint@BITS@_bswap(u)
diff --git a/src/headers/bits-template b/src/headers/bits-template
index 4b43de2..b09036b 100644
--- a/src/headers/bits-template
+++ b/src/headers/bits-template
@@ -3,6 +3,7 @@ extern void uint@BITS@_pack_big (char *, uint@BITS@_t) ;
extern void uint@BITS@_unpack (char const *, uint@BITS@_t *) ;
extern void uint@BITS@_unpack_big (char const *, uint@BITS@_t *) ;
extern void uint@BITS@_reverse (char *, size_t) ;
+extern uint@BITS@_t uint@BITS@_bswap (uint@BITS@_t) ;
#define UINT@BITS@_FMT @DFMT@
#define UINT@BITS@_OFMT @OFMT@
diff --git a/src/libstddjb/uint16_bswap.c b/src/libstddjb/uint16_bswap.c
new file mode 100644
index 0000000..6ab96ed
--- /dev/null
+++ b/src/libstddjb/uint16_bswap.c
@@ -0,0 +1,9 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <skalibs/uint16.h>
+
+uint16_t uint16_bswap (uint16_t a)
+{
+ return (a & 0x00ffu) << 8 | (a & 0xff00u) >> 8 ;
+}
diff --git a/src/libstddjb/uint16_pack.c b/src/libstddjb/uint16_pack.c
index de0a09b..e7ffe24 100644
--- a/src/libstddjb/uint16_pack.c
+++ b/src/libstddjb/uint16_pack.c
@@ -1,10 +1,11 @@
/* ISC license. */
+#include <stdint.h>
+#include <string.h>
#include <skalibs/uint16.h>
-#include <skalibs/bytestr.h>
void uint16_pack (char *s, uint16_t u)
{
- ((unsigned char *)s)[0] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[1] = T8(u) ;
+ u = uint16_little(u) ;
+ memcpy(s, &u, sizeof(uint16_t)) ;
}
diff --git a/src/libstddjb/uint16_pack_big.c b/src/libstddjb/uint16_pack_big.c
index f73f88b..c24f78f 100644
--- a/src/libstddjb/uint16_pack_big.c
+++ b/src/libstddjb/uint16_pack_big.c
@@ -1,10 +1,11 @@
/* ISC license. */
+#include <stdint.h>
+#include <string.h>
#include <skalibs/uint16.h>
-#include <skalibs/bytestr.h>
void uint16_pack_big (char *s, uint16_t u)
{
- ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[0] = T8(u) ;
+ u = uint16_big(u) ;
+ memcpy(s, &u, sizeof(uint16_t)) ;
}
diff --git a/src/libstddjb/uint16_reverse.c b/src/libstddjb/uint16_reverse.c
index b4fe2c8..4fa0a7b 100644
--- a/src/libstddjb/uint16_reverse.c
+++ b/src/libstddjb/uint16_reverse.c
@@ -1,5 +1,6 @@
/* ISC license. */
+#include <string.h>
#include <skalibs/uint16.h>
void uint16_reverse (char *s, size_t n)
diff --git a/src/libstddjb/uint16_unpack.c b/src/libstddjb/uint16_unpack.c
index 1497671..ea31ebc 100644
--- a/src/libstddjb/uint16_unpack.c
+++ b/src/libstddjb/uint16_unpack.c
@@ -1,12 +1,12 @@
/* ISC license. */
#include <stdint.h>
+#include <string.h>
#include <skalibs/uint16.h>
-#include <skalibs/bytestr.h>
void uint16_unpack (char const *s, uint16_t *u)
{
- uint16_t r = T8((unsigned char)s[1]) ; r <<= 8 ;
- r += T8((unsigned char)s[0]) ;
- *u = r ;
+ uint16_t x ;
+ memcpy(&x, s, sizeof(uint16_t)) ;
+ *u = uint16_little(x) ;
}
diff --git a/src/libstddjb/uint16_unpack_big.c b/src/libstddjb/uint16_unpack_big.c
index 73b94da..3f6f0df 100644
--- a/src/libstddjb/uint16_unpack_big.c
+++ b/src/libstddjb/uint16_unpack_big.c
@@ -1,12 +1,12 @@
/* ISC license. */
#include <stdint.h>
+#include <string.h>
#include <skalibs/uint16.h>
-#include <skalibs/bytestr.h>
void uint16_unpack_big (char const *s, uint16_t *u)
{
- uint16_t r = T8((unsigned char)s[0]) ; r <<= 8 ;
- r += T8((unsigned char)s[1]) ;
- *u = r ;
+ uint16_t x ;
+ memcpy(&x, s, sizeof(uint16_t)) ;
+ *u = uint16_big(x) ;
}
diff --git a/src/libstddjb/uint32_bswap.c b/src/libstddjb/uint32_bswap.c
new file mode 100644
index 0000000..b9dbcab
--- /dev/null
+++ b/src/libstddjb/uint32_bswap.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <skalibs/uint32.h>
+
+uint32_t uint32_bswap (uint32_t a)
+{
+ return
+ (a & 0x000000ffu) << 24 |
+ (a & 0x0000ff00u) << 8 |
+ (a & 0x00ff0000u) >> 8 |
+ (a & 0xff000000u) >> 24 ;
+}
diff --git a/src/libstddjb/uint32_pack.c b/src/libstddjb/uint32_pack.c
index a5320e0..a06ccf1 100644
--- a/src/libstddjb/uint32_pack.c
+++ b/src/libstddjb/uint32_pack.c
@@ -1,12 +1,11 @@
/* ISC license. */
+#include <stdint.h>
+#include <string.h>
#include <skalibs/uint32.h>
-#include <skalibs/bytestr.h>
void uint32_pack (char *s, uint32_t u)
{
- ((unsigned char *)s)[0] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[2] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[3] = T8(u) ;
+ u = uint32_little(u) ;
+ memcpy(s, &u, sizeof(uint32_t)) ;
}
diff --git a/src/libstddjb/uint32_pack_big.c b/src/libstddjb/uint32_pack_big.c
index 2a17a7b..e861e7e 100644
--- a/src/libstddjb/uint32_pack_big.c
+++ b/src/libstddjb/uint32_pack_big.c
@@ -1,12 +1,11 @@
/* ISC license. */
+#include <stdint.h>
+#include <string.h>
#include <skalibs/uint32.h>
-#include <skalibs/bytestr.h>
void uint32_pack_big (char *s, uint32_t u)
{
- ((unsigned char *)s)[3] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[2] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[0] = T8(u) ;
+ u = uint32_big(u) ;
+ memcpy(s, &u, sizeof(uint32_t)) ;
}
diff --git a/src/libstddjb/uint32_reverse.c b/src/libstddjb/uint32_reverse.c
index 51c9877..2d3f915 100644
--- a/src/libstddjb/uint32_reverse.c
+++ b/src/libstddjb/uint32_reverse.c
@@ -1,17 +1,17 @@
/* ISC license. */
+#include <stdint.h>
+#include <string.h>
#include <skalibs/uint32.h>
void uint32_reverse (char *s, size_t n)
{
while (n--)
{
- char c = s[0] ;
- s[0] = s[3] ;
- s[3] = c ;
- c = s[1] ;
- s[1] = s[2] ;
- s[2] = c ;
- s += 4 ;
+ uint32_t x ;
+ memcpy(&x, s, sizeof(uint32_t)) ;
+ x = uint32_bswap(x) ;
+ memcpy(s, &x, sizeof(uint32_t)) ;
+ s += sizeof(uint32_t) ;
}
}
diff --git a/src/libstddjb/uint32_unpack.c b/src/libstddjb/uint32_unpack.c
index a9cabbb..78aca79 100644
--- a/src/libstddjb/uint32_unpack.c
+++ b/src/libstddjb/uint32_unpack.c
@@ -1,14 +1,12 @@
/* ISC license. */
#include <stdint.h>
+#include <string.h>
#include <skalibs/uint32.h>
-#include <skalibs/bytestr.h>
void uint32_unpack (char const *s, uint32_t *u)
{
- uint32_t r = T8((unsigned char)s[3]) ; r <<= 8 ;
- r += T8((unsigned char)s[2]) ; r <<= 8 ;
- r += T8((unsigned char)s[1]) ; r <<= 8 ;
- r += T8((unsigned char)s[0]) ;
- *u = r ;
+ uint32_t x ;
+ memcpy(&x, s, sizeof(uint32_t)) ;
+ *u = uint32_little(x) ;
}
diff --git a/src/libstddjb/uint32_unpack_big.c b/src/libstddjb/uint32_unpack_big.c
index defde56..307141f 100644
--- a/src/libstddjb/uint32_unpack_big.c
+++ b/src/libstddjb/uint32_unpack_big.c
@@ -1,14 +1,12 @@
/* ISC license. */
#include <stdint.h>
+#include <string.h>
#include <skalibs/uint32.h>
-#include <skalibs/bytestr.h>
void uint32_unpack_big (char const *s, uint32_t *u)
{
- uint32_t r = T8((unsigned char)s[0]) ; r <<= 8 ;
- r += T8((unsigned char)s[1]) ; r <<= 8 ;
- r += T8((unsigned char)s[2]) ; r <<= 8 ;
- r += T8((unsigned char)s[3]) ;
- *u = r ;
+ uint32_t x ;
+ memcpy(&x, s, sizeof(uint32_t)) ;
+ *u = uint32_big(x) ;
}
diff --git a/src/libstddjb/uint64_bswap.c b/src/libstddjb/uint64_bswap.c
new file mode 100644
index 0000000..3dfaf18
--- /dev/null
+++ b/src/libstddjb/uint64_bswap.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include <skalibs/uint64.h>
+
+uint64_t uint64_bswap (uint64_t a)
+{
+ return
+ (a & 0x00000000000000ffull) << 56 |
+ (a & 0x000000000000ff00ull) << 40 |
+ (a & 0x0000000000ff0000ull) << 24 |
+ (a & 0x00000000ff000000ull) << 8 |
+ (a & 0x000000ff00000000ull) >> 8 |
+ (a & 0x0000ff0000000000ull) >> 24 |
+ (a & 0x00ff000000000000ull) >> 40 |
+ (a & 0xff00000000000000ull) >> 56 ;
+}
diff --git a/src/libstddjb/uint64_pack.c b/src/libstddjb/uint64_pack.c
index 5559a90..18033da 100644
--- a/src/libstddjb/uint64_pack.c
+++ b/src/libstddjb/uint64_pack.c
@@ -1,16 +1,10 @@
/* ISC license. */
+#include <string.h>
#include <skalibs/uint64.h>
-#include <skalibs/bytestr.h>
void uint64_pack (char *s, uint64_t u)
{
- ((unsigned char *)s)[0] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[2] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[3] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[4] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[5] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[6] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[7] = T8(u) ;
+ u = uint64_little(u) ;
+ memcpy(s, &u, sizeof(uint64_t)) ;
}
diff --git a/src/libstddjb/uint64_pack_big.c b/src/libstddjb/uint64_pack_big.c
index 381f105..c0bbcd7 100644
--- a/src/libstddjb/uint64_pack_big.c
+++ b/src/libstddjb/uint64_pack_big.c
@@ -1,16 +1,10 @@
/* ISC license. */
+#include <string.h>
#include <skalibs/uint64.h>
-#include <skalibs/bytestr.h>
void uint64_pack_big (char *s, uint64_t u)
{
- ((unsigned char *)s)[7] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[6] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[5] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[4] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[3] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[2] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ;
- ((unsigned char *)s)[0] = T8(u) ;
+ u = uint64_big(u) ;
+ memcpy(s, &u, sizeof(uint64_t)) ;
}
diff --git a/src/libstddjb/uint64_reverse.c b/src/libstddjb/uint64_reverse.c
index 5a616f5..a870b31 100644
--- a/src/libstddjb/uint64_reverse.c
+++ b/src/libstddjb/uint64_reverse.c
@@ -1,15 +1,16 @@
/* ISC license. */
+#include <string.h>
#include <skalibs/uint64.h>
void uint64_reverse (char *s, size_t n)
{
while (n--)
{
- char c = s[0] ; s[0] = s[7] ; s[7] = c ;
- c = s[1] ; s[1] = s[6] ; s[6] = c ;
- c = s[2] ; s[2] = s[5] ; s[5] = c ;
- c = s[3] ; s[3] = s[4] ; s[4] = c ;
- s += 8 ;
+ uint64_t x ;
+ memcpy(&x, s, sizeof(uint64_t)) ;
+ x = uint64_bswap(x) ;
+ memcpy(s, &x, sizeof(uint64_t)) ;
+ s += sizeof(uint64_t) ;
}
}
diff --git a/src/libstddjb/uint64_unpack.c b/src/libstddjb/uint64_unpack.c
index 452d3ea..ca7aad9 100644
--- a/src/libstddjb/uint64_unpack.c
+++ b/src/libstddjb/uint64_unpack.c
@@ -1,17 +1,11 @@
/* ISC license. */
+#include <string.h>
#include <skalibs/uint64.h>
-#include <skalibs/bytestr.h>
void uint64_unpack (char const *s, uint64_t *u)
{
- uint64_t r = T8((unsigned char)s[7]) ; r <<= 8 ;
- r += T8((unsigned char)s[6]) ; r <<= 8 ;
- r += T8((unsigned char)s[5]) ; r <<= 8 ;
- r += T8((unsigned char)s[4]) ; r <<= 8 ;
- r += T8((unsigned char)s[3]) ; r <<= 8 ;
- r += T8((unsigned char)s[2]) ; r <<= 8 ;
- r += T8((unsigned char)s[1]) ; r <<= 8 ;
- r += T8((unsigned char)s[0]) ;
- *u = r ;
+ uint64_t x ;
+ memcpy(&x, s, sizeof(uint64_t)) ;
+ *u = uint64_little(x) ;
}
diff --git a/src/libstddjb/uint64_unpack_big.c b/src/libstddjb/uint64_unpack_big.c
index 3554dcc..f4e7d52 100644
--- a/src/libstddjb/uint64_unpack_big.c
+++ b/src/libstddjb/uint64_unpack_big.c
@@ -1,17 +1,11 @@
/* ISC license. */
+#include <string.h>
#include <skalibs/uint64.h>
-#include <skalibs/bytestr.h>
void uint64_unpack_big (char const *s, uint64_t *u)
{
- uint64_t r = T8((unsigned char)s[0]) ; r <<= 8 ;
- r += T8((unsigned char)s[1]) ; r <<= 8 ;
- r += T8((unsigned char)s[2]) ; r <<= 8 ;
- r += T8((unsigned char)s[3]) ; r <<= 8 ;
- r += T8((unsigned char)s[4]) ; r <<= 8 ;
- r += T8((unsigned char)s[5]) ; r <<= 8 ;
- r += T8((unsigned char)s[6]) ; r <<= 8 ;
- r += T8((unsigned char)s[7]) ;
- *u = r ;
+ uint64_t x ;
+ memcpy(&x, s, sizeof(uint64_t)) ;
+ *u = uint64_big(x) ;
}