Skip to content

Commit

Permalink
htole64() etc for systems without endian.h
Browse files Browse the repository at this point in the history
  • Loading branch information
djmdjm committed Oct 27, 2024
1 parent 0c3927c commit ef7c26c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,6 @@ AC_CHECK_FUNCS([ \
strtoll \
strtoul \
strtoull \
swap32 \
sysconf \
tcgetpgrp \
timegm \
Expand Down
26 changes: 26 additions & 0 deletions defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ef7c26c

Please sign in to comment.