Annotation of nono/lib/missing_endian.h, revision 1.1.1.3

1.1       root        1: //
                      2: // nono
1.1.1.3 ! root        3: // Copyright (C) 2020 nono project
        !             4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #pragma once
                      8: 
                      9: #if !defined(_LITTLE_ENDIAN)
                     10: # define _LITTLE_ENDIAN        1234
                     11: # define _BIG_ENDIAN   4321
                     12: #endif
                     13: 
                     14: #if !defined(_BYTE_ORDER)
                     15: # if defined(WORDS_BIGENDIAN)
                     16: #  define _BYTE_ORDER _BIG_ENDIAN
                     17: # else
                     18: #  define _BYTE_ORDER _LITTLE_ENDIAN
                     19: # endif
                     20: #endif
                     21: 
1.1.1.2   root       22: // __builtin_bswap* がないような環境があったらその時考える
                     23: #if !defined(HAVE___BUILTIN_BSWAP16) || \
                     24:     !defined(HAVE___BUILTIN_BSWAP32) || \
                     25:     !defined(HAVE___BUILTIN_BSWAP64)
                     26: #error No __builtin_bswap*
1.1       root       27: #endif
                     28: 
                     29: #if _BYTE_ORDER == _BIG_ENDIAN
1.1.1.2   root       30: #define be16toh(x)     ((uint16)(x))
                     31: #define be32toh(x)     ((uint32)(x))
                     32: #define be64toh(x)     ((uint64)(x))
                     33: #define le16toh(x)     __builtin_bswap16((uint16)(x))
                     34: #define le32toh(x)     __builtin_bswap32((uint32)(x))
                     35: #define le64toh(x)     __builtin_bswap64((uint64)(x))
1.1       root       36: #else
1.1.1.2   root       37: #define be16toh(x)     __builtin_bswap16((uint16)(x))
                     38: #define be32toh(x)     __builtin_bswap32((uint32)(x))
                     39: #define be64toh(x)     __builtin_bswap64((uint64)(x))
                     40: #define le16toh(x)     ((uint16)(x))
                     41: #define le32toh(x)     ((uint32)(x))
                     42: #define le64toh(x)     ((uint64)(x))
1.1       root       43: #endif
                     44: 
1.1.1.2   root       45: #define htobe16(x)     be16toh(x)
                     46: #define htobe32(x)     be32toh(x)
                     47: #define htobe64(x)     be64toh(x)
1.1       root       48: 
1.1.1.2   root       49: #define htole16(x)     le16toh(x)
                     50: #define htole32(x)     le32toh(x)
                     51: #define htole64(x)     le64toh(x)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.