]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
htole64() etc for systems without endian.h
authorDamien Miller <djm@mindrot.org>
Sun, 27 Oct 2024 02:28:11 +0000 (13:28 +1100)
committerDamien Miller <djm@mindrot.org>
Sun, 27 Oct 2024 04:36:30 +0000 (15:36 +1100)
configure.ac
defines.h

index 591d5a3880c59c23074fe58f2eb580ff4d71938c..9053a9a2bc9373444d4f7f28ad54fd91d910147f 100644 (file)
@@ -2013,7 +2013,6 @@ AC_CHECK_FUNCS([ \
        strtoll \
        strtoul \
        strtoull \
-       swap32 \
        sysconf \
        tcgetpgrp \
        timegm \
index ed860e78bba0c9fc551d373e1051b4135cc35139..b02f2942a9b560040a431b303aaca0641c509924 100644 (file)
--- a/defines.h
+++ b/defines.h
@@ -646,6 +646,32 @@ struct winsize {
 # endif /* WORDS_BIGENDIAN */
 #endif /* BYTE_ORDER */
 
+#ifndef HAVE_ENDIAN_H
+# define openssh_swap32(v)                                     \
+       (uint32_t)(((uint32_t)(v) & 0xff) << 24 |               \
+       ((uint32_t)(v) & 0xff00) << 8 |                         \
+       ((uint32_t)(v) & 0xff0000) >> 8 |                       \
+       ((uint32_t)(v) & 0xff000000) >> 24)
+# define openssh_swap64(v)                                     \
+       (__uint64_t)((((__uint64_t)(v) & 0xff) << 56) |         \
+       ((__uint64_t)(v) & 0xff00ULL) << 40 |                   \
+       ((__uint64_t)(v) & 0xff0000ULL) << 24 |                 \
+       ((__uint64_t)(v) & 0xff000000ULL) << 8 |                \
+       ((__uint64_t)(v) & 0xff00000000ULL) >> 8 |              \
+       ((__uint64_t)(v) & 0xff0000000000ULL) >> 24 |           \
+       ((__uint64_t)(v) & 0xff000000000000ULL) >> 40 |         \
+       ((__uint64_t)(v) & 0xff00000000000000ULL) >> 56)
+# ifdef WORDS_BIGENDIAN
+#  define le32toh(v) (openssh_swap32(v))
+#  define le64toh(v) (openssh_swap64(v))
+#  define htole64(v) (openssh_swap64(v))
+# else
+#  define le32toh(v) ((uint32_t)v)
+#  define le64toh(v) ((uint64_t)v)
+#  define htole64(v) ((uint64_t)v)
+# endif
+#endif
+
 /* Function replacement / compatibility hacks */
 
 #if !defined(HAVE_GETADDRINFO) && (defined(HAVE_OGETADDRINFO) || defined(HAVE_NGETADDRINFO))