Skip to content

Commit 4b8d141

Browse files
committed
Check for le32toh, le64toh, htole64 individually.
It appears that at least some versions of endian.h in glibc do not have the latter two, so check for and replace each one individually. bz#3794, ok djm@
1 parent d76b267 commit 4b8d141

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,18 @@ AC_CHECK_HEADERS([ \
536536
wchar.h \
537537
])
538538

539+
AC_CHECK_DECLS([le32toh, le64toh, htole64], [], [], [
540+
#ifdef HAVE_SYS_TYPES_H
541+
# include <sys/types.h>
542+
#endif
543+
#ifdef HAVE_STDINT_H
544+
# include <stdint.h>
545+
#endif
546+
#ifdef HAVE_ENDIAN_H
547+
# include <endian.h>
548+
#endif
549+
])
550+
539551
# On some platforms (eg SunOS4) sys/audit.h requires sys/[time|types|label.h]
540552
# to be included first.
541553
AC_CHECK_HEADERS([sys/audit.h], [], [], [

defines.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,9 @@ struct winsize {
646646
# endif /* WORDS_BIGENDIAN */
647647
#endif /* BYTE_ORDER */
648648

649-
#ifndef HAVE_ENDIAN_H
649+
#if (defined(HAVE_DECL_LE32TOH) && HAVE_DECL_LE32TOH == 0) || \
650+
(defined(HAVE_DECL_LE64TOH) && HAVE_DECL_LE64TOH == 0) || \
651+
(defined(HAVE_DECL_HTOLE64) && HAVE_DECL_HTOLE64 == 0)
650652
# define openssh_swap32(v) \
651653
(uint32_t)(((uint32_t)(v) & 0xff) << 24 | \
652654
((uint32_t)(v) & 0xff00) << 8 | \
@@ -662,13 +664,25 @@ struct winsize {
662664
((uint64_t)(v) & 0xff000000000000ULL) >> 40 | \
663665
((uint64_t)(v) & 0xff00000000000000ULL) >> 56)
664666
# ifdef WORDS_BIGENDIAN
665-
# define le32toh(v) (openssh_swap32(v))
666-
# define le64toh(v) (openssh_swap64(v))
667-
# define htole64(v) (openssh_swap64(v))
667+
# if defined(HAVE_DECL_LE32TOH) && HAVE_DECL_LE32TOH == 0
668+
# define le32toh(v) (openssh_swap32(v))
669+
# endif
670+
# if defined(HAVE_DECL_LE64TOH) && HAVE_DECL_LE64TOH == 0
671+
# define le64toh(v) (openssh_swap64(v))
672+
# endif
673+
# if defined(HAVE_DECL_HTOLE64) && HAVE_DECL_HTOLE64 == 0
674+
# define htole64(v) (openssh_swap64(v))
675+
# endif
668676
# else
669-
# define le32toh(v) ((uint32_t)v)
670-
# define le64toh(v) ((uint64_t)v)
671-
# define htole64(v) ((uint64_t)v)
677+
# if defined(HAVE_DECL_LE32TOH) && HAVE_DECL_LE32TOH == 0
678+
# define le32toh(v) ((uint32_t)v)
679+
# endif
680+
# if defined(HAVE_DECL_LE64TOH) && HAVE_DECL_LE64TOH == 0
681+
# define le64toh(v) ((uint64_t)v)
682+
# endif
683+
# if defined(HAVE_DECL_HTOLE64) && HAVE_DECL_HTOLE64 == 0
684+
# define htole64(v) ((uint64_t)v)
685+
# endif
672686
# endif
673687
#endif
674688

0 commit comments

Comments
 (0)