diff options
author | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-14 13:59:42 -0600 |
---|---|---|
committer | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-14 13:59:42 -0600 |
commit | b0119419b6edc287062e3a34a199a4315d860d28 (patch) | |
tree | 85780ef9e2cef0a1aace11daf0ea4cd9c36cf70f | |
parent | 70f4ec71123a7646bf4e2141969cfdcdecfcdffa (diff) | |
download | apk-tools-b0119419b6edc287062e3a34a199a4315d860d28.tar.gz apk-tools-b0119419b6edc287062e3a34a199a4315d860d28.tar.bz2 apk-tools-b0119419b6edc287062e3a34a199a4315d860d28.tar.xz apk-tools-b0119419b6edc287062e3a34a199a4315d860d28.zip |
portability: take over apk_endian.h
-rw-r--r-- | portability/apk_endian.h | 57 | ||||
-rw-r--r-- | portability/meson.build | 5 | ||||
-rw-r--r-- | src/apk_endian.h | 33 | ||||
-rw-r--r-- | src/meson.build | 8 |
4 files changed, 69 insertions, 34 deletions
diff --git a/portability/apk_endian.h b/portability/apk_endian.h new file mode 100644 index 0000000..284b07b --- /dev/null +++ b/portability/apk_endian.h @@ -0,0 +1,57 @@ +/* apk_endian.h - Alpine Package Keeper (APK) + * + * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org> + * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi> + * Copyright (C) 2011 Rich Felker + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#ifndef APK_ENDIAN_H +#define APK_ENDIAN_H + +static __inline uint16_t __bswap16(uint16_t __x) +{ + return (__x<<8) | (__x>>8); +} + +static __inline uint32_t __bswap32(uint32_t __x) +{ + return (__x>>24) | (__x>>8&0xff00) | (__x<<8&0xff0000) | (__x<<24); +} + +static __inline uint64_t __bswap64(uint64_t __x) +{ + return (__bswap32(__x)+0ULL)<<32 | __bswap32(__x>>32); +} + +#ifndef WORDS_BIGENDIAN +# define htobe16(x) __bswap16(x) +# define be16toh(x) __bswap16(x) +# define htobe32(x) __bswap32(x) +# define be32toh(x) __bswap32(x) +# define htobe64(x) __bswap64(x) +# define be64toh(x) __bswap64(x) +# define htole16(x) (uint16_t)(x) +# define le16toh(x) (uint16_t)(x) +# define htole32(x) (uint32_t)(x) +# define le32toh(x) (uint32_t)(x) +# define htole64(x) (uint64_t)(x) +# define le64toh(x) (uint64_t)(x) +#else +# define htobe16(x) (uint16_t)(x) +# define be16toh(x) (uint16_t)(x) +# define htobe32(x) (uint32_t)(x) +# define be32toh(x) (uint32_t)(x) +# define htobe64(x) (uint64_t)(x) +# define be64toh(x) (uint64_t)(x) +# define htole16(x) __bswap16(x) +# define le16toh(x) __bswap16(x) +# define htole32(x) __bswap32(x) +# define le32toh(x) __bswap32(x) +# define htole64(x) __bswap64(x) +# define le64toh(x) __bswap64(x) +#endif + +#endif diff --git a/portability/meson.build b/portability/meson.build index e3be65d..851dfca 100644 --- a/portability/meson.build +++ b/portability/meson.build @@ -1,6 +1,11 @@ cc = meson.get_compiler('c') +if host_machine.endian() == 'big' + add_project_arguments('-DWORDS_BIGENDIAN', language: 'c') +endif + + libportability_src = [] diff --git a/src/apk_endian.h b/src/apk_endian.h deleted file mode 100644 index d4ff516..0000000 --- a/src/apk_endian.h +++ /dev/null @@ -1,33 +0,0 @@ -/* apk_endian.h - Alpine Package Keeper (APK) - * - * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org> - * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#ifndef APK_ENDIAN_H -#define APK_ENDIAN_H - -#ifdef __linux__ -# include <endian.h> -#endif - -#ifdef __APPLE__ -# include <libkern/OSByteOrder.h> -# define htobe16(x) OSSwapHostToBigInt16(x) -# define htole16(x) OSSwapHostToLittleInt16(x) -# define be16toh(x) OSSwapBigToHostInt16(x) -# define le16toh(x) OSSwapLittleToHostInt16(x) -# define htobe32(x) OSSwapHostToBigInt32(x) -# define htole32(x) OSSwapHostToLittleInt32(x) -# define be32toh(x) OSSwapBigToHostInt32(x) -# define le32toh(x) OSSwapLittleToHostInt32(x) -# define htobe64(x) OSSwapHostToBigInt64(x) -# define htole64(x) OSSwapHostToLittleInt64(x) -# define be64toh(x) OSSwapBigToHostInt64(x) -# define le64toh(x) OSSwapLittleToHostInt64(x) -#endif - -#endif diff --git a/src/meson.build b/src/meson.build index ccfdbb0..da6bb9b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -160,7 +160,12 @@ if(lua_dep.found()) libluaapk = library( 'luaapk', luaapk_src, - dependencies: [lua_dep, libapk_dep, shared_deps], + dependencies: [ + lua_dep, + libapk_dep, + shared_deps, + libportability_dep.partial_dependency(includes: true), + ], install: true, install_dir: lua_dep.get_pkgconfig_variable('libdir'), c_args: apk_cargs, @@ -175,6 +180,7 @@ apk_exe = executable( libapk_dep, shared_deps, libfetch_dep.partial_dependency(includes: true), + libportability_dep.partial_dependency(includes: true), ], c_args: apk_cargs, ) |