* Use LITTLE_ENDIAN instead of __LITTLE_ENDIAN (LITTLE_ENDIAN is what POSIX now specifies and everyone seems to define - NetBSD also defines _LITTLE_ENDIAN, but not __LITTLE_ENDIAN) * file descriptors greater than 2 must be explicitly passed to a child on NetBSD. POSIX leaves that unspecified, see https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#exec * system library functions get declared with visibility "default" on NetBSD, so a "hidden" visibility attribute is ignored on a redeclaration. Work around by putting the functions in a namespace - as they are extern "C", they still end up in the object file without the namespace qualifier. * remove the cast on the NULL pointer on the funopen call - it's not needed and the types are different between FreeBSD (fpos_t) and NetBSD/OpenBSD (off_t); also trying to change that upstream https://github.com/openSUSE/libsolv/pull/603 Change-Id: I6ab7f3c74d18960d7589b403a1c219cdac85a453 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10133 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
132 lines
4.4 KiB
C
132 lines
4.4 KiB
C
/*
|
|
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _FSSH_BYTEORDER_H
|
|
#define _FSSH_BYTEORDER_H
|
|
|
|
#include <endian.h>
|
|
// platform endian.h
|
|
|
|
|
|
#include "fssh_defs.h"
|
|
|
|
|
|
// swap directions
|
|
typedef enum {
|
|
FSSH_B_SWAP_HOST_TO_LENDIAN,
|
|
FSSH_B_SWAP_HOST_TO_BENDIAN,
|
|
FSSH_B_SWAP_LENDIAN_TO_HOST,
|
|
FSSH_B_SWAP_BENDIAN_TO_HOST,
|
|
FSSH_B_SWAP_ALWAYS
|
|
} fssh_swap_action;
|
|
|
|
|
|
// BSD/networking macros
|
|
#ifndef fssh_htonl
|
|
# define fssh_htonl(x) FSSH_B_HOST_TO_BENDIAN_INT32(x)
|
|
# define fssh_ntohl(x) FSSH_B_BENDIAN_TO_HOST_INT32(x)
|
|
# define fssh_htons(x) FSSH_B_HOST_TO_BENDIAN_INT16(x)
|
|
# define fssh_ntohs(x) FSSH_B_BENDIAN_TO_HOST_INT16(x)
|
|
#endif
|
|
|
|
// always swap macros
|
|
#define FSSH_B_SWAP_DOUBLE(arg) __fssh_swap_double(arg)
|
|
#define FSSH_B_SWAP_FLOAT(arg) __fssh_swap_float(arg)
|
|
#define FSSH_B_SWAP_INT64(arg) __fssh_swap_int64(arg)
|
|
#define FSSH_B_SWAP_INT32(arg) __fssh_swap_int32(arg)
|
|
#define FSSH_B_SWAP_INT16(arg) __fssh_swap_int16(arg)
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
// Host is little endian
|
|
|
|
#define FSSH_B_HOST_IS_LENDIAN 1
|
|
#define FSSH_B_HOST_IS_BENDIAN 0
|
|
|
|
// Host native to little endian
|
|
#define FSSH_B_HOST_TO_LENDIAN_DOUBLE(arg) (double)(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_FLOAT(arg) (float)(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_INT64(arg) (uint64_t)(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_INT32(arg) (uint32_t)(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_INT16(arg) (uint16_t)(arg)
|
|
|
|
// Little endian to host native
|
|
#define FSSH_B_LENDIAN_TO_HOST_DOUBLE(arg) (double)(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_FLOAT(arg) (float)(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_INT64(arg) (uint64_t)(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_INT32(arg) (uint32_t)(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_INT16(arg) (uint16_t)(arg)
|
|
|
|
// Host native to big endian
|
|
#define FSSH_B_HOST_TO_BENDIAN_DOUBLE(arg) __fssh_swap_double(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_FLOAT(arg) __fssh_swap_float(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_INT64(arg) __fssh_swap_int64(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_INT32(arg) __fssh_swap_int32(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_INT16(arg) __fssh_swap_int16(arg)
|
|
|
|
// Big endian to host native
|
|
#define FSSH_B_BENDIAN_TO_HOST_DOUBLE(arg) __fssh_swap_double(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_FLOAT(arg) __fssh_swap_float(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_INT64(arg) __fssh_swap_int64(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_INT32(arg) __fssh_swap_int32(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_INT16(arg) __fssh_swap_int16(arg)
|
|
|
|
#else // BYTE_ORDER
|
|
// Host is big endian
|
|
|
|
#define FSSH_B_HOST_IS_LENDIAN 0
|
|
#define FSSH_B_HOST_IS_BENDIAN 1
|
|
|
|
// Host native to little endian
|
|
#define FSSH_B_HOST_TO_LENDIAN_DOUBLE(arg) __fssh_swap_double(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_FLOAT(arg) __fssh_swap_float(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_INT64(arg) __fssh_swap_int64(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_INT32(arg) __fssh_swap_int32(arg)
|
|
#define FSSH_B_HOST_TO_LENDIAN_INT16(arg) __fssh_swap_int16(arg)
|
|
|
|
// Little endian to host native
|
|
#define FSSH_B_LENDIAN_TO_HOST_DOUBLE(arg) __fssh_swap_double(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_FLOAT(arg) __fssh_swap_float(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_INT64(arg) __fssh_swap_int64(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_INT32(arg) __fssh_swap_int32(arg)
|
|
#define FSSH_B_LENDIAN_TO_HOST_INT16(arg) __fssh_swap_int16(arg)
|
|
|
|
// Host native to big endian
|
|
#define FSSH_B_HOST_TO_BENDIAN_DOUBLE(arg) (double)(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_FLOAT(arg) (float)(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_INT64(arg) (uint64_t)(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_INT32(arg) (uint32_t)(arg)
|
|
#define FSSH_B_HOST_TO_BENDIAN_INT16(arg) (uint16_t)(arg)
|
|
|
|
// Big endian to host native
|
|
#define FSSH_B_BENDIAN_TO_HOST_DOUBLE(arg) (double)(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_FLOAT(arg) (float)(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_INT64(arg) (uint64_t)(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_INT32(arg) (uint32_t)(arg)
|
|
#define FSSH_B_BENDIAN_TO_HOST_INT16(arg) (uint16_t)(arg)
|
|
|
|
#endif // BYTE_ORDER
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
extern fssh_status_t fssh_swap_data(fssh_type_code type, void *data,
|
|
fssh_size_t length, fssh_swap_action action);
|
|
extern bool fssh_is_type_swapped(fssh_type_code type);
|
|
|
|
|
|
// Private implementations
|
|
extern double __fssh_swap_double(double arg);
|
|
extern float __fssh_swap_float(float arg);
|
|
extern uint64_t __fssh_swap_int64(uint64_t arg);
|
|
extern uint32_t __fssh_swap_int32(uint32_t arg);
|
|
extern uint16_t __fssh_swap_int16(uint16_t arg);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // _FSSH_BYTEORDER_H
|