/* * The QUAFFLER library * Copyright (c) 2006 Clifford Wolf * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _QUAFFLER_UTILS_H #define _QUAFFLER_UTILS_H #include static inline int test_bit(const unsigned char *bitmap, int offset) { return (bitmap[offset / 8] & (1 << (offset % 8))) != 0; } static inline void set_bit(unsigned char *bitmap, int offset) { bitmap[offset / 8] |= (1 << (offset % 8)); } static inline void clear_bit(unsigned char *bitmap, int offset) { bitmap[offset / 8] &= ~(1 << (offset % 8)); } static inline int test_bit_file(QFL_OS_FILEHDL_TYPE *filehdl_p, int pos, int offset) { unsigned char byte; qfl_os_read(filehdl_p, pos + offset / 8, &byte, 1); return (byte & (1 << (offset % 8))) != 0; } static inline void set_bit_file(QFL_OS_FILEHDL_TYPE *filehdl_p, int pos, int offset) { unsigned char byte; qfl_os_read(filehdl_p, pos + offset / 8, &byte, 1); byte |= (1 << (offset % 8)); qfl_os_write(filehdl_p, pos + offset / 8, &byte, 1); } static inline void clear_bit_file(QFL_OS_FILEHDL_TYPE *filehdl_p, int pos, int offset) { unsigned char byte; qfl_os_read(filehdl_p, pos + offset / 8, &byte, 1); byte &= ~(1 << (offset % 8)); qfl_os_write(filehdl_p, pos + offset / 8, &byte, 1); } static inline long long htonll(long long x) { if (htonl(1) == 1) return x; return (((x) & 0xff00000000000000ull) >> 56) | (((x) & 0x00ff000000000000ull) >> 40) | (((x) & 0x0000ff0000000000ull) >> 24) | (((x) & 0x000000ff00000000ull) >> 8) | (((x) & 0x00000000ff000000ull) << 8) | (((x) & 0x0000000000ff0000ull) << 24) | (((x) & 0x000000000000ff00ull) << 40) | (((x) & 0x00000000000000ffull) << 56); } static inline long long ntohll(long long x) { return htonll(x); } #endif