Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move the 16/32-bit encode/decode to/from octet stream ro...



details:   https://anonhg.NetBSD.org/src/rev/96a9a31d19a0
branches:  trunk
changeset: 569901:96a9a31d19a0
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Sep 12 23:17:37 2004 +0000

description:
Move the 16/32-bit encode/decode to/from octet stream routines from
kern_uuid.c to sys/endian.h (where FreeBSD has them), and add 64-bit
variants.

diffstat:

 sys/kern/kern_uuid.c |   76 +---------------------------------
 sys/sys/endian.h     |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 114 insertions(+), 75 deletions(-)

diffs (224 lines):

diff -r 1c3fd71f0e08 -r 96a9a31d19a0 sys/kern/kern_uuid.c
--- a/sys/kern/kern_uuid.c      Sun Sep 12 22:52:58 2004 +0000
+++ b/sys/kern/kern_uuid.c      Sun Sep 12 23:17:37 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_uuid.c,v 1.2 2004/08/30 02:56:03 thorpej Exp $    */
+/*     $NetBSD: kern_uuid.c,v 1.3 2004/09/12 23:17:37 thorpej Exp $    */
 
 /*
  * Copyright (c) 2002 Marcel Moolenaar
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_uuid.c,v 1.2 2004/08/30 02:56:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_uuid.c,v 1.3 2004/09/12 23:17:37 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/endian.h>
@@ -255,78 +255,6 @@
  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 
-static void
-be16enc(void *buf, uint16_t u)
-{
-       uint8_t *p = buf;
-
-       p[0] = (u >> 8) & 0xff;
-       p[1] = u & 0xff;
-}
-
-static void
-le16enc(void *buf, uint16_t u)
-{
-       uint8_t *p = buf;
-
-       p[0] = u & 0xff;
-       p[1] = (u >> 8) & 0xff;
-}
-
-static uint16_t
-be16dec(const void *buf)
-{
-       const uint8_t *p = buf;
-
-       return ((p[0] << 8) | p[1]);
-}
-
-static uint16_t
-le16dec(const void *buf)
-{
-       const uint8_t *p = buf;
-
-       return ((p[1] << 8) | p[0]);
-}
-
-static void
-be32enc(void *buf, uint32_t u)
-{
-       uint8_t *p = buf;
-
-       p[0] = (u >> 24) & 0xff;
-       p[1] = (u >> 16) & 0xff;
-       p[2] = (u >> 8) & 0xff;
-       p[3] = u & 0xff;
-}
-
-static void
-le32enc(void *buf, uint32_t u)
-{
-       uint8_t *p = buf;
-
-       p[0] = u & 0xff;
-       p[1] = (u >> 8) & 0xff;
-       p[2] = (u >> 16) & 0xff;
-       p[3] = (u >> 24) & 0xff;
-}
-
-static uint32_t
-be32dec(const void *buf)
-{
-       const uint8_t *p = buf;
-
-       return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
-}
-
-static uint32_t
-le32dec(const void *buf)
-{
-       const uint8_t *p = buf;
-
-       return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
-}
-
 void
 uuid_enc_le(void *buf, const struct uuid *uuid)
 {
diff -r 1c3fd71f0e08 -r 96a9a31d19a0 sys/sys/endian.h
--- a/sys/sys/endian.h  Sun Sep 12 22:52:58 2004 +0000
+++ b/sys/sys/endian.h  Sun Sep 12 23:17:37 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: endian.h,v 1.9 2004/09/12 22:52:58 thorpej Exp $       */
+/*     $NetBSD: endian.h,v 1.10 2004/09/12 23:17:37 thorpej Exp $      */
 
 /*
  * Copyright (c) 1987, 1991, 1993
@@ -171,6 +171,117 @@
 #define LE32TOH(x)     HTOLE32(x)
 #define LE64TOH(x)     HTOLE64(x)
 
+/*
+ * Routines to encode/decode big- and little-endian multi-octet values
+ * to/from an octet stream.
+ */
+
+static __inline void __unused
+be16enc(void *buf, uint16_t u)
+{
+       uint8_t *p = buf;
+
+       p[0] = (u >> 8) & 0xff;
+       p[1] = u & 0xff;
+}
+
+static __inline void __unused
+le16enc(void *buf, uint16_t u)
+{
+       uint8_t *p = buf;
+
+       p[0] = u & 0xff;
+       p[1] = (u >> 8) & 0xff;
+}
+
+static __inline uint16_t __unused
+be16dec(const void *buf)
+{
+       const uint8_t *p = buf;
+
+       return ((p[0] << 8) | p[1]);
+}
+
+static __inline uint16_t __unused
+le16dec(const void *buf)
+{
+       const uint8_t *p = buf;
+
+       return ((p[1] << 8) | p[0]);
+}
+
+static __inline void __unused
+be32enc(void *buf, uint32_t u)
+{
+       uint8_t *p = buf;
+
+       p[0] = (u >> 24) & 0xff;
+       p[1] = (u >> 16) & 0xff;
+       p[2] = (u >> 8) & 0xff;
+       p[3] = u & 0xff;
+}
+
+static __inline void __unused
+le32enc(void *buf, uint32_t u)
+{
+       uint8_t *p = buf;
+
+       p[0] = u & 0xff;
+       p[1] = (u >> 8) & 0xff;
+       p[2] = (u >> 16) & 0xff;
+       p[3] = (u >> 24) & 0xff;
+}
+
+static __inline uint32_t __unused
+be32dec(const void *buf)
+{
+       const uint8_t *p = buf;
+
+       return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+
+static __inline uint32_t __unused
+le32dec(const void *buf)
+{
+       const uint8_t *p = buf;
+
+       return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+}
+
+static __inline void __unused
+be64enc(void *buf, uint64_t u)
+{
+       uint8_t *p = buf;
+
+       be32enc(p, u >> 32);
+       be32enc(p + 4, u & 0xffffffffU);
+}
+
+static __inline void __unused
+le64enc(void *buf, uint64_t u)
+{
+       uint8_t *p = buf;
+
+       le32enc(p, u & 0xffffffffU);
+       le32enc(p + 4, u >> 32);
+}
+
+static __inline uint64_t __unused
+be64dec(const void *buf)
+{
+       const uint8_t *p = buf;
+
+       return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
+}
+
+static __inline uint64_t __unused
+le64dec(const void *buf)
+{
+       const uint8_t *p = buf;
+
+       return (le32dec(p) | ((uint64_t)le32dec(p + 4) << 32));
+}
+
 #endif /* !_LOCORE */
 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
 #endif /* !_SYS_ENDIAN_H_ */



Home | Main Index | Thread Index | Old Index