View | Details | Raw Unified | Return to bug 258544 | Differences between
and this patch

Collapse All | Expand All

(-)b/include/Makefile (-2 / +2 lines)
Lines 11-18 SUBDIR= arpa protocols rpcsvc rpc xlocale Link Here
11
SUBDIR_PARALLEL=
11
SUBDIR_PARALLEL=
12
INCS=	a.out.h ar.h assert.h bitstring.h complex.h cpio.h _ctype.h ctype.h \
12
INCS=	a.out.h ar.h assert.h bitstring.h complex.h cpio.h _ctype.h ctype.h \
13
	db.h \
13
	db.h \
14
	dirent.h dlfcn.h elf.h elf-hints.h err.h fmtmsg.h fnmatch.h fstab.h \
14
	dirent.h dlfcn.h elf.h elf-hints.h endian.h err.h fmtmsg.h fnmatch.h \
15
	fts.h ftw.h getopt.h glob.h grp.h \
15
	fstab.h fts.h ftw.h getopt.h glob.h grp.h \
16
	ieeefp.h ifaddrs.h \
16
	ieeefp.h ifaddrs.h \
17
	inttypes.h iso646.h kenv.h langinfo.h libgen.h limits.h link.h \
17
	inttypes.h iso646.h kenv.h langinfo.h libgen.h limits.h link.h \
18
	locale.h malloc.h malloc_np.h memory.h monetary.h mpool.h mqueue.h \
18
	locale.h malloc.h malloc_np.h memory.h monetary.h mpool.h mqueue.h \
(-)b/include/endian.h (+56 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2021 M Warner Losh <imp@FreeBSD.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
/*
8
 * A mostly Linux/glibc-compatible endian.h
9
 */
10
11
#ifndef _ENDIAN_H_
12
#define _ENDIAN_H_
13
14
/*
15
 * FreeBSD's sys/endian.h is very close to the interface provided on Linux by
16
 * glibc's endian.h. Linux doesn't define the hto* [bl]*toh macros when there's
17
 * a strict name space. We request that the FreeBSD-specific
18
 * [lb]e{16,32,64}{enc,dec} be omitted as well.
19
 */
20
#define __OMIT_ENDIAN_ENCODE_DECODE
21
#include <sys/endian.h>
22
23
/*
24
 * The bswap* functions cause problems for some Linux code (like mesa), so
25
 * remove them from the name space as well.  You need to include sys/endian.h
26
 * directly if you want these (or the other FreeBSD-specific macros) to be
27
 * visible.
28
 */
29
#undef bswap16
30
#undef bswap32
31
#undef bswap64
32
33
/*
34
 * glibc uses double underscore for these symbols. Define these unconditionally.
35
 * The compiler defines __BYTE_ORDER__ these days, so we don't do anything
36
 * with that since sys/endian.h defines _BYTE_ORDER based on it.
37
 */
38
#define __BIG_ENDIAN		_BIG_ENDIAN
39
#define __BYTE_ORDER		_BYTE_ORDER
40
#define __LITTLE_ENDIAN		_LITTLE_ENDIAN
41
#define __PDP_ENDIAN		_PDP_ENDIAN
42
43
/*
44
 * FreeBSD's sys/endian.h and machine/endian.h doesn't define a separate
45
 * byte order for floats. Use the host non-float byte order.
46
 */
47
#define __FLOAT_WORD_ORDER	_BYTE_ORDER
48
49
/*
50
 * We don't define BIG_ENDI, LITTLE_ENDI, HIGH_HALF and LOW_HALF macros that
51
 * glibc's endian.h defines since those appear to be internal to internal to
52
 * glibc. We also don't try to emulate the various helper macros that glibc
53
 * uses to limit namespace visibility.
54
 */
55
56
#endif /* _ENDIAN_H_ */
(-)b/sys/sys/endian.h (-14 / +16 lines)
Lines 55-60 typedef __uint64_t uint64_t; Link Here
55
#define	_UINT64_T_DECLARED
55
#define	_UINT64_T_DECLARED
56
#endif
56
#endif
57
57
58
#if __BSD_VISIBLE
58
/*
59
/*
59
 * General byte order swapping functions.
60
 * General byte order swapping functions.
60
 */
61
 */
Lines 67-82 typedef __uint64_t uint64_t; Link Here
67
 * endian to host byte order functions as detailed in byteorder(9).
68
 * endian to host byte order functions as detailed in byteorder(9).
68
 */
69
 */
69
#if _BYTE_ORDER == _LITTLE_ENDIAN
70
#if _BYTE_ORDER == _LITTLE_ENDIAN
70
#define	htobe16(x)	bswap16((x))
71
#define	htobe16(x)	__bswap16((x))
71
#define	htobe32(x)	bswap32((x))
72
#define	htobe32(x)	__bswap32((x))
72
#define	htobe64(x)	bswap64((x))
73
#define	htobe64(x)	__bswap64((x))
73
#define	htole16(x)	((uint16_t)(x))
74
#define	htole16(x)	((uint16_t)(x))
74
#define	htole32(x)	((uint32_t)(x))
75
#define	htole32(x)	((uint32_t)(x))
75
#define	htole64(x)	((uint64_t)(x))
76
#define	htole64(x)	((uint64_t)(x))
76
77
77
#define	be16toh(x)	bswap16((x))
78
#define	be16toh(x)	__bswap16((x))
78
#define	be32toh(x)	bswap32((x))
79
#define	be32toh(x)	__bswap32((x))
79
#define	be64toh(x)	bswap64((x))
80
#define	be64toh(x)	__bswap64((x))
80
#define	le16toh(x)	((uint16_t)(x))
81
#define	le16toh(x)	((uint16_t)(x))
81
#define	le32toh(x)	((uint32_t)(x))
82
#define	le32toh(x)	((uint32_t)(x))
82
#define	le64toh(x)	((uint64_t)(x))
83
#define	le64toh(x)	((uint64_t)(x))
Lines 84-103 typedef __uint64_t uint64_t; Link Here
84
#define	htobe16(x)	((uint16_t)(x))
85
#define	htobe16(x)	((uint16_t)(x))
85
#define	htobe32(x)	((uint32_t)(x))
86
#define	htobe32(x)	((uint32_t)(x))
86
#define	htobe64(x)	((uint64_t)(x))
87
#define	htobe64(x)	((uint64_t)(x))
87
#define	htole16(x)	bswap16((x))
88
#define	htole16(x)	__bswap16((x))
88
#define	htole32(x)	bswap32((x))
89
#define	htole32(x)	__bswap32((x))
89
#define	htole64(x)	bswap64((x))
90
#define	htole64(x)	__bswap64((x))
90
91
91
#define	be16toh(x)	((uint16_t)(x))
92
#define	be16toh(x)	((uint16_t)(x))
92
#define	be32toh(x)	((uint32_t)(x))
93
#define	be32toh(x)	((uint32_t)(x))
93
#define	be64toh(x)	((uint64_t)(x))
94
#define	be64toh(x)	((uint64_t)(x))
94
#define	le16toh(x)	bswap16((x))
95
#define	le16toh(x)	__bswap16((x))
95
#define	le32toh(x)	bswap32((x))
96
#define	le32toh(x)	__bswap32((x))
96
#define	le64toh(x)	bswap64((x))
97
#define	le64toh(x)	__bswap64((x))
97
#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
98
#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
98
99
99
/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
100
/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
100
101
#ifndef __OMIT_ENDIAN_ENCODE_DECODE
101
static __inline uint16_t
102
static __inline uint16_t
102
be16dec(const void *pp)
103
be16dec(const void *pp)
103
{
104
{
Lines 203-207 le64enc(void *pp, uint64_t u) Link Here
203
	le32enc(p, (uint32_t)(u & 0xffffffffU));
204
	le32enc(p, (uint32_t)(u & 0xffffffffU));
204
	le32enc(p + 4, (uint32_t)(u >> 32));
205
	le32enc(p + 4, (uint32_t)(u >> 32));
205
}
206
}
206
207
#endif	/* __OMIT_ENDIAN_ENCODE_DECODE */
208
#endif	/* __BSD_VISIBLE */
207
#endif	/* _SYS_ENDIAN_H_ */
209
#endif	/* _SYS_ENDIAN_H_ */

Return to bug 258544