Skip to content

Commit e6a4f08

Browse files
committed
Added supports byteswap.h and sys/bswap.h
1 parent 3ebe9bf commit e6a4f08

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

Zend/zend_portability.h

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -812,23 +812,34 @@ typedef union {
812812
#endif
813813

814814
/* Bytes swap */
815-
#ifdef _MSC_VER
816-
# include <stdlib.h>
817-
# define ZEND_BYTES_SWAP32(u) _byteswap_ulong(u)
818-
# define ZEND_BYTES_SWAP64(u) _byteswap_uint64(u)
819-
#else
820-
# ifdef __GNUC__
821-
# define ZEND_BYTES_SWAP32(u) __builtin_bswap32(u)
822-
# define ZEND_BYTES_SWAP64(u) __builtin_bswap64(u)
823-
# elif defined(__has_builtin)
824-
# if __has_builtin(__builtin_bswap32)
815+
#ifdef HAVE_BYTESWAP_H
816+
# include <byteswap.h>
817+
# define ZEND_BYTES_SWAP32(u) bswap_32(u)
818+
# define ZEND_BYTES_SWAP64(u) bswap_64(u)
819+
#elif defined(HAVE_SYS_BSWAP_H)
820+
# include <sys/bswap.h>
821+
# define ZEND_BYTES_SWAP32(u) bswap32(u)
822+
# define ZEND_BYTES_SWAP64(u) bswap64(u)
823+
#else
824+
# ifdef _MSC_VER
825+
# include <stdlib.h>
826+
# define ZEND_BYTES_SWAP32(u) _byteswap_ulong(u)
827+
# define ZEND_BYTES_SWAP64(u) _byteswap_uint64(u)
828+
# else
829+
# ifdef __GNUC__
825830
# define ZEND_BYTES_SWAP32(u) __builtin_bswap32(u)
826-
# endif // __has_builtin(__builtin_bswap32)
827-
# if __has_builtin(__builtin_bswap64)
828831
# define ZEND_BYTES_SWAP64(u) __builtin_bswap64(u)
829-
# endif // __has_builtin(__builtin_bswap64)
830-
# endif // __GNUC__
831-
#endif // _MSC_VER
832+
# elif defined(__has_builtin)
833+
# if __has_builtin(__builtin_bswap32)
834+
# define ZEND_BYTES_SWAP32(u) __builtin_bswap32(u)
835+
# endif // __has_builtin(__builtin_bswap32)
836+
# if __has_builtin(__builtin_bswap64)
837+
# define ZEND_BYTES_SWAP64(u) __builtin_bswap64(u)
838+
# endif // __has_builtin(__builtin_bswap64)
839+
# endif // __GNUC__
840+
# endif // _MSC_VER
841+
#endif // HAVE_BYTESWAP_H
842+
832843
#ifndef ZEND_BYTES_SWAP32
833844
static zend_always_inline uint32_t ZEND_BYTES_SWAP32(uint32_t u)
834845
{

0 commit comments

Comments
 (0)