freebsd-compat.h (4685B)
1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1982, 1986, 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37 #ifndef FSCK_FAT_COMPAT_H 38 #define FSCK_FAT_COMPAT_H 39 40 #include <limits.h> 41 #include <sys/param.h> 42 43 #ifndef __dead2 44 #define __dead2 __attribute__((__noreturn__)) 45 #endif 46 #ifndef __printflike 47 #define __printflike(f, a) __attribute__((__format__(__printf__, f, a))) 48 #endif 49 #ifndef LONG_BIT 50 #define LONG_BIT (sizeof(long) * CHAR_BIT) 51 #endif 52 53 /* From FreeBSD sys/sys/param.h */ 54 55 #ifndef roundup2 56 #define roundup2(x, y) (((x) + ((y) - 1)) & (~((y) - 1))) /* if y is powers of two */ 57 #endif 58 59 /*- 60 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 61 * 62 * Copyright (c) 2002 Thomas Moestl <tmm@FreeBSD.org> 63 * All rights reserved. 64 * 65 * Redistribution and use in source and binary forms, with or without 66 * modification, are permitted provided that the following conditions 67 * are met: 68 * 1. Redistributions of source code must retain the above copyright 69 * notice, this list of conditions and the following disclaimer. 70 * 2. Redistributions in binary form must reproduce the above copyright 71 * notice, this list of conditions and the following disclaimer in the 72 * documentation and/or other materials provided with the distribution. 73 * 74 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 75 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 76 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 77 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 78 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 79 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 80 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 82 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 83 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 84 * SUCH DAMAGE. 85 */ 86 87 #include <stdint.h> 88 89 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 90 #include <sys/endian.h> 91 #else 92 93 /* From FreeBSD sys/sys/endian.h */ 94 95 static __inline void 96 le16enc(void *pp, uint16_t u) 97 { 98 uint8_t *p = (uint8_t *)pp; 99 100 p[0] = u & 0xff; 101 p[1] = (u >> 8) & 0xff; 102 } 103 104 static __inline void 105 le32enc(void *pp, uint32_t u) 106 { 107 uint8_t *p = (uint8_t *)pp; 108 109 p[0] = u & 0xff; 110 p[1] = (u >> 8) & 0xff; 111 p[2] = (u >> 16) & 0xff; 112 p[3] = (u >> 24) & 0xff; 113 } 114 115 static __inline uint16_t 116 le16dec(const void *pp) 117 { 118 uint8_t const *p = (uint8_t const *)pp; 119 120 return ((p[1] << 8) | p[0]); 121 } 122 123 static __inline uint32_t 124 le32dec(const void *pp) 125 { 126 uint8_t const *p = (uint8_t const *)pp; 127 128 return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); 129 } 130 #endif 131 132 #endif