From 3010520b52752156a54058cead076308184fd639 Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Thu, 27 Mar 2025 05:46:45 +0800 Subject: [PATCH 1/4] feat port: removed any dependencies on the system - Enhance the system abstraction layer. - Using bfdev to customize types. Signed-off-by: John Sanpe --- CMakeLists.txt | 1 + build.cmake | 1 + examples/ascii85/utils.c | 1 + examples/base32/utils.c | 1 + examples/base64/utils.c | 1 + examples/bloom/simple.c | 1 + examples/btree/selftest.c | 1 + examples/cache/simple.c | 1 + examples/crypto/utils.c | 1 + examples/fsm/console.c | 1 + examples/glob/utils.c | 1 + examples/prandom/simple.c | 1 + examples/ratelimit/simple.c | 1 + examples/time.h | 1 + examples/tokenbucket/simple.c | 1 + include/base.h | 2 - include/bfdev/action.h | 2 +- include/bfdev/align.h | 6 +- include/bfdev/allocator.h | 13 +- include/bfdev/allocpool.h | 9 +- include/bfdev/arc4.h | 10 +- include/bfdev/array.h | 11 +- include/bfdev/ascii85.h | 14 +- include/bfdev/asm-generic/bitops.h | 76 +++--- include/bfdev/asm-generic/byteorder.h | 32 +-- include/bfdev/asm-generic/cmpxchg.h | 8 +- include/bfdev/asm-generic/dword-compiler.h | 2 +- include/bfdev/asm-generic/types.h | 39 +++ include/bfdev/asm-generic/unaligned.h | 48 ++-- include/bfdev/base32.h | 12 +- include/bfdev/base64.h | 12 +- include/bfdev/bcd.h | 28 +- include/bfdev/bitflags.h | 83 +++--- include/bfdev/bitmap-comp.h | 10 +- include/bfdev/bitmap.h | 30 +-- include/bfdev/bitops-endian.h | 52 ++-- include/bfdev/bitops.h | 160 +++++------ include/bfdev/bitrev.h | 300 ++++++++++----------- include/bfdev/bits.h | 12 +- include/bfdev/bitwalk-comp.h | 8 +- include/bfdev/bitwalk.h | 44 +-- include/bfdev/bloom.h | 4 +- include/bfdev/bsearch.h | 6 +- include/bfdev/btree.h | 32 +-- include/bfdev/bug.h | 8 +- include/bfdev/byteorder/big-endian.h | 80 +++--- include/bfdev/byteorder/little-endian.h | 72 ++--- include/bfdev/cache.h | 2 +- include/bfdev/cmpxchg.h | 2 +- include/bfdev/container.h | 26 +- include/bfdev/crc.h | 40 +-- include/bfdev/crypto/crc-ccitt-inline.h | 2 +- include/bfdev/crypto/crc-inline.h | 32 +-- include/bfdev/crypto/crc-itut-inline.h | 2 +- include/bfdev/crypto/crc-rocksoft-inline.h | 2 +- include/bfdev/crypto/crc-t10dif-inline.h | 2 +- include/bfdev/crypto/crc16-inline.h | 2 +- include/bfdev/crypto/crc32-inline.h | 2 +- include/bfdev/crypto/crc4-inline.h | 12 +- include/bfdev/crypto/crc64-inline.h | 2 +- include/bfdev/crypto/crc7-inline.h | 4 +- include/bfdev/crypto/crc8-inline.h | 4 +- include/bfdev/crypto/md5-base.h | 112 ++++---- include/bfdev/crypto/md5.h | 4 +- include/bfdev/crypto/sha1-base.h | 18 +- include/bfdev/crypto/sha1.h | 18 +- include/bfdev/crypto/sha2-base.h | 20 +- include/bfdev/crypto/sha2.h | 10 +- include/bfdev/ctype.h | 5 +- include/bfdev/errptr.h | 10 +- include/bfdev/fifo.h | 5 +- include/bfdev/fsm.h | 15 +- include/bfdev/glob.h | 2 +- include/bfdev/guards.h | 2 +- include/bfdev/hash.h | 16 +- include/bfdev/hashmap.h | 8 +- include/bfdev/hashtbl.h | 6 +- include/bfdev/heap.h | 10 +- include/bfdev/hlist.h | 32 +-- include/bfdev/ilist.h | 4 +- include/bfdev/jhash.h | 16 +- include/bfdev/levenshtein.h | 2 +- include/bfdev/limits.h | 49 ++-- include/bfdev/list.h | 22 +- include/bfdev/llist.h | 7 +- include/bfdev/log.h | 6 +- include/bfdev/log2.h | 4 +- include/bfdev/math.h | 6 +- include/bfdev/md5.h | 8 +- include/bfdev/memalloc.h | 19 +- include/bfdev/mpi.h | 12 +- include/bfdev/once.h | 14 +- include/bfdev/overflow.h | 20 +- include/bfdev/popcount.h | 76 +++--- include/bfdev/port/ctype.h | 21 -- include/bfdev/port/limits.h | 22 -- include/bfdev/port/stdarg.h | 12 +- include/bfdev/port/stdbool.h | 14 +- include/bfdev/port/stddef.h | 16 +- include/bfdev/port/stdint.h | 21 -- include/bfdev/port/stdio.h | 62 ----- include/bfdev/port/stdlib.h | 52 +--- include/bfdev/port/string.h | 137 +++------- include/bfdev/prandom.h | 16 +- include/bfdev/radix.h | 39 +-- include/bfdev/ratelimit.h | 2 +- include/bfdev/rbtree.h | 76 +++--- include/bfdev/refcount.h | 52 ++-- include/bfdev/respool.h | 2 +- include/bfdev/ringbuf.h | 4 +- include/bfdev/scnprintf.h | 5 +- include/bfdev/segtree.h | 22 +- include/bfdev/sha1.h | 6 +- include/bfdev/sha2.h | 6 +- include/bfdev/slist.h | 16 +- include/bfdev/sort.h | 3 +- include/bfdev/stdio.h | 16 -- include/bfdev/string.h | 8 +- include/bfdev/swab.h | 170 ++++++------ include/bfdev/textsearch.h | 33 +-- include/bfdev/time.h | 8 +- include/bfdev/titer.h | 20 +- include/bfdev/tokenbucket.h | 2 +- include/bfdev/types.h | 34 +-- include/bfdev/unaligned.h | 36 +-- include/bfdev/uplower.h | 8 +- include/port/allocator.h | 7 +- include/port/log.h | 21 +- include/port/stdio.h | 21 ++ include/port/stdlib.h | 34 +++ include/port/string.h | 49 ++++ port/build.cmake | 22 ++ port/posix/build.cmake | 12 + port/posix/log.c | 24 ++ port/posix/stdio.c | 21 ++ port/posix/stdlib.c | 49 ++++ port/posix/string.c | 79 ++++++ scripts/gen-crc.c | 11 +- scripts/gen-crc16.c | 1 + scripts/gen-crc16be.c | 1 + scripts/gen-crc32.c | 1 + scripts/gen-crc32be.c | 1 + scripts/gen-crc64.c | 1 + scripts/gen-crc64be.c | 1 + scripts/gen-crc8.c | 1 + scripts/sanitize.cmake | 3 +- src/allocator.c | 17 +- src/allocpool.c | 9 +- src/argv.c | 18 +- src/array.c | 32 +-- src/bcd.c | 8 +- src/bitmap.c | 40 +-- src/bitrev.c | 2 +- src/bitwalk.c | 8 +- src/bloom.c | 24 +- src/bsearch.c | 2 +- src/btree-utils.c | 17 +- src/btree.c | 133 ++++----- src/build.cmake | 1 + src/cache/cache.c | 44 +-- src/cache/lfu.c | 17 +- src/cache/lru.c | 6 +- src/crypto/arc4.c | 16 +- src/crypto/ascii85.c | 25 +- src/crypto/base32.c | 16 +- src/crypto/base64.c | 16 +- src/crypto/crc-ccitt.c | 4 +- src/crypto/crc-itut.c | 4 +- src/crypto/crc-rocksoft.c | 4 +- src/crypto/crc-t10dif.c | 4 +- src/crypto/crc16.c | 4 +- src/crypto/crc32.c | 4 +- src/crypto/crc4.c | 4 +- src/crypto/crc64.c | 4 +- src/crypto/crc7.c | 4 +- src/crypto/crc8.c | 4 +- src/crypto/md5.c | 6 +- src/crypto/sha1.c | 6 +- src/crypto/sha2.c | 6 +- src/errname.c | 6 +- src/fifo.c | 16 +- src/fsm.c | 2 +- src/glob.c | 18 +- src/hashmap.c | 16 +- src/heap-debug.c | 16 +- src/heap.c | 12 +- src/hlist-debug.c | 26 +- src/ilist.c | 18 +- src/jhash.c | 34 +-- src/levenshtein.c | 12 +- src/libc/strdup.c | 22 +- src/libc/string.c | 6 +- src/list-debug.c | 18 +- src/list-sort.c | 8 +- src/llist.c | 4 +- src/log/log.c | 34 ++- src/matrix.c | 8 +- src/memalloc.c | 62 ++--- src/mpi.c | 104 +++---- src/notifier.c | 2 +- src/popcount.c | 132 ++++----- src/port/build.cmake | 10 + src/port/stdlib.c | 14 + src/port/string.c | 74 +++++ src/prandom.c | 18 +- src/radix.c | 106 ++++---- src/ratelimit.c | 10 +- src/rbtree-debug.c | 16 +- src/rbtree.c | 36 +-- src/respool.c | 2 +- src/ringbuf.c | 19 +- src/scnprintf.c | 12 +- src/skiplist.c | 13 +- src/slist-debug.c | 14 +- src/sort.c | 19 +- src/textsearch/bm.c | 32 +-- src/textsearch/kmp.c | 14 +- src/textsearch/sunday.c | 24 +- src/textsearch/textsearch.c | 16 +- src/tokenbucket.c | 8 +- testsuite/array/fuzzy.c | 1 + testsuite/bitwalk/fuzzy.c | 1 + testsuite/glob/selftest.c | 2 + testsuite/mpi/empty.c | 1 + testsuite/mpi/fuzzy.c | 1 + testsuite/randpool.h | 1 + testsuite/testsuite.c | 1 + 227 files changed, 2521 insertions(+), 2264 deletions(-) create mode 100644 include/bfdev/asm-generic/types.h delete mode 100644 include/bfdev/port/ctype.h delete mode 100644 include/bfdev/port/limits.h delete mode 100644 include/bfdev/port/stdint.h delete mode 100644 include/bfdev/port/stdio.h delete mode 100644 include/bfdev/stdio.h create mode 100644 include/port/stdio.h create mode 100644 include/port/stdlib.h create mode 100644 include/port/string.h create mode 100644 port/build.cmake create mode 100644 port/posix/build.cmake create mode 100644 port/posix/log.c create mode 100644 port/posix/stdio.c create mode 100644 port/posix/stdlib.c create mode 100644 port/posix/string.c create mode 100644 src/port/build.cmake create mode 100644 src/port/stdlib.c create mode 100644 src/port/string.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f45df8e8..b45f9f72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ set(BFDEV_ARCH generic) set(BFDEV_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) set(BFDEV_HEADER_PATH ${PROJECT_SOURCE_DIR}/include) set(BFDEV_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src) +set(BFDEV_PORT_PATH ${PROJECT_SOURCE_DIR}/port) set(BFDEV_DOCUMENT_PATH ${PROJECT_SOURCE_DIR}/docs) set(BFDEV_GENERATED_PATH ${PROJECT_BINARY_DIR}/generated) set(BFDEV_EXPORT_PATH ${PROJECT_BINARY_DIR}/export) diff --git a/build.cmake b/build.cmake index 4237fccd..0718f64d 100644 --- a/build.cmake +++ b/build.cmake @@ -65,6 +65,7 @@ set(BFDEV_INCLUDE_DIRS include_directories(${BFDEV_INCLUDE_DIRS}) include(${BFDEV_ARCH_PATH}/build.cmake) include(${BFDEV_SOURCE_PATH}/build.cmake) +include(${BFDEV_PORT_PATH}/build.cmake) set(BFDEV_LIBRARY_HEADER ${BFDEV_HEADER} diff --git a/examples/ascii85/utils.c b/examples/ascii85/utils.c index 0ad9fa1e..c11dea6c 100644 --- a/examples/ascii85/utils.c +++ b/examples/ascii85/utils.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/examples/base32/utils.c b/examples/base32/utils.c index 1f59a919..6e7a55f1 100644 --- a/examples/base32/utils.c +++ b/examples/base32/utils.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/examples/base64/utils.c b/examples/base64/utils.c index aed82414..856b9160 100644 --- a/examples/base64/utils.c +++ b/examples/base64/utils.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/examples/bloom/simple.c b/examples/bloom/simple.c index b94dc265..e4593d12 100644 --- a/examples/bloom/simple.c +++ b/examples/bloom/simple.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/examples/btree/selftest.c b/examples/btree/selftest.c index 97c1a1e3..07d5113a 100644 --- a/examples/btree/selftest.c +++ b/examples/btree/selftest.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include diff --git a/examples/cache/simple.c b/examples/cache/simple.c index 77156c72..7452b937 100644 --- a/examples/cache/simple.c +++ b/examples/cache/simple.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/examples/crypto/utils.c b/examples/crypto/utils.c index 6897a567..2a661783 100644 --- a/examples/crypto/utils.c +++ b/examples/crypto/utils.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/examples/fsm/console.c b/examples/fsm/console.c index 44c0a288..f36329e9 100644 --- a/examples/fsm/console.c +++ b/examples/fsm/console.c @@ -5,6 +5,7 @@ #include #include +#include #include enum { diff --git a/examples/glob/utils.c b/examples/glob/utils.c index f0a84ce1..95bcdec0 100644 --- a/examples/glob/utils.c +++ b/examples/glob/utils.c @@ -6,6 +6,7 @@ #define MODULE_NAME "bfdev-glob" #define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt +#include #include #include diff --git a/examples/prandom/simple.c b/examples/prandom/simple.c index f431e750..e21e316a 100644 --- a/examples/prandom/simple.c +++ b/examples/prandom/simple.c @@ -6,6 +6,7 @@ #define MODULE_NAME "prandom-simple" #define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt +#include #include #include #include diff --git a/examples/ratelimit/simple.c b/examples/ratelimit/simple.c index 9af92772..e05d608e 100644 --- a/examples/ratelimit/simple.c +++ b/examples/ratelimit/simple.c @@ -6,6 +6,7 @@ #define MODULE_NAME "ratelimit-simple" #define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt +#include #include #include #include diff --git a/examples/time.h b/examples/time.h index f6836fc1..2e4ec9dd 100644 --- a/examples/time.h +++ b/examples/time.h @@ -7,6 +7,7 @@ #define _EXAMPLES_TIME_H_ #include +#include #include #include #include diff --git a/examples/tokenbucket/simple.c b/examples/tokenbucket/simple.c index 5e773bb0..88aa54d7 100644 --- a/examples/tokenbucket/simple.c +++ b/examples/tokenbucket/simple.c @@ -6,6 +6,7 @@ #define MODULE_NAME "tokenbucket-simple" #define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt +#include #include #include #include diff --git a/include/base.h b/include/base.h index 151a8979..23248a34 100644 --- a/include/base.h +++ b/include/base.h @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include diff --git a/include/bfdev/action.h b/include/bfdev/action.h index a1723af3..4fe768f3 100644 --- a/include/bfdev/action.h +++ b/include/bfdev/action.h @@ -64,7 +64,7 @@ bfdev_action_update(bfdev_action_t *action, const void *data) static inline void bfdev_action_clear(bfdev_action_t *action) { - action->func = NULL; + action->func = BFDEV_NULL; } /** diff --git a/include/bfdev/align.h b/include/bfdev/align.h index eea4361b..5a54859b 100644 --- a/include/bfdev/align.h +++ b/include/bfdev/align.h @@ -29,7 +29,7 @@ BFDEV_BEGIN_DECLS * @align: check alignment size. */ #define bfdev_align_ptr_check(ptr, align) ( \ - bfdev_align_check((uintptr_t)(ptr), align) \ + bfdev_align_check((bfdev_uintptr_t)(ptr), align) \ ) /** @@ -57,7 +57,7 @@ BFDEV_BEGIN_DECLS * @align: alignment size. */ #define bfdev_align_ptr_low(ptr, align) ({ \ - (typeof(ptr))bfdev_align_low((uintptr_t)(ptr), align); \ + (typeof(ptr))bfdev_align_low((bfdev_uintptr_t)(ptr), align); \ }) /** @@ -66,7 +66,7 @@ BFDEV_BEGIN_DECLS * @align: alignment size. */ #define bfdev_align_ptr_high(ptr, align) ({ \ - (typeof(ptr))bfdev_align_high((uintptr_t)(ptr), align); \ + (typeof(ptr))bfdev_align_high((bfdev_uintptr_t)(ptr), align); \ }) #define bfdev_align_low_adj(value, align) ({ \ diff --git a/include/bfdev/allocator.h b/include/bfdev/allocator.h index 9121aba5..41ce3dd9 100644 --- a/include/bfdev/allocator.h +++ b/include/bfdev/allocator.h @@ -76,13 +76,14 @@ bfdev_alloc_ops_init(bfdev_alloc_ops_t *ops, } extern __bfdev_malloc void * -bfdev_malloc(const bfdev_alloc_t *alloc, size_t size); +bfdev_malloc(const bfdev_alloc_t *alloc, bfdev_size_t size); extern __bfdev_malloc void * -bfdev_zalloc(const bfdev_alloc_t *alloc, size_t size); +bfdev_zalloc(const bfdev_alloc_t *alloc, bfdev_size_t size); extern __bfdev_malloc void * -bfdev_realloc(const bfdev_alloc_t *alloc, const void *block, size_t resize); +bfdev_realloc(const bfdev_alloc_t *alloc, const void *block, + bfdev_size_t resize); extern void bfdev_free(const bfdev_alloc_t *alloc, const void *block); @@ -94,7 +95,7 @@ bfdev_free(const bfdev_alloc_t *alloc, const void *block); */ static __bfdev_always_inline __bfdev_malloc void * bfdev_malloc_array(const bfdev_alloc_t *alloc, - size_t nr, size_t size) + bfdev_size_t nr, bfdev_size_t size) { return bfdev_malloc(alloc, size * nr); } @@ -106,7 +107,7 @@ bfdev_malloc_array(const bfdev_alloc_t *alloc, */ static __bfdev_always_inline __bfdev_malloc void * bfdev_zalloc_array(const bfdev_alloc_t *alloc, - size_t nr, size_t size) + bfdev_size_t nr, bfdev_size_t size) { return bfdev_zalloc(alloc, size * nr); } @@ -119,7 +120,7 @@ bfdev_zalloc_array(const bfdev_alloc_t *alloc, */ static __bfdev_always_inline __bfdev_malloc void * bfdev_realloc_array(const bfdev_alloc_t *alloc, - void *block, size_t nr, size_t size) + void *block, bfdev_size_t nr, bfdev_size_t size) { return bfdev_realloc(alloc, block, size * nr); } diff --git a/include/bfdev/allocpool.h b/include/bfdev/allocpool.h index 396720a0..2437353c 100644 --- a/include/bfdev/allocpool.h +++ b/include/bfdev/allocpool.h @@ -16,8 +16,8 @@ typedef struct bfdev_allocpool bfdev_allocpool_t; struct bfdev_allocpool { void *block; - size_t size; - uintptr_t last; + bfdev_size_t size; + bfdev_uintptr_t last; unsigned long count; }; @@ -38,7 +38,7 @@ struct bfdev_allocpool { * @size: mempool array size. */ static inline void -bfdev_allocpool_init(bfdev_allocpool_t *pool, void *block, size_t size) +bfdev_allocpool_init(bfdev_allocpool_t *pool, void *block, bfdev_size_t size) { *pool = BFDEV_ALLOCPOOL_INIT(block, size); } @@ -61,7 +61,8 @@ bfdev_allocpool_reset(bfdev_allocpool_t *pool) * @align: align to allocation. */ extern __bfdev_malloc void * -bfdev_allocpool_alloc(bfdev_allocpool_t *pool, size_t size, size_t align); +bfdev_allocpool_alloc(bfdev_allocpool_t *pool, bfdev_size_t size, + bfdev_size_t align); /** * bfdev_allocpool_free() - Allocation mempool free. diff --git a/include/bfdev/arc4.h b/include/bfdev/arc4.h index e31e4105..a5e91e23 100644 --- a/include/bfdev/arc4.h +++ b/include/bfdev/arc4.h @@ -19,18 +19,18 @@ BFDEV_BEGIN_DECLS typedef struct bfdev_arc4_ctx bfdev_arc4_ctx_t; struct bfdev_arc4_ctx { - uint8_t box[BFDEV_ARC4_KSIZE]; - uint8_t proa; - uint8_t prob; + bfdev_u8 box[BFDEV_ARC4_KSIZE]; + bfdev_u8 proa; + bfdev_u8 prob; }; extern void bfdev_arc4_trans(bfdev_arc4_ctx_t *ctx, void *buff, - const void *data, size_t size); + const void *data, bfdev_size_t size); extern void bfdev_arc4_setkey(bfdev_arc4_ctx_t *ctx, - const uint8_t *key, unsigned int klen); + const bfdev_u8 *key, unsigned int klen); BFDEV_END_DECLS diff --git a/include/bfdev/array.h b/include/bfdev/array.h index 9ea65b15..c75153c0 100644 --- a/include/bfdev/array.h +++ b/include/bfdev/array.h @@ -33,7 +33,7 @@ struct bfdev_array { const bfdev_alloc_t *alloc; unsigned long capacity; unsigned long index; - size_t cells; + bfdev_size_t cells; void *data; }; @@ -54,7 +54,8 @@ struct bfdev_array { * @cells: the size per elements. */ static inline void -bfdev_array_init(bfdev_array_t *array, const bfdev_alloc_t *alloc, size_t cells) +bfdev_array_init(bfdev_array_t *array, const bfdev_alloc_t *alloc, + bfdev_size_t cells) { *array = BFDEV_ARRAY_INIT(alloc, cells); } @@ -92,7 +93,7 @@ bfdev_array_index(const bfdev_array_t *array) * Returns the total size of elements stored in * the array container. */ -static inline size_t +static inline bfdev_size_t bfdev_array_size(const bfdev_array_t *array) { return array->cells * array->index; @@ -106,7 +107,7 @@ bfdev_array_size(const bfdev_array_t *array) * Return the address offset of the object indexed * by @index in the array. */ -static inline uintptr_t +static inline bfdev_uintptr_t bfdev_array_offset(const bfdev_array_t *array, unsigned long index) { return array->cells * index; @@ -124,7 +125,7 @@ static inline void * bfdev_array_data(const bfdev_array_t *array, unsigned long index) { if (bfdev_unlikely(index >= array->index)) - return NULL; + return BFDEV_NULL; return array->data + bfdev_array_offset(array, index); } diff --git a/include/bfdev/ascii85.h b/include/bfdev/ascii85.h index 1db90872..07a9691c 100644 --- a/include/bfdev/ascii85.h +++ b/include/bfdev/ascii85.h @@ -20,8 +20,8 @@ BFDEV_BEGIN_DECLS * Get the maximum length a block of * data will encode to. */ -static inline size_t -bfdev_ascii85_encode_length(size_t size) +static inline bfdev_size_t +bfdev_ascii85_encode_length(bfdev_size_t size) { return BFDEV_DIV_ROUND_UP(size, 4) * 5; } @@ -33,8 +33,8 @@ bfdev_ascii85_encode_length(size_t size) * Get the maximum length a block of * data will decode to. */ -static inline size_t -bfdev_ascii85_decode_length(size_t size) +static inline bfdev_size_t +bfdev_ascii85_decode_length(bfdev_size_t size) { return BFDEV_DIV_ROUND_UP(size, 5) * 4; } @@ -47,7 +47,8 @@ bfdev_ascii85_decode_length(size_t size) * @size: length of @data. */ extern void -bfdev_ascii85_encode(void *buff, const void *data, size_t *plen, size_t size); +bfdev_ascii85_encode(void *buff, const void *data, + bfdev_size_t *plen, bfdev_size_t size); /** * bfdev_ascii85_decode() - ascii85 decoder. @@ -57,7 +58,8 @@ bfdev_ascii85_encode(void *buff, const void *data, size_t *plen, size_t size); * @size: length of @data. */ extern int -bfdev_ascii85_decode(void *buff, const void *data, size_t *plen, size_t size); +bfdev_ascii85_decode(void *buff, const void *data, + bfdev_size_t *plen, bfdev_size_t size); BFDEV_END_DECLS diff --git a/include/bfdev/asm-generic/bitops.h b/include/bfdev/asm-generic/bitops.h index f477e7c6..9524c2b9 100644 --- a/include/bfdev/asm-generic/bitops.h +++ b/include/bfdev/asm-generic/bitops.h @@ -47,7 +47,8 @@ bfdev_arch_bit_flip(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_change # define bfdev_arch_bit_change bfdev_arch_bit_change static __bfdev_always_inline void -bfdev_arch_bit_change(volatile unsigned long *addr, unsigned int bit, bool val) +bfdev_arch_bit_change(volatile unsigned long *addr, unsigned int bit, + bfdev_bool val) { addr += BFDEV_BITS_WORD(bit); if (val) @@ -59,7 +60,7 @@ bfdev_arch_bit_change(volatile unsigned long *addr, unsigned int bit, bool val) #ifndef bfdev_arch_bit_test # define bfdev_arch_bit_test bfdev_arch_bit_test -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_test(const volatile unsigned long *addr, unsigned int bit) { addr += BFDEV_BITS_WORD(bit); @@ -69,7 +70,7 @@ bfdev_arch_bit_test(const volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_test_clr # define bfdev_arch_bit_test_clr bfdev_arch_bit_test_clr -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_test_clr(volatile unsigned long *addr, unsigned int bit) { unsigned long old; @@ -82,7 +83,7 @@ bfdev_arch_bit_test_clr(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_test_set # define bfdev_arch_bit_test_set bfdev_arch_bit_test_set -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_test_set(volatile unsigned long *addr, unsigned int bit) { unsigned long old; @@ -95,7 +96,7 @@ bfdev_arch_bit_test_set(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_test_flip # define bfdev_arch_bit_test_flip bfdev_arch_bit_test_flip -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_test_flip(volatile unsigned long *addr, unsigned int bit) { unsigned long old; @@ -108,8 +109,9 @@ bfdev_arch_bit_test_flip(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_test_change # define bfdev_arch_bit_test_change bfdev_arch_bit_test_change -static __bfdev_always_inline bool -bfdev_arch_bit_test_change(volatile unsigned long *addr, unsigned int bit, bool val) +static __bfdev_always_inline bfdev_bool +bfdev_arch_bit_test_change(volatile unsigned long *addr, unsigned int bit, + bfdev_bool val) { unsigned long old; addr += BFDEV_BITS_WORD(bit); @@ -155,7 +157,8 @@ bfdev_arch_bit_atomic_flip(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_atomic_change # define bfdev_arch_bit_atomic_change bfdev_arch_bit_atomic_change static __bfdev_always_inline void -bfdev_arch_bit_atomic_change(volatile unsigned long *addr, unsigned int bit, bool val) +bfdev_arch_bit_atomic_change(volatile unsigned long *addr, unsigned int bit, + bfdev_bool val) { addr += BFDEV_BITS_WORD(bit); if (val) @@ -167,7 +170,7 @@ bfdev_arch_bit_atomic_change(volatile unsigned long *addr, unsigned int bit, boo #ifndef bfdev_arch_bit_atomic_test # define bfdev_arch_bit_atomic_test bfdev_arch_bit_atomic_test -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_atomic_test(const volatile unsigned long *addr, unsigned int bit) { addr += BFDEV_BITS_WORD(bit); @@ -177,7 +180,7 @@ bfdev_arch_bit_atomic_test(const volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_atomic_test_clr # define bfdev_arch_bit_atomic_test_clr bfdev_arch_bit_atomic_test_clr -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_atomic_test_clr(volatile unsigned long *addr, unsigned int bit) { unsigned long old; @@ -193,7 +196,7 @@ bfdev_arch_bit_atomic_test_clr(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_atomic_test_set # define bfdev_arch_bit_atomic_test_set bfdev_arch_bit_atomic_test_set -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_atomic_test_set(volatile unsigned long *addr, unsigned int bit) { unsigned long old; @@ -209,7 +212,7 @@ bfdev_arch_bit_atomic_test_set(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_atomic_test_flip # define bfdev_arch_bit_atomic_test_flip bfdev_arch_bit_atomic_test_flip -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_arch_bit_atomic_test_flip(volatile unsigned long *addr, unsigned int bit) { unsigned long old; @@ -221,8 +224,9 @@ bfdev_arch_bit_atomic_test_flip(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_arch_bit_atomic_test_change # define bfdev_arch_bit_atomic_test_change bfdev_arch_bit_atomic_test_change -static __bfdev_always_inline bool -bfdev_arch_bit_atomic_test_change(volatile unsigned long *addr, unsigned int bit, bool val) +static __bfdev_always_inline bfdev_bool +bfdev_arch_bit_atomic_test_change(volatile unsigned long *addr, unsigned int bit, + bfdev_bool val) { unsigned long old; addr += BFDEV_BITS_WORD(bit); @@ -241,8 +245,8 @@ bfdev_arch_bit_atomic_test_change(volatile unsigned long *addr, unsigned int bit */ #ifndef bfdev_arch_rol8 # define bfdev_arch_rol8 bfdev_arch_rol8 -static __bfdev_always_inline uint8_t -bfdev_arch_rol8(uint8_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u8 +bfdev_arch_rol8(bfdev_u8 value, unsigned int shift) { return (value << (shift & 7)) | (value >> ((-shift) & 7)); } @@ -255,8 +259,8 @@ bfdev_arch_rol8(uint8_t value, unsigned int shift) */ #ifndef bfdev_arch_ror8 # define bfdev_arch_ror8 bfdev_arch_ror8 -static __bfdev_always_inline uint8_t -bfdev_arch_ror8(uint8_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u8 +bfdev_arch_ror8(bfdev_u8 value, unsigned int shift) { return (value >> (shift & 7)) | (value << ((-shift) & 7)); } @@ -269,8 +273,8 @@ bfdev_arch_ror8(uint8_t value, unsigned int shift) */ #ifndef bfdev_arch_rol16 # define bfdev_arch_rol16 bfdev_arch_rol16 -static __bfdev_always_inline uint16_t -bfdev_arch_rol16(uint16_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u16 +bfdev_arch_rol16(bfdev_u16 value, unsigned int shift) { return (value << (shift & 15)) | (value >> ((-shift) & 15)); } @@ -283,8 +287,8 @@ bfdev_arch_rol16(uint16_t value, unsigned int shift) */ #ifndef bfdev_arch_ror16 # define bfdev_arch_ror16 bfdev_arch_ror16 -static __bfdev_always_inline uint16_t -bfdev_arch_ror16(uint16_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u16 +bfdev_arch_ror16(bfdev_u16 value, unsigned int shift) { return (value >> (shift & 15)) | (value << ((-shift) & 15)); } @@ -297,8 +301,8 @@ bfdev_arch_ror16(uint16_t value, unsigned int shift) */ #ifndef bfdev_arch_rol32 # define bfdev_arch_rol32 bfdev_arch_rol32 -static __bfdev_always_inline uint32_t -bfdev_arch_rol32(uint32_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u32 +bfdev_arch_rol32(bfdev_u32 value, unsigned int shift) { return (value << (shift & 31)) | (value >> ((-shift) & 31)); } @@ -311,8 +315,8 @@ bfdev_arch_rol32(uint32_t value, unsigned int shift) */ #ifndef bfdev_arch_ror32 # define bfdev_arch_ror32 bfdev_arch_ror32 -static __bfdev_always_inline uint32_t -bfdev_arch_ror32(uint32_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u32 +bfdev_arch_ror32(bfdev_u32 value, unsigned int shift) { return (value >> (shift & 31)) | (value << ((-shift) & 31)); } @@ -325,8 +329,8 @@ bfdev_arch_ror32(uint32_t value, unsigned int shift) */ #ifndef bfdev_arch_rol64 # define bfdev_arch_rol64 bfdev_arch_rol64 -static __bfdev_always_inline uint64_t -bfdev_arch_rol64(uint64_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u64 +bfdev_arch_rol64(bfdev_u64 value, unsigned int shift) { return (value << (shift & 63)) | (value >> ((-shift) & 63)); } @@ -339,8 +343,8 @@ bfdev_arch_rol64(uint64_t value, unsigned int shift) */ #ifndef bfdev_arch_ror64 # define bfdev_arch_ror64 bfdev_arch_ror64 -static __bfdev_always_inline uint64_t -bfdev_arch_ror64(uint64_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u64 +bfdev_arch_ror64(bfdev_u64 value, unsigned int shift) { return (value >> (shift & 63)) | (value << ((-shift) & 63)); } @@ -502,7 +506,7 @@ bfdev_arch_fls(unsigned long value) static __bfdev_always_inline unsigned int bfdev_arch_ffz(unsigned long value) { - if (value == ULONG_MAX) + if (value == BFDEV_ULONG_MAX) return 0; return bfdev_arch_ffs(~value); } @@ -517,7 +521,7 @@ bfdev_arch_ffz(unsigned long value) static __bfdev_always_inline unsigned int bfdev_arch_flz(unsigned long value) { - if (value == ULONG_MAX) + if (value == BFDEV_ULONG_MAX) return 0; return bfdev_arch_fls(~value); } @@ -532,7 +536,7 @@ bfdev_arch_flz(unsigned long value) static __bfdev_always_inline unsigned int bfdev_arch_ctz(unsigned long value) { - if (value == ULONG_MAX) + if (value == BFDEV_ULONG_MAX) return 0; if (!value) return BFDEV_BITS_PER_LONG; @@ -549,7 +553,7 @@ bfdev_arch_ctz(unsigned long value) static __bfdev_always_inline unsigned int bfdev_arch_clz(unsigned long value) { - if (value == ULONG_MAX) + if (value == BFDEV_ULONG_MAX) return 0; if (!value) return BFDEV_BITS_PER_LONG; @@ -564,7 +568,7 @@ bfdev_arch_ffnsp(unsigned long word, unsigned int *nr) { unsigned int bit; - if (word == ULONG_MAX) + if (word == BFDEV_ULONG_MAX) return *nr; while (word) { @@ -585,7 +589,7 @@ bfdev_arch_flnsp(unsigned long word, unsigned int *nr) { unsigned int bit; - if (word == ULONG_MAX) + if (word == BFDEV_ULONG_MAX) return *nr; while (word) { diff --git a/include/bfdev/asm-generic/byteorder.h b/include/bfdev/asm-generic/byteorder.h index 017b2bf0..a8c90e55 100644 --- a/include/bfdev/asm-generic/byteorder.h +++ b/include/bfdev/asm-generic/byteorder.h @@ -20,72 +20,72 @@ BFDEV_BEGIN_DECLS #define BFDEV_GENERIC_BYTEORDER_ARRAY(name, type1, type2, func) \ static inline void \ -name(type1 *dest, const type2 *src, size_t size) \ +name(type1 *dest, const type2 *src, bfdev_size_t size) \ { \ - size_t index; \ + bfdev_size_t index; \ \ - for (index = 0; index < size; ++index) \ - dest[index] = func(src[index]); \ + for (index = 0; index < size; ++index) \ + dest[index] = func(src[index]); \ } BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_cpu_to_le16_array, - bfdev_le16, uint16_t, bfdev_cpu_to_le16 + bfdev_le16, bfdev_u16, bfdev_cpu_to_le16 ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_cpu_to_le32_array, - bfdev_le32, uint32_t, bfdev_cpu_to_le32 + bfdev_le32, bfdev_u32, bfdev_cpu_to_le32 ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_cpu_to_le64_array, - bfdev_le64, uint64_t, bfdev_cpu_to_le64 + bfdev_le64, bfdev_u64, bfdev_cpu_to_le64 ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_le16_to_cpu_array, - uint16_t, bfdev_le16, bfdev_le16_to_cpu + bfdev_u16, bfdev_le16, bfdev_le16_to_cpu ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_le32_to_cpu_array, - uint32_t, bfdev_le32, bfdev_le32_to_cpu + bfdev_u32, bfdev_le32, bfdev_le32_to_cpu ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_le64_to_cpu_array, - uint64_t, bfdev_le64, bfdev_le64_to_cpu + bfdev_u64, bfdev_le64, bfdev_le64_to_cpu ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_cpu_to_be16_array, - bfdev_be16, uint16_t, bfdev_cpu_to_be16 + bfdev_be16, bfdev_u16, bfdev_cpu_to_be16 ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_cpu_to_be32_array, - bfdev_be32, uint32_t, bfdev_cpu_to_be32 + bfdev_be32, bfdev_u32, bfdev_cpu_to_be32 ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_cpu_to_be64_array, - bfdev_be64, uint64_t, bfdev_cpu_to_be64 + bfdev_be64, bfdev_u64, bfdev_cpu_to_be64 ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_be16_to_cpu_array, - uint16_t, bfdev_be16, bfdev_be16_to_cpu + bfdev_u16, bfdev_be16, bfdev_be16_to_cpu ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_be32_to_cpu_array, - uint32_t, bfdev_be32, bfdev_be32_to_cpu + bfdev_u32, bfdev_be32, bfdev_be32_to_cpu ) BFDEV_GENERIC_BYTEORDER_ARRAY( bfdev_be64_to_cpu_array, - uint64_t, bfdev_be64, bfdev_be64_to_cpu + bfdev_u64, bfdev_be64, bfdev_be64_to_cpu ) BFDEV_END_DECLS diff --git a/include/bfdev/asm-generic/cmpxchg.h b/include/bfdev/asm-generic/cmpxchg.h index d0a96ae5..0e169753 100644 --- a/include/bfdev/asm-generic/cmpxchg.h +++ b/include/bfdev/asm-generic/cmpxchg.h @@ -16,7 +16,8 @@ BFDEV_BEGIN_DECLS #ifndef bfdev_arch_cmpxchg # define bfdev_arch_cmpxchg bfdev_arch_cmpxchg static __bfdev_always_inline bfdev_atomic_t -bfdev_arch_cmpxchg(bfdev_atomic_t *atomic, bfdev_atomic_t old, bfdev_atomic_t value) +bfdev_arch_cmpxchg(bfdev_atomic_t *atomic, bfdev_atomic_t old, + bfdev_atomic_t value) { return __sync_val_compare_and_swap(atomic, old, value); } @@ -40,8 +41,9 @@ bfdev_arch_xchg(bfdev_atomic_t *atomic, bfdev_atomic_t value) #ifndef bfdev_arch_try_cmpxchg # define bfdev_arch_try_cmpxchg bfdev_arch_try_cmpxchg -static __bfdev_always_inline bool -bfdev_arch_try_cmpxchg(bfdev_atomic_t *atomic, bfdev_atomic_t *old, bfdev_atomic_t value) +static __bfdev_always_inline bfdev_bool +bfdev_arch_try_cmpxchg(bfdev_atomic_t *atomic, bfdev_atomic_t *old, + bfdev_atomic_t value) { bfdev_atomic_t result, prev; diff --git a/include/bfdev/asm-generic/dword-compiler.h b/include/bfdev/asm-generic/dword-compiler.h index 31961603..e2a3e788 100644 --- a/include/bfdev/asm-generic/dword-compiler.h +++ b/include/bfdev/asm-generic/dword-compiler.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #if BFDEV_BITS_PER_LONG == 32 -typedef uint64_t bfdev_dword_t; +typedef bfdev_u64 bfdev_dword_t; #else typedef unsigned __int128 bfdev_dword_t; #endif diff --git a/include/bfdev/asm-generic/types.h b/include/bfdev/asm-generic/types.h new file mode 100644 index 00000000..c5a2b459 --- /dev/null +++ b/include/bfdev/asm-generic/types.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#ifndef _BFDEV_ASM_GENERIC_TYPES_H_ +#define _BFDEV_ASM_GENERIC_TYPES_H_ + +#include + +BFDEV_BEGIN_DECLS + +typedef __signed__ char bfdev_s8; +typedef __signed__ short bfdev_s16; +typedef __signed__ int bfdev_s32; + +typedef unsigned char bfdev_u8; +typedef unsigned short bfdev_u16; +typedef unsigned int bfdev_u32; + +#ifdef __GNUC__ +__extension__ typedef __signed__ long long bfdev_s64; +__extension__ typedef unsigned long long bfdev_u64; +#else +typedef __signed__ long long bfdev_s64; +typedef unsigned long long bfdev_u64; +#endif + +typedef unsigned long bfdev_size_t; +typedef bfdev_s64 bfdev_intmax_t; +typedef bfdev_u64 bfdev_uintmax_t; + +typedef unsigned long bfdev_uintptr_t; +typedef __signed__ long bfdev_intptr_t; +typedef __signed__ long bfdev_ptrdiff_t; + +BFDEV_END_DECLS + +#endif /* _BFDEV_ASM_GENERIC_TYPES_H_ */ diff --git a/include/bfdev/asm-generic/unaligned.h b/include/bfdev/asm-generic/unaligned.h index 79207609..bae15abc 100644 --- a/include/bfdev/asm-generic/unaligned.h +++ b/include/bfdev/asm-generic/unaligned.h @@ -76,61 +76,61 @@ bfdev_arch_unaligned_set_ulong(void *p, unsigned long val) #ifndef bfdev_arch_unaligned_get_u16 # define bfdev_arch_unaligned_get_u16 bfdev_arch_unaligned_get_u16 -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_arch_unaligned_get_u16(const void *p) { - return bfdev_arch_unaligned_get_type(uint16_t, p); + return bfdev_arch_unaligned_get_type(bfdev_u16, p); } #endif #ifndef bfdev_arch_unaligned_get_u32 # define bfdev_arch_unaligned_get_u32 bfdev_arch_unaligned_get_u32 -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_arch_unaligned_get_u32(const void *p) { - return bfdev_arch_unaligned_get_type(uint32_t, p); + return bfdev_arch_unaligned_get_type(bfdev_u32, p); } #endif #ifndef bfdev_arch_unaligned_get_u64 # define bfdev_arch_unaligned_get_u64 bfdev_arch_unaligned_get_u64 -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_arch_unaligned_get_u64(const void *p) { - return bfdev_arch_unaligned_get_type(uint64_t, p); + return bfdev_arch_unaligned_get_type(bfdev_u64, p); } #endif #ifndef bfdev_arch_unaligned_set_u16 # define bfdev_arch_unaligned_set_u16 bfdev_arch_unaligned_set_u16 static __bfdev_always_inline void -bfdev_arch_unaligned_set_u16(void *p, uint16_t val) +bfdev_arch_unaligned_set_u16(void *p, bfdev_u16 val) { - bfdev_arch_unaligned_set_type(uint16_t, p, val); + bfdev_arch_unaligned_set_type(bfdev_u16, p, val); } #endif #ifndef bfdev_arch_unaligned_set_u32 # define bfdev_arch_unaligned_set_u32 bfdev_arch_unaligned_set_u32 static __bfdev_always_inline void -bfdev_arch_unaligned_set_u32(void *p, uint32_t val) +bfdev_arch_unaligned_set_u32(void *p, bfdev_u32 val) { - bfdev_arch_unaligned_set_type(uint32_t, p, val); + bfdev_arch_unaligned_set_type(bfdev_u32, p, val); } #endif #ifndef bfdev_arch_unaligned_set_u64 # define bfdev_arch_unaligned_set_u64 bfdev_arch_unaligned_set_u64 static __bfdev_always_inline void -bfdev_arch_unaligned_set_u64(void *p, uint64_t val) +bfdev_arch_unaligned_set_u64(void *p, bfdev_u64 val) { - bfdev_arch_unaligned_set_type(uint64_t, p, val); + bfdev_arch_unaligned_set_type(bfdev_u64, p, val); } #endif #ifndef bfdev_arch_unaligned_get_le16 # define bfdev_arch_unaligned_get_le16 bfdev_arch_unaligned_get_le16 -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_arch_unaligned_get_le16(const void *p) { return bfdev_le16_to_cpu(bfdev_arch_unaligned_get_type(bfdev_le16, p)); @@ -139,7 +139,7 @@ bfdev_arch_unaligned_get_le16(const void *p) #ifndef bfdev_arch_unaligned_get_le32 # define bfdev_arch_unaligned_get_le32 bfdev_arch_unaligned_get_le32 -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_arch_unaligned_get_le32(const void *p) { return bfdev_le32_to_cpu(bfdev_arch_unaligned_get_type(bfdev_le32, p)); @@ -148,7 +148,7 @@ bfdev_arch_unaligned_get_le32(const void *p) #ifndef bfdev_arch_unaligned_get_le64 # define bfdev_arch_unaligned_get_le64 bfdev_arch_unaligned_get_le64 -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_arch_unaligned_get_le64(const void *p) { return bfdev_le64_to_cpu(bfdev_arch_unaligned_get_type(bfdev_le64, p)); @@ -158,7 +158,7 @@ bfdev_arch_unaligned_get_le64(const void *p) #ifndef bfdev_arch_unaligned_set_le16 # define bfdev_arch_unaligned_set_le16 bfdev_arch_unaligned_set_le16 static __bfdev_always_inline void -bfdev_arch_unaligned_set_le16(void *p, uint16_t val) +bfdev_arch_unaligned_set_le16(void *p, bfdev_u16 val) { bfdev_arch_unaligned_set_type(bfdev_le16, p, bfdev_cpu_to_le16(val)); } @@ -167,7 +167,7 @@ bfdev_arch_unaligned_set_le16(void *p, uint16_t val) #ifndef bfdev_arch_unaligned_set_le32 # define bfdev_arch_unaligned_set_le32 bfdev_arch_unaligned_set_le32 static __bfdev_always_inline void -bfdev_arch_unaligned_set_le32(void *p, uint32_t val) +bfdev_arch_unaligned_set_le32(void *p, bfdev_u32 val) { bfdev_arch_unaligned_set_type(bfdev_le32, p, bfdev_cpu_to_le32(val)); } @@ -176,7 +176,7 @@ bfdev_arch_unaligned_set_le32(void *p, uint32_t val) #ifndef bfdev_arch_unaligned_set_le64 # define bfdev_arch_unaligned_set_le64 bfdev_arch_unaligned_set_le64 static __bfdev_always_inline void -bfdev_arch_unaligned_set_le64(void *p, uint64_t val) +bfdev_arch_unaligned_set_le64(void *p, bfdev_u64 val) { bfdev_arch_unaligned_set_type(bfdev_le64, p, bfdev_cpu_to_le64(val)); } @@ -184,7 +184,7 @@ bfdev_arch_unaligned_set_le64(void *p, uint64_t val) #ifndef bfdev_arch_unaligned_get_be16 # define bfdev_arch_unaligned_get_be16 bfdev_arch_unaligned_get_be16 -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_arch_unaligned_get_be16(const void *p) { return bfdev_be16_to_cpu(bfdev_arch_unaligned_get_type(bfdev_be16, p)); @@ -193,7 +193,7 @@ bfdev_arch_unaligned_get_be16(const void *p) #ifndef bfdev_arch_unaligned_get_be32 # define bfdev_arch_unaligned_get_be32 bfdev_arch_unaligned_get_be32 -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_arch_unaligned_get_be32(const void *p) { return bfdev_be32_to_cpu(bfdev_arch_unaligned_get_type(bfdev_be32, p)); @@ -202,7 +202,7 @@ bfdev_arch_unaligned_get_be32(const void *p) #ifndef bfdev_arch_unaligned_get_be64 # define bfdev_arch_unaligned_get_be64 bfdev_arch_unaligned_get_be64 -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_arch_unaligned_get_be64(const void *p) { return bfdev_be64_to_cpu(bfdev_arch_unaligned_get_type(bfdev_be64, p)); @@ -212,7 +212,7 @@ bfdev_arch_unaligned_get_be64(const void *p) #ifndef bfdev_arch_unaligned_set_be16 # define bfdev_arch_unaligned_set_be16 bfdev_arch_unaligned_set_be16 static __bfdev_always_inline void -bfdev_arch_unaligned_set_be16(void *p, uint16_t val) +bfdev_arch_unaligned_set_be16(void *p, bfdev_u16 val) { bfdev_arch_unaligned_set_type(bfdev_be16, p, bfdev_cpu_to_be16(val)); } @@ -221,7 +221,7 @@ bfdev_arch_unaligned_set_be16(void *p, uint16_t val) #ifndef bfdev_arch_unaligned_set_be32 # define bfdev_arch_unaligned_set_be32 bfdev_arch_unaligned_set_be32 static __bfdev_always_inline void -bfdev_arch_unaligned_set_be32(void *p, uint32_t val) +bfdev_arch_unaligned_set_be32(void *p, bfdev_u32 val) { bfdev_arch_unaligned_set_type(bfdev_be32, p, bfdev_cpu_to_be32(val)); } @@ -230,7 +230,7 @@ bfdev_arch_unaligned_set_be32(void *p, uint32_t val) #ifndef bfdev_arch_unaligned_set_be64 # define bfdev_arch_unaligned_set_be64 bfdev_arch_unaligned_set_be64 static __bfdev_always_inline void -bfdev_arch_unaligned_set_be64(void *p, uint64_t val) +bfdev_arch_unaligned_set_be64(void *p, bfdev_u64 val) { bfdev_arch_unaligned_set_type(bfdev_be64, p, bfdev_cpu_to_be64(val)); } diff --git a/include/bfdev/base32.h b/include/bfdev/base32.h index d7a939a8..76775f31 100644 --- a/include/bfdev/base32.h +++ b/include/bfdev/base32.h @@ -17,8 +17,8 @@ BFDEV_BEGIN_DECLS * bfdev_base32_encode_length() - base32 encode buffer length. * @size: length to encode. */ -static inline size_t -bfdev_base32_encode_length(size_t size) +static inline bfdev_size_t +bfdev_base32_encode_length(bfdev_size_t size) { return BFDEV_DIV_ROUND_UP(size, 5) * 8; } @@ -27,8 +27,8 @@ bfdev_base32_encode_length(size_t size) * bfdev_base32_decode_length() - base32 decoder buffer length. * @size: length to decode. */ -static inline size_t -bfdev_base32_decode_length(size_t size) +static inline bfdev_size_t +bfdev_base32_decode_length(bfdev_size_t size) { return BFDEV_DIV_ROUND_UP(size, 8) * 5; } @@ -40,7 +40,7 @@ bfdev_base32_decode_length(size_t size) * @size: length of @data. */ extern void __bfdev_nonnull(1, 2) -bfdev_base32_encode(void *buff, const void *data, size_t size); +bfdev_base32_encode(void *buff, const void *data, bfdev_size_t size); /** * bfdev_base32_decode() - base32 decoder. @@ -49,7 +49,7 @@ bfdev_base32_encode(void *buff, const void *data, size_t size); * @size: length of @data. */ extern int __bfdev_nonnull(1, 2) -bfdev_base32_decode(void *buff, const void *data, size_t size); +bfdev_base32_decode(void *buff, const void *data, bfdev_size_t size); BFDEV_END_DECLS diff --git a/include/bfdev/base64.h b/include/bfdev/base64.h index 1ce8d0a1..2cebd17d 100644 --- a/include/bfdev/base64.h +++ b/include/bfdev/base64.h @@ -17,8 +17,8 @@ BFDEV_BEGIN_DECLS * bfdev_base64_encode_length() - base64 encode buffer length. * @size: length to encode. */ -static inline size_t -bfdev_base64_encode_length(size_t size) +static inline bfdev_size_t +bfdev_base64_encode_length(bfdev_size_t size) { return BFDEV_DIV_ROUND_UP(size, 3) * 4; } @@ -27,8 +27,8 @@ bfdev_base64_encode_length(size_t size) * bfdev_base64_decode_length() - base64 decoder buffer length. * @size: length to decode. */ -static inline size_t -bfdev_base64_decode_length(size_t size) +static inline bfdev_size_t +bfdev_base64_decode_length(bfdev_size_t size) { return BFDEV_DIV_ROUND_UP(size, 4) * 3; } @@ -40,7 +40,7 @@ bfdev_base64_decode_length(size_t size) * @size: length of @data. */ extern void -bfdev_base64_encode(void *buff, const void *data, size_t size); +bfdev_base64_encode(void *buff, const void *data, bfdev_size_t size); /** * bfdev_base64_decode() - base64 decoder. @@ -49,7 +49,7 @@ bfdev_base64_encode(void *buff, const void *data, size_t size); * @size: length of @data. */ extern int -bfdev_base64_decode(void *buff, const void *data, size_t size); +bfdev_base64_decode(void *buff, const void *data, bfdev_size_t size); BFDEV_END_DECLS diff --git a/include/bfdev/bcd.h b/include/bfdev/bcd.h index ffb4a744..798add56 100644 --- a/include/bfdev/bcd.h +++ b/include/bfdev/bcd.h @@ -28,20 +28,20 @@ BFDEV_BEGIN_DECLS * Interface for known dynamic arguments */ -extern const uint8_t +extern const bfdev_u8 bfdev_bcd2bin_table[256]; -extern const uint8_t +extern const bfdev_u8 bfdev_bin2bcd_table[256]; static __bfdev_attribute_const __bfdev_always_inline -uint8_t bfdev_bcd2bin_dynamic(uint8_t bcd) +bfdev_u8 bfdev_bcd2bin_dynamic(bfdev_u8 bcd) { return bfdev_bcd2bin_table[bcd]; } static __bfdev_attribute_const __bfdev_always_inline -uint8_t bfdev_bin2bcd_dynamic(uint8_t bin) +bfdev_u8 bfdev_bin2bcd_dynamic(bfdev_u8 bin) { return bfdev_bin2bcd_table[bin]; } @@ -50,22 +50,22 @@ uint8_t bfdev_bin2bcd_dynamic(uint8_t bin) * bfdev_bcd2bin - convert bcd to bin. * @bcd: the bcd to convert. */ -#define bfdev_bcd2bin(bcd) ({ \ - uint8_t __bcd = (uint8_t)(bcd); \ - __builtin_constant_p(__bcd) \ - ? bfdev_bcd2bin_const(__bcd) \ - : bfdev_bcd2bin_dynamic(__bcd); \ +#define bfdev_bcd2bin(bcd) ({ \ + bfdev_u8 __bcd = (bfdev_u8)(bcd); \ + __builtin_constant_p(__bcd) \ + ? bfdev_bcd2bin_const(__bcd) \ + : bfdev_bcd2bin_dynamic(__bcd); \ }) /** * bfdev_bin2bcd - convert bin to bcd. * @bin: the bin to convert. */ -#define bfdev_bin2bcd(bin) ({ \ - uint8_t __bin = (uint8_t)(bin); \ - __builtin_constant_p(__bin) \ - ? bfdev_bin2bcd_const(__bin) \ - : bfdev_bin2bcd_dynamic(__bin); \ +#define bfdev_bin2bcd(bin) ({ \ + bfdev_u8 __bin = (bfdev_u8)(bin); \ + __builtin_constant_p(__bin) \ + ? bfdev_bin2bcd_const(__bin) \ + : bfdev_bin2bcd_dynamic(__bin); \ }) BFDEV_END_DECLS diff --git a/include/bfdev/bitflags.h b/include/bfdev/bitflags.h index 318292b6..4cb3aacf 100644 --- a/include/bfdev/bitflags.h +++ b/include/bfdev/bitflags.h @@ -7,51 +7,52 @@ #define _BFDEV_BITFLAGS_H_ #include +#include #include BFDEV_BEGIN_DECLS -#define BFDEV_GENERIC_BITFLAGS(name, func, type, member, index) \ -static __bfdev_always_inline void \ -name##_clr(type *ptr) \ -{ \ - bfdev_bit##func##_clr(member, index); \ -} \ - \ -static __bfdev_always_inline void \ -name##_set(type *ptr) \ -{ \ - bfdev_bit##func##_set(member, index); \ -} \ - \ -static __bfdev_always_inline void \ -name##_flip(type *ptr) \ -{ \ - bfdev_bit##func##_flip(member, index); \ -} \ - \ -static __bfdev_always_inline bool \ -name##_test(const type *ptr) \ -{ \ - return bfdev_bit##func##_test(member, index); \ -} \ - \ -static __bfdev_always_inline bool \ -name##_test_clr(type *ptr) \ -{ \ - return bfdev_bit##func##_test_clr(member, index); \ -} \ - \ -static __bfdev_always_inline bool \ -name##_test_set(type *ptr) \ -{ \ - return bfdev_bit##func##_test_set(member, index); \ -} \ - \ -static __bfdev_always_inline bool \ -name##_test_flip(type *ptr) \ -{ \ - return bfdev_bit##func##_test_flip(member, index); \ +#define BFDEV_GENERIC_BITFLAGS(name, func, type, member, index) \ +static __bfdev_always_inline void \ +name##_clr(type *ptr) \ +{ \ + bfdev_bit##func##_clr(member, index); \ +} \ + \ +static __bfdev_always_inline void \ +name##_set(type *ptr) \ +{ \ + bfdev_bit##func##_set(member, index); \ +} \ + \ +static __bfdev_always_inline void \ +name##_flip(type *ptr) \ +{ \ + bfdev_bit##func##_flip(member, index); \ +} \ + \ +static __bfdev_always_inline bfdev_bool \ +name##_test(const type *ptr) \ +{ \ + return bfdev_bit##func##_test(member, index); \ +} \ + \ +static __bfdev_always_inline bfdev_bool \ +name##_test_clr(type *ptr) \ +{ \ + return bfdev_bit##func##_test_clr(member, index); \ +} \ + \ +static __bfdev_always_inline bfdev_bool \ +name##_test_set(type *ptr) \ +{ \ + return bfdev_bit##func##_test_set(member, index); \ +} \ + \ +static __bfdev_always_inline bfdev_bool \ +name##_test_flip(type *ptr) \ +{ \ + return bfdev_bit##func##_test_flip(member, index); \ } #define BFDEV_BITFLAGS(name, index) \ diff --git a/include/bfdev/bitmap-comp.h b/include/bfdev/bitmap-comp.h index 7d9ea0ff..f190aa34 100644 --- a/include/bfdev/bitmap-comp.h +++ b/include/bfdev/bitmap-comp.h @@ -11,23 +11,23 @@ BFDEV_BEGIN_DECLS -extern bool +extern bfdev_bool bfdev_bitmap_comp_equal(const unsigned long *src1, const unsigned long *src2, unsigned int bits); -extern bool +extern bfdev_bool bfdev_bitmap_comp_or_equal(const unsigned long *src1, const unsigned long *src2, const unsigned long *src3, unsigned int bits); -extern bool +extern bfdev_bool bfdev_bitmap_comp_intersects(const unsigned long *src1, const unsigned long *src2, unsigned int bits); -extern bool +extern bfdev_bool bfdev_bitmap_comp_and(unsigned long *dest, const unsigned long *src1, const unsigned long *src2, unsigned int bits); -extern bool +extern bfdev_bool bfdev_bitmap_comp_andnot(unsigned long *dest, const unsigned long *src1, const unsigned long *src2, unsigned int bits); diff --git a/include/bfdev/bitmap.h b/include/bfdev/bitmap.h index 70235e47..587db470 100644 --- a/include/bfdev/bitmap.h +++ b/include/bfdev/bitmap.h @@ -36,7 +36,7 @@ BFDEV_BEGIN_DECLS bfdev_align_check(bits, BFDEV_BITMAP_ALIGN) \ ) -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bitmap_empty(const unsigned long *src, unsigned int bits) { if (bfdev_const_small_nbits(bits)) @@ -48,7 +48,7 @@ bfdev_bitmap_empty(const unsigned long *src, unsigned int bits) return !bfdev_memdiff(src, BFDEV_UINT8_MIN, bits / BFDEV_BITS_PER_BYTE); } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bitmap_full(const unsigned long *src, unsigned int bits) { if (bfdev_const_small_nbits(bits)) @@ -60,7 +60,7 @@ bfdev_bitmap_full(const unsigned long *src, unsigned int bits) return !bfdev_memdiff(src, BFDEV_UINT8_MAX, bits / BFDEV_BITS_PER_BYTE); } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bitmap_equal(const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -70,10 +70,10 @@ bfdev_bitmap_equal(const unsigned long *src1, const unsigned long *src2, if (!bfdev_bitmap_const_aligned(bits)) return bfdev_bitmap_comp_equal(src1, src2, bits); - return bfport_memcmp(src1, src2, bits / BFDEV_BITS_PER_BYTE); + return bfdev_memcmp(src1, src2, bits / BFDEV_BITS_PER_BYTE); } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bitmap_or_equal(const unsigned long *src1, const unsigned long *src2, const unsigned long *src3, unsigned int bits) { @@ -86,7 +86,7 @@ bfdev_bitmap_or_equal(const unsigned long *src1, const unsigned long *src2, return !!(value & BFDEV_BIT_LOW_MASK(bits)); } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bitmap_intersects(const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -99,7 +99,7 @@ bfdev_bitmap_intersects(const unsigned long *src1, const unsigned long *src2, return !!(value & BFDEV_BIT_LOW_MASK(bits)); } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bitmap_and(unsigned long *dest, const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -112,7 +112,7 @@ bfdev_bitmap_and(unsigned long *dest, const unsigned long *src1, return !!(*dest = (value & BFDEV_BIT_LOW_MASK(bits))); } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bitmap_andnot(unsigned long *dest, const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -193,7 +193,7 @@ bfdev_bitmap_complement(unsigned long *dest, const unsigned long *src, static __bfdev_always_inline void bfdev_bitmap_set(unsigned long *bitmap, unsigned int start, unsigned int bits) { - size_t size, offset; + bfdev_size_t size, offset; if (__builtin_constant_p(bits) && bits == 1) return bfdev_bit_set(bitmap, start); @@ -205,13 +205,13 @@ bfdev_bitmap_set(unsigned long *bitmap, unsigned int start, unsigned int bits) offset = start / BFDEV_BITS_PER_BYTE; size = bits / BFDEV_BITS_PER_BYTE; - bfport_memset((char *)bitmap + offset, 0xff, size); + bfdev_memset((char *)bitmap + offset, 0xff, size); } static __bfdev_always_inline void bfdev_bitmap_clr(unsigned long *bitmap, unsigned int start, unsigned int bits) { - size_t size, offset; + bfdev_size_t size, offset; if (__builtin_constant_p(bits) && bits == 1) return bfdev_bit_clr(bitmap, start); @@ -223,7 +223,7 @@ bfdev_bitmap_clr(unsigned long *bitmap, unsigned int start, unsigned int bits) offset = start / BFDEV_BITS_PER_BYTE; size = bits / BFDEV_BITS_PER_BYTE; - bfport_memset((char *)bitmap + offset, 0, size); + bfdev_memset((char *)bitmap + offset, 0, size); } static __bfdev_always_inline void @@ -237,7 +237,7 @@ bfdev_bitmap_zero(unsigned long *bitmap, unsigned int bits) } length = BFDEV_BITS_TO_U8(bits); - bfport_memset(bitmap, 0, length); + bfdev_memset(bitmap, 0, length); } static __bfdev_always_inline void @@ -251,7 +251,7 @@ bfdev_bitmap_fill(unsigned long *bitmap, unsigned int bits) } length = BFDEV_BITS_TO_U8(bits); - bfport_memset(bitmap, BFDEV_UINT8_MAX, length); + bfdev_memset(bitmap, BFDEV_UINT8_MAX, length); } static __bfdev_always_inline void @@ -265,7 +265,7 @@ bfdev_bitmap_copy(unsigned long *dest, unsigned long *src, unsigned int bits) } length = BFDEV_BITS_TO_U8(bits); - bfport_memcpy(dest, src, length); + bfdev_memcpy(dest, src, length); } BFDEV_END_DECLS diff --git a/include/bfdev/bitops-endian.h b/include/bfdev/bitops-endian.h index f86ef212..a4573bf6 100644 --- a/include/bfdev/bitops-endian.h +++ b/include/bfdev/bitops-endian.h @@ -42,30 +42,30 @@ bfdev_bit_flip_le(void *addr, unsigned int bit) } static inline void -bfdev_bit_change_le(void *addr, unsigned int bit, bool val) +bfdev_bit_change_le(void *addr, unsigned int bit, bfdev_bool val) { bfdev_bit_change(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE, val); } -static inline bool +static inline bfdev_bool bfdev_bit_test_le(const void *addr, unsigned int bit) { return bfdev_bit_test(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_test_clr_le(void *addr, unsigned int bit) { return bfdev_bit_test_clr(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_test_set_le(void *addr, unsigned int bit) { return bfdev_bit_test_set(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_test_flip_le(void *addr, unsigned int bit) { return bfdev_bit_test_flip(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); @@ -90,37 +90,37 @@ bfdev_bit_atomic_flip_le(void *addr, unsigned int bit) } static inline void -bfdev_bit_atomic_change_le(void *addr, unsigned int bit, bool val) +bfdev_bit_atomic_change_le(void *addr, unsigned int bit, bfdev_bool val) { bfdev_bit_atomic_change(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE, val); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_le(const void *addr, unsigned int bit) { return bfdev_bit_atomic_test(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_clr_le(void *addr, unsigned int bit) { return bfdev_bit_atomic_test_clr(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_set_le(void *addr, unsigned int bit) { return bfdev_bit_atomic_test_set(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_flip_le(void *addr, unsigned int bit) { return bfdev_bit_atomic_test_flip(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE); } -static inline bool -bfdev_bit_atomic_test_change_le(void *addr, unsigned int bit, bool val) +static inline bfdev_bool +bfdev_bit_atomic_test_change_le(void *addr, unsigned int bit, bfdev_bool val) { return bfdev_bit_atomic_test_change(addr, bit ^ BFDEV_BITOPS_LE_SWIZZLE, val); } @@ -144,37 +144,37 @@ bfdev_bit_flip_be(void *addr, unsigned int bit) } static inline void -bfdev_bit_change_be(void *addr, unsigned int bit, bool val) +bfdev_bit_change_be(void *addr, unsigned int bit, bfdev_bool val) { bfdev_bit_change(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE, val); } -static inline bool +static inline bfdev_bool bfdev_bit_test_be(const void *addr, unsigned int bit) { return bfdev_bit_test(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_test_clr_be(void *addr, unsigned int bit) { return bfdev_bit_test_clr(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_test_set_be(void *addr, unsigned int bit) { return bfdev_bit_test_set(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_test_flip_be(void *addr, unsigned int bit) { return bfdev_bit_test_flip(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool -bfdev_bit_test_change_be(void *addr, unsigned int bit, bool val) +static inline bfdev_bool +bfdev_bit_test_change_be(void *addr, unsigned int bit, bfdev_bool val) { return bfdev_bit_test_change(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE, val); } @@ -198,37 +198,37 @@ bfdev_bit_atomic_flip_be(void *addr, unsigned int bit) } static inline void -bfdev_bit_atomic_change_be(void *addr, unsigned int bit, bool val) +bfdev_bit_atomic_change_be(void *addr, unsigned int bit, bfdev_bool val) { bfdev_bit_atomic_change(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE, val); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_be(const void *addr, unsigned int bit) { return bfdev_bit_atomic_test(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_clr_be(void *addr, unsigned int bit) { return bfdev_bit_atomic_test_clr(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_set_be(void *addr, unsigned int bit) { return bfdev_bit_atomic_test_set(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool +static inline bfdev_bool bfdev_bit_atomic_test_flip_be(void *addr, unsigned int bit) { return bfdev_bit_atomic_test_flip(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE); } -static inline bool -bfdev_bit_atomic_test_change_be(void *addr, unsigned int bit, bool val) +static inline bfdev_bool +bfdev_bit_atomic_test_change_be(void *addr, unsigned int bit, bfdev_bool val) { return bfdev_bit_atomic_test_change(addr, bit ^ BFDEV_BITOPS_BE_SWIZZLE, val); } diff --git a/include/bfdev/bitops.h b/include/bfdev/bitops.h index d1fa1e76..69e316d9 100644 --- a/include/bfdev/bitops.h +++ b/include/bfdev/bitops.h @@ -71,14 +71,14 @@ bfdev_bit_flip(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_bit_change static __bfdev_always_inline void -bfdev_bit_change(volatile unsigned long *addr, unsigned int bit, bool val) +bfdev_bit_change(volatile unsigned long *addr, unsigned int bit, bfdev_bool val) { bfdev_arch_bit_change(addr, bit, val); } #endif #ifndef bfdev_bit_test -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_test(const volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_test(addr, bit); @@ -86,7 +86,7 @@ bfdev_bit_test(const volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_test_clr -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_test_clr(volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_test_clr(addr, bit); @@ -94,7 +94,7 @@ bfdev_bit_test_clr(volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_test_set -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_test_set(volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_test_set(addr, bit); @@ -102,7 +102,7 @@ bfdev_bit_test_set(volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_test_flip -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_test_flip(volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_test_flip(addr, bit); @@ -110,8 +110,8 @@ bfdev_bit_test_flip(volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_test_change -static __bfdev_always_inline bool -bfdev_bit_test_change(volatile unsigned long *addr, unsigned int bit, bool val) +static __bfdev_always_inline bfdev_bool +bfdev_bit_test_change(volatile unsigned long *addr, unsigned int bit, bfdev_bool val) { return bfdev_arch_bit_test_change(addr, bit, val); } @@ -143,14 +143,14 @@ bfdev_bit_atomic_flip(volatile unsigned long *addr, unsigned int bit) #ifndef bfdev_bit_atomic_change static __bfdev_always_inline void -bfdev_bit_atomic_change(volatile unsigned long *addr, unsigned int bit, bool val) +bfdev_bit_atomic_change(volatile unsigned long *addr, unsigned int bit, bfdev_bool val) { bfdev_arch_bit_atomic_change(addr, bit, val); } #endif #ifndef bfdev_bit_atomic_test -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_atomic_test(const volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_atomic_test(addr, bit); @@ -158,7 +158,7 @@ bfdev_bit_atomic_test(const volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_atomic_test_clr -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_atomic_test_clr(volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_atomic_test_clr(addr, bit); @@ -166,7 +166,7 @@ bfdev_bit_atomic_test_clr(volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_atomic_test_set -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_atomic_test_set(volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_atomic_test_set(addr, bit); @@ -174,7 +174,7 @@ bfdev_bit_atomic_test_set(volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_atomic_test_flip -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_bit_atomic_test_flip(volatile unsigned long *addr, unsigned int bit) { return bfdev_arch_bit_atomic_test_flip(addr, bit); @@ -182,72 +182,72 @@ bfdev_bit_atomic_test_flip(volatile unsigned long *addr, unsigned int bit) #endif #ifndef bfdev_bit_atomic_test_change -static __bfdev_always_inline bool -bfdev_bit_atomic_test_change(volatile unsigned long *addr, unsigned int bit, bool val) +static __bfdev_always_inline bfdev_bool +bfdev_bit_atomic_test_change(volatile unsigned long *addr, unsigned int bit, bfdev_bool val) { return bfdev_arch_bit_atomic_test_change(addr, bit, val); } #endif #ifndef bfdev_rol8 -static __bfdev_always_inline uint8_t -bfdev_rol8(uint8_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u8 +bfdev_rol8(bfdev_u8 value, unsigned int shift) { return bfdev_arch_rol8(value, shift); } #endif #ifndef bfdev_ror8 -static __bfdev_always_inline uint8_t -bfdev_ror8(uint8_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u8 +bfdev_ror8(bfdev_u8 value, unsigned int shift) { return bfdev_arch_ror8(value, shift); } #endif #ifndef bfdev_rol16 -static __bfdev_always_inline uint16_t -bfdev_rol16(uint16_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u16 +bfdev_rol16(bfdev_u16 value, unsigned int shift) { return bfdev_arch_rol16(value, shift); } #endif #ifndef bfdev_ror16 -static __bfdev_always_inline uint16_t -bfdev_ror16(uint16_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u16 +bfdev_ror16(bfdev_u16 value, unsigned int shift) { return bfdev_arch_ror16(value, shift); } #endif #ifndef bfdev_rol32 -static __bfdev_always_inline uint32_t -bfdev_rol32(uint32_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u32 +bfdev_rol32(bfdev_u32 value, unsigned int shift) { return bfdev_arch_rol32(value, shift); } #endif #ifndef bfdev_ror32 -static __bfdev_always_inline uint32_t -bfdev_ror32(uint32_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u32 +bfdev_ror32(bfdev_u32 value, unsigned int shift) { return bfdev_arch_ror32(value, shift); } #endif #ifndef bfdev_rol64 -static __bfdev_always_inline uint64_t -bfdev_rol64(uint64_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u64 +bfdev_rol64(bfdev_u64 value, unsigned int shift) { return bfdev_arch_rol64(value, shift); } #endif #ifndef bfdev_ror64 -static __bfdev_always_inline uint64_t -bfdev_ror64(uint64_t value, unsigned int shift) +static __bfdev_always_inline bfdev_u64 +bfdev_ror64(bfdev_u64 value, unsigned int shift) { return bfdev_arch_ror64(value, shift); } @@ -399,12 +399,12 @@ bfdev_flnz(unsigned long word, unsigned int nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffsuf64(uint64_t value) +bfdev_ffsuf64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; - if ((uint32_t)value) - return bfdev_ffsuf((uint32_t)value); + if ((bfdev_u32)value) + return bfdev_ffsuf((bfdev_u32)value); return bfdev_ffsuf(hi) + 32; } @@ -414,14 +414,14 @@ bfdev_ffsuf64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_flsuf64(uint64_t value) +bfdev_flsuf64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; if (hi) return bfdev_flsuf(hi) + 32; - return bfdev_flsuf((uint32_t)value); + return bfdev_flsuf((bfdev_u32)value); } #else # define bfdev_flsuf64 bfdev_flsuf @@ -429,12 +429,12 @@ bfdev_flsuf64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffzuf64(uint64_t value) +bfdev_ffzuf64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; - if ((uint32_t)value) - return bfdev_ffzuf((uint32_t)value); + if ((bfdev_u32)value) + return bfdev_ffzuf((bfdev_u32)value); return bfdev_ffzuf(hi) + 32; } @@ -444,14 +444,14 @@ bfdev_ffzuf64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_flzuf64(uint64_t value) +bfdev_flzuf64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; if (hi) return bfdev_flzuf(hi) + 32; - return bfdev_flzuf((uint32_t)value); + return bfdev_flzuf((bfdev_u32)value); } #else # define bfdev_flzuf64 bfdev_flzuf @@ -459,12 +459,12 @@ bfdev_flzuf64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffs64(uint64_t value) +bfdev_ffs64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; - if ((uint32_t)value) - return bfdev_ffs((uint32_t)value); + if ((bfdev_u32)value) + return bfdev_ffs((bfdev_u32)value); return bfdev_ffs(hi) + 32; } @@ -474,14 +474,14 @@ bfdev_ffs64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_fls64(uint64_t value) +bfdev_fls64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; if (hi) return bfdev_fls(hi) + 32; - return bfdev_fls((uint32_t)value); + return bfdev_fls((bfdev_u32)value); } #else # define bfdev_fls64 bfdev_fls @@ -489,12 +489,12 @@ bfdev_fls64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffz64(uint64_t value) +bfdev_ffz64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; - if ((uint32_t)value) - return bfdev_ffz((uint32_t)value); + if ((bfdev_u32)value) + return bfdev_ffz((bfdev_u32)value); return bfdev_ffz(hi) + 32; } @@ -504,14 +504,14 @@ bfdev_ffz64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_flz64(uint64_t value) +bfdev_flz64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; if (hi) return bfdev_flz(hi) + 32; - return bfdev_flz((uint32_t)value); + return bfdev_flz((bfdev_u32)value); } #else # define bfdev_flz64 bfdev_flz @@ -519,11 +519,11 @@ bfdev_flz64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ctz64(uint64_t value) +bfdev_ctz64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; - if ((uint32_t)value) + if ((bfdev_u32)value) return bfdev_ctz(value); return bfdev_ctz(hi) + 32; @@ -534,14 +534,14 @@ bfdev_ctz64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_clz64(uint64_t value) +bfdev_clz64(bfdev_u64 value) { - uint32_t hi = value >> 32; + bfdev_u32 hi = value >> 32; if (hi) return bfdev_clz(hi); - return bfdev_clz((uint32_t)value) + 32; + return bfdev_clz((bfdev_u32)value) + 32; } #else # define bfdev_clz64 bfdev_clz @@ -549,12 +549,12 @@ bfdev_clz64(uint64_t value) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffnsp64(uint64_t word, unsigned int *nr) +bfdev_ffnsp64(bfdev_u64 word, unsigned int *nr) { - uint32_t hi = word >> 32; + bfdev_u32 hi = word >> 32; unsigned int bit; - bit = bfdev_ffnsp((uint32_t)word, nr); + bit = bfdev_ffnsp((bfdev_u32)word, nr); if (bit < BFDEV_BITS_PER_LONG) return bit; @@ -566,16 +566,16 @@ bfdev_ffnsp64(uint64_t word, unsigned int *nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_flnsp64(uint64_t word, unsigned int *nr) +bfdev_flnsp64(bfdev_u64 word, unsigned int *nr) { - uint32_t hi = word >> 32; + bfdev_u32 hi = word >> 32; unsigned int bit; bit = bfdev_flnsp(hi, nr); if (bit < BFDEV_BITS_PER_LONG) return bit + 32; - return bfdev_flnsp((uint32_t)word, nr); + return bfdev_flnsp((bfdev_u32)word, nr); } #else # define bfdev_flnsp64 bfdev_flns @@ -583,12 +583,12 @@ bfdev_flnsp64(uint64_t word, unsigned int *nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffnzp64(uint64_t word, unsigned int *nr) +bfdev_ffnzp64(bfdev_u64 word, unsigned int *nr) { - uint32_t hi = word >> 32; + bfdev_u32 hi = word >> 32; unsigned int bit; - bit = bfdev_ffnzp((uint32_t)word, nr); + bit = bfdev_ffnzp((bfdev_u32)word, nr); if (bit < BFDEV_BITS_PER_LONG) return bit; @@ -600,16 +600,16 @@ bfdev_ffnzp64(uint64_t word, unsigned int *nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_flnzp64(uint64_t word, unsigned int *nr) +bfdev_flnzp64(bfdev_u64 word, unsigned int *nr) { - uint32_t hi = word >> 32; + bfdev_u32 hi = word >> 32; unsigned int bit; bit = bfdev_flnzp(hi, nr); if (bit < BFDEV_BITS_PER_LONG) return bit + 32; - return bfdev_flnzp((uint32_t)word, nr); + return bfdev_flnzp((bfdev_u32)word, nr); } #else # define bfdev_flnzp64 bfdev_flnzp @@ -617,7 +617,7 @@ bfdev_flnzp64(uint64_t word, unsigned int *nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffns64(uint64_t word, unsigned int nr) +bfdev_ffns64(bfdev_u64 word, unsigned int nr) { return bfdev_ffnsp64(word, &nr); } @@ -627,7 +627,7 @@ bfdev_ffns64(uint64_t word, unsigned int nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_flns64(uint64_t word, unsigned int nr) +bfdev_flns64(bfdev_u64 word, unsigned int nr) { return bfdev_flnsp64(word, &nr); } @@ -637,7 +637,7 @@ bfdev_flns64(uint64_t word, unsigned int nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_ffnz64(uint64_t word, unsigned int nr) +bfdev_ffnz64(bfdev_u64 word, unsigned int nr) { return bfdev_ffnzp64(word, &nr); } @@ -647,7 +647,7 @@ bfdev_ffnz64(uint64_t word, unsigned int nr) #if BFDEV_BITS_PER_LONG == 32 static __bfdev_always_inline unsigned int -bfdev_flnz64(uint64_t word, unsigned int nr) +bfdev_flnz64(bfdev_u64 word, unsigned int nr) { return bfdev_flnzp64(word, &nr); } diff --git a/include/bfdev/bitrev.h b/include/bfdev/bitrev.h index f278b727..bae87b37 100644 --- a/include/bfdev/bitrev.h +++ b/include/bfdev/bitrev.h @@ -15,191 +15,191 @@ BFDEV_BEGIN_DECLS * Interface for known constant arguments */ -#define bfdev_bitrev8_const(value) ( \ - (((uint8_t)(value) & (uint8_t)0x01UL) << 7) | \ - (((uint8_t)(value) & (uint8_t)0x02UL) << 5) | \ - (((uint8_t)(value) & (uint8_t)0x04UL) << 3) | \ - (((uint8_t)(value) & (uint8_t)0x08UL) << 1) | \ - (((uint8_t)(value) & (uint8_t)0x10UL) >> 1) | \ - (((uint8_t)(value) & (uint8_t)0x20UL) >> 3) | \ - (((uint8_t)(value) & (uint8_t)0x40UL) >> 5) | \ - (((uint8_t)(value) & (uint8_t)0x80UL) >> 7)) - -#define bfdev_bitrev16_const(value) ( \ - (((uint16_t)(value) & (uint16_t)0x0001UL) << 15) | \ - (((uint16_t)(value) & (uint16_t)0x0002UL) << 13) | \ - (((uint16_t)(value) & (uint16_t)0x0004UL) << 11) | \ - (((uint16_t)(value) & (uint16_t)0x0008UL) << 9) | \ - (((uint16_t)(value) & (uint16_t)0x0010UL) << 7) | \ - (((uint16_t)(value) & (uint16_t)0x0020UL) << 5) | \ - (((uint16_t)(value) & (uint16_t)0x0040UL) << 3) | \ - (((uint16_t)(value) & (uint16_t)0x0080UL) << 1) | \ - (((uint16_t)(value) & (uint16_t)0x0100UL) >> 1) | \ - (((uint16_t)(value) & (uint16_t)0x0200UL) >> 3) | \ - (((uint16_t)(value) & (uint16_t)0x0400UL) >> 5) | \ - (((uint16_t)(value) & (uint16_t)0x0800UL) >> 7) | \ - (((uint16_t)(value) & (uint16_t)0x1000UL) >> 9) | \ - (((uint16_t)(value) & (uint16_t)0x2000UL) >> 11) | \ - (((uint16_t)(value) & (uint16_t)0x4000UL) >> 13) | \ - (((uint16_t)(value) & (uint16_t)0x8000UL) >> 15)) - -#define bfdev_bitrev32_const(value) ( \ - (((uint32_t)(value) & (uint32_t)0x00000001UL) << 31) | \ - (((uint32_t)(value) & (uint32_t)0x00000002UL) << 29) | \ - (((uint32_t)(value) & (uint32_t)0x00000004UL) << 27) | \ - (((uint32_t)(value) & (uint32_t)0x00000008UL) << 25) | \ - (((uint32_t)(value) & (uint32_t)0x00000010UL) << 23) | \ - (((uint32_t)(value) & (uint32_t)0x00000020UL) << 21) | \ - (((uint32_t)(value) & (uint32_t)0x00000040UL) << 19) | \ - (((uint32_t)(value) & (uint32_t)0x00000080UL) << 17) | \ - (((uint32_t)(value) & (uint32_t)0x00000100UL) << 15) | \ - (((uint32_t)(value) & (uint32_t)0x00000200UL) << 13) | \ - (((uint32_t)(value) & (uint32_t)0x00000400UL) << 11) | \ - (((uint32_t)(value) & (uint32_t)0x00000800UL) << 9) | \ - (((uint32_t)(value) & (uint32_t)0x00001000UL) << 7) | \ - (((uint32_t)(value) & (uint32_t)0x00002000UL) << 5) | \ - (((uint32_t)(value) & (uint32_t)0x00004000UL) << 3) | \ - (((uint32_t)(value) & (uint32_t)0x00008000UL) << 1) | \ - (((uint32_t)(value) & (uint32_t)0x00010000UL) >> 1) | \ - (((uint32_t)(value) & (uint32_t)0x00020000UL) >> 3) | \ - (((uint32_t)(value) & (uint32_t)0x00040000UL) >> 5) | \ - (((uint32_t)(value) & (uint32_t)0x00080000UL) >> 7) | \ - (((uint32_t)(value) & (uint32_t)0x00100000UL) >> 9) | \ - (((uint32_t)(value) & (uint32_t)0x00200000UL) >> 11) | \ - (((uint32_t)(value) & (uint32_t)0x00400000UL) >> 13) | \ - (((uint32_t)(value) & (uint32_t)0x00800000UL) >> 15) | \ - (((uint32_t)(value) & (uint32_t)0x01000000UL) >> 17) | \ - (((uint32_t)(value) & (uint32_t)0x02000000UL) >> 19) | \ - (((uint32_t)(value) & (uint32_t)0x04000000UL) >> 21) | \ - (((uint32_t)(value) & (uint32_t)0x08000000UL) >> 25) | \ - (((uint32_t)(value) & (uint32_t)0x10000000UL) >> 23) | \ - (((uint32_t)(value) & (uint32_t)0x20000000UL) >> 27) | \ - (((uint32_t)(value) & (uint32_t)0x40000000UL) >> 29) | \ - (((uint32_t)(value) & (uint32_t)0x80000000UL) >> 31)) - -#define bfdev_bitrev64_const(value) ( \ - (((uint64_t)(value) & (uint64_t)0x0000000000000001ULL) << 63) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000002ULL) << 61) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000004ULL) << 59) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000008ULL) << 57) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000010ULL) << 55) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000020ULL) << 53) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000040ULL) << 51) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000080ULL) << 49) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000100ULL) << 47) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000200ULL) << 45) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000400ULL) << 43) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000000800ULL) << 41) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000001000ULL) << 39) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000002000ULL) << 37) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000004000ULL) << 35) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000008000ULL) << 33) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000010000ULL) << 31) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000020000ULL) << 29) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000040000ULL) << 27) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000080000ULL) << 25) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000100000ULL) << 23) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000200000ULL) << 21) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000400000ULL) << 19) | \ - (((uint64_t)(value) & (uint64_t)0x0000000000800000ULL) << 17) | \ - (((uint64_t)(value) & (uint64_t)0x0000000001000000ULL) << 15) | \ - (((uint64_t)(value) & (uint64_t)0x0000000002000000ULL) << 13) | \ - (((uint64_t)(value) & (uint64_t)0x0000000004000000ULL) << 11) | \ - (((uint64_t)(value) & (uint64_t)0x0000000008000000ULL) << 9) | \ - (((uint64_t)(value) & (uint64_t)0x0000000010000000ULL) << 7) | \ - (((uint64_t)(value) & (uint64_t)0x0000000020000000ULL) << 5) | \ - (((uint64_t)(value) & (uint64_t)0x0000000040000000ULL) << 3) | \ - (((uint64_t)(value) & (uint64_t)0x0000000080000000ULL) << 1) | \ - (((uint64_t)(value) & (uint64_t)0x0000000100000000ULL) >> 1) | \ - (((uint64_t)(value) & (uint64_t)0x0000000200000000ULL) >> 3) | \ - (((uint64_t)(value) & (uint64_t)0x0000000400000000ULL) >> 5) | \ - (((uint64_t)(value) & (uint64_t)0x0000000800000000ULL) >> 7) | \ - (((uint64_t)(value) & (uint64_t)0x0000001000000000ULL) >> 9) | \ - (((uint64_t)(value) & (uint64_t)0x0000002000000000ULL) >> 11) | \ - (((uint64_t)(value) & (uint64_t)0x0000004000000000ULL) >> 13) | \ - (((uint64_t)(value) & (uint64_t)0x0000008000000000ULL) >> 15) | \ - (((uint64_t)(value) & (uint64_t)0x0000010000000000ULL) >> 17) | \ - (((uint64_t)(value) & (uint64_t)0x0000020000000000ULL) >> 19) | \ - (((uint64_t)(value) & (uint64_t)0x0000040000000000ULL) >> 21) | \ - (((uint64_t)(value) & (uint64_t)0x0000080000000000ULL) >> 25) | \ - (((uint64_t)(value) & (uint64_t)0x0000100000000000ULL) >> 23) | \ - (((uint64_t)(value) & (uint64_t)0x0000200000000000ULL) >> 27) | \ - (((uint64_t)(value) & (uint64_t)0x0000400000000000ULL) >> 29) | \ - (((uint64_t)(value) & (uint64_t)0x0000800000000000ULL) >> 31) | \ - (((uint64_t)(value) & (uint64_t)0x0001000000000000ULL) >> 33) | \ - (((uint64_t)(value) & (uint64_t)0x0002000000000000ULL) >> 35) | \ - (((uint64_t)(value) & (uint64_t)0x0004000000000000ULL) >> 37) | \ - (((uint64_t)(value) & (uint64_t)0x0008000000000000ULL) >> 39) | \ - (((uint64_t)(value) & (uint64_t)0x0010000000000000ULL) >> 41) | \ - (((uint64_t)(value) & (uint64_t)0x0020000000000000ULL) >> 43) | \ - (((uint64_t)(value) & (uint64_t)0x0040000000000000ULL) >> 45) | \ - (((uint64_t)(value) & (uint64_t)0x0080000000000000ULL) >> 47) | \ - (((uint64_t)(value) & (uint64_t)0x0100000000000000ULL) >> 49) | \ - (((uint64_t)(value) & (uint64_t)0x0200000000000000ULL) >> 51) | \ - (((uint64_t)(value) & (uint64_t)0x0400000000000000ULL) >> 53) | \ - (((uint64_t)(value) & (uint64_t)0x0800000000000000ULL) >> 55) | \ - (((uint64_t)(value) & (uint64_t)0x1000000000000000ULL) >> 57) | \ - (((uint64_t)(value) & (uint64_t)0x2000000000000000ULL) >> 59) | \ - (((uint64_t)(value) & (uint64_t)0x4000000000000000ULL) >> 61) | \ - (((uint64_t)(value) & (uint64_t)0x8000000000000000ULL) >> 63)) +#define bfdev_bitrev8_const(value) ( \ + (((bfdev_u8)(value) & (bfdev_u8)0x01UL) << 7) | \ + (((bfdev_u8)(value) & (bfdev_u8)0x02UL) << 5) | \ + (((bfdev_u8)(value) & (bfdev_u8)0x04UL) << 3) | \ + (((bfdev_u8)(value) & (bfdev_u8)0x08UL) << 1) | \ + (((bfdev_u8)(value) & (bfdev_u8)0x10UL) >> 1) | \ + (((bfdev_u8)(value) & (bfdev_u8)0x20UL) >> 3) | \ + (((bfdev_u8)(value) & (bfdev_u8)0x40UL) >> 5) | \ + (((bfdev_u8)(value) & (bfdev_u8)0x80UL) >> 7)) + +#define bfdev_bitrev16_const(value) ( \ + (((bfdev_u16)(value) & (bfdev_u16)0x0001UL) << 15) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0002UL) << 13) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0004UL) << 11) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0008UL) << 9) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0010UL) << 7) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0020UL) << 5) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0040UL) << 3) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0080UL) << 1) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0100UL) >> 1) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0200UL) >> 3) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0400UL) >> 5) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x0800UL) >> 7) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x1000UL) >> 9) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x2000UL) >> 11) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x4000UL) >> 13) | \ + (((bfdev_u16)(value) & (bfdev_u16)0x8000UL) >> 15)) + +#define bfdev_bitrev32_const(value) ( \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000001UL) << 31) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000002UL) << 29) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000004UL) << 27) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000008UL) << 25) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000010UL) << 23) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000020UL) << 21) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000040UL) << 19) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000080UL) << 17) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000100UL) << 15) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000200UL) << 13) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000400UL) << 11) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00000800UL) << 9) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00001000UL) << 7) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00002000UL) << 5) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00004000UL) << 3) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00008000UL) << 1) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00010000UL) >> 1) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00020000UL) >> 3) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00040000UL) >> 5) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00080000UL) >> 7) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00100000UL) >> 9) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00200000UL) >> 11) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00400000UL) >> 13) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x00800000UL) >> 15) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x01000000UL) >> 17) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x02000000UL) >> 19) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x04000000UL) >> 21) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x08000000UL) >> 25) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x10000000UL) >> 23) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x20000000UL) >> 27) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x40000000UL) >> 29) | \ + (((bfdev_u32)(value) & (bfdev_u32)0x80000000UL) >> 31)) + +#define bfdev_bitrev64_const(value) ( \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000001ULL) << 63) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000002ULL) << 61) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000004ULL) << 59) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000008ULL) << 57) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000010ULL) << 55) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000020ULL) << 53) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000040ULL) << 51) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000080ULL) << 49) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000100ULL) << 47) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000200ULL) << 45) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000400ULL) << 43) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000000800ULL) << 41) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000001000ULL) << 39) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000002000ULL) << 37) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000004000ULL) << 35) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000008000ULL) << 33) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000010000ULL) << 31) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000020000ULL) << 29) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000040000ULL) << 27) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000080000ULL) << 25) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000100000ULL) << 23) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000200000ULL) << 21) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000400000ULL) << 19) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000000800000ULL) << 17) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000001000000ULL) << 15) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000002000000ULL) << 13) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000004000000ULL) << 11) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000008000000ULL) << 9) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000010000000ULL) << 7) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000020000000ULL) << 5) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000040000000ULL) << 3) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000080000000ULL) << 1) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000100000000ULL) >> 1) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000200000000ULL) >> 3) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000400000000ULL) >> 5) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000000800000000ULL) >> 7) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000001000000000ULL) >> 9) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000002000000000ULL) >> 11) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000004000000000ULL) >> 13) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000008000000000ULL) >> 15) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000010000000000ULL) >> 17) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000020000000000ULL) >> 19) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000040000000000ULL) >> 21) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000080000000000ULL) >> 25) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000100000000000ULL) >> 23) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000200000000000ULL) >> 27) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000400000000000ULL) >> 29) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0000800000000000ULL) >> 31) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0001000000000000ULL) >> 33) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0002000000000000ULL) >> 35) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0004000000000000ULL) >> 37) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0008000000000000ULL) >> 39) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0010000000000000ULL) >> 41) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0020000000000000ULL) >> 43) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0040000000000000ULL) >> 45) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0080000000000000ULL) >> 47) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0100000000000000ULL) >> 49) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0200000000000000ULL) >> 51) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0400000000000000ULL) >> 53) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x0800000000000000ULL) >> 55) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x1000000000000000ULL) >> 57) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x2000000000000000ULL) >> 59) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x4000000000000000ULL) >> 61) | \ + (((bfdev_u64)(value) & (bfdev_u64)0x8000000000000000ULL) >> 63)) /* * Interface for known dynamic arguments */ -extern const uint8_t +extern const bfdev_u8 bfdev_bitrev_byte_table[256]; -static inline uint8_t -bfdev_bitrev8_dynamic(uint8_t value) +static inline bfdev_u8 +bfdev_bitrev8_dynamic(bfdev_u8 value) { return bfdev_bitrev_byte_table[value]; } -static inline uint16_t -bfdev_bitrev16_dynamic(uint16_t value) +static inline bfdev_u16 +bfdev_bitrev16_dynamic(bfdev_u16 value) { - return ((uint16_t)bfdev_bitrev8_dynamic(value & 0xff) << 8) | - bfdev_bitrev8_dynamic(value >> 8); + return ((bfdev_u16)bfdev_bitrev8_dynamic(value & 0xff) << 8) | + bfdev_bitrev8_dynamic(value >> 8); } -static inline uint32_t -bfdev_bitrev32_dynamic(uint32_t value) +static inline bfdev_u32 +bfdev_bitrev32_dynamic(bfdev_u32 value) { - return ((uint32_t)bfdev_bitrev16_dynamic(value & 0xffff) << 16) | - bfdev_bitrev16_dynamic(value >> 16); + return ((bfdev_u32)bfdev_bitrev16_dynamic(value & 0xffff) << 16) | + bfdev_bitrev16_dynamic(value >> 16); } -static inline uint64_t -bfdev_bitrev64_dynamic(uint64_t value) +static inline bfdev_u64 +bfdev_bitrev64_dynamic(bfdev_u64 value) { - return ((uint64_t)bfdev_bitrev32_dynamic(value & 0xffffffff) << 32) | - bfdev_bitrev32_dynamic(value >> 32); + return ((bfdev_u64)bfdev_bitrev32_dynamic(value & 0xffffffff) << 32) | + bfdev_bitrev32_dynamic(value >> 32); } -#define bfdev_bitrev8(value) ({ \ - uint8_t __value = (uint8_t)(value); \ - __builtin_constant_p(__value) \ - ? bfdev_bitrev8_const(__value) \ - : bfdev_bitrev8_dynamic(__value); \ +#define bfdev_bitrev8(value) ({ \ + bfdev_u8 __value = (bfdev_u8)(value); \ + __builtin_constant_p(__value) \ + ? bfdev_bitrev8_const(__value) \ + : bfdev_bitrev8_dynamic(__value); \ }) #define bfdev_bitrev16(value) ({ \ - uint16_t __value = (uint16_t)(value); \ + bfdev_u16 __value = (bfdev_u16)(value); \ __builtin_constant_p(__value) \ ? bfdev_bitrev16_const(__value) \ : bfdev_bitrev16_dynamic(__value); \ }) #define bfdev_bitrev32(value) ({ \ - uint32_t __value = (uint32_t)(value); \ + bfdev_u32 __value = (bfdev_u32)(value); \ __builtin_constant_p(__value) \ ? bfdev_bitrev32_const(__value) \ : bfdev_bitrev32_dynamic(__value); \ }) #define bfdev_bitrev64(value) ({ \ - uint64_t __value = (uint64_t)(value); \ + bfdev_u64 __value = (bfdev_u64)(value); \ __builtin_constant_p(__value) \ ? bfdev_bitrev64_const(__value) \ : bfdev_bitrev64_dynamic(__value); \ diff --git a/include/bfdev/bits.h b/include/bfdev/bits.h index 0307cd96..d3f7fe18 100644 --- a/include/bfdev/bits.h +++ b/include/bfdev/bits.h @@ -17,10 +17,10 @@ BFDEV_BEGIN_DECLS #define BFDEV_BITS_PER_TYPE(type) (sizeof(type) * BFDEV_BITS_PER_BYTE) #define BFDEV_BITS_WORD(bit) ((bit) / BFDEV_BITS_PER_LONG) -#define BFDEV_BITS_PER_U8 BFDEV_BITS_PER_TYPE(uint8_t) -#define BFDEV_BITS_PER_U16 BFDEV_BITS_PER_TYPE(uint16_t) -#define BFDEV_BITS_PER_U32 BFDEV_BITS_PER_TYPE(uint32_t) -#define BFDEV_BITS_PER_U64 BFDEV_BITS_PER_TYPE(uint64_t) +#define BFDEV_BITS_PER_U8 BFDEV_BITS_PER_TYPE(bfdev_u8) +#define BFDEV_BITS_PER_U16 BFDEV_BITS_PER_TYPE(bfdev_u16) +#define BFDEV_BITS_PER_U32 BFDEV_BITS_PER_TYPE(bfdev_u32) +#define BFDEV_BITS_PER_U64 BFDEV_BITS_PER_TYPE(bfdev_u64) #define BFDEV_BITS_PER_CHAR BFDEV_BITS_PER_TYPE(char) #define BFDEV_BITS_PER_SHORT BFDEV_BITS_PER_TYPE(short) @@ -38,7 +38,7 @@ BFDEV_BEGIN_DECLS * BFDEV_BIT_LOW_MASK(8) gives us the vector 0x000000ff. */ #define BFDEV_BIT_LOW_MASK(nbits) ( \ - ULONG_MAX >> \ + BFDEV_ULONG_MAX >> \ (-(nbits) & (BFDEV_BITS_PER_LONG - 1)) \ ) @@ -50,7 +50,7 @@ BFDEV_BEGIN_DECLS * BFDEV_BIT_HIGH_MASK(8) gives us the vector 0xffffff00. */ #define BFDEV_BIT_HIGH_MASK(nbits) ( \ - ULONG_MAX << \ + BFDEV_ULONG_MAX << \ ((nbits) & (BFDEV_BITS_PER_LONG - 1)) \ ) diff --git a/include/bfdev/bitwalk-comp.h b/include/bfdev/bitwalk-comp.h index 3b867db0..12aa441d 100644 --- a/include/bfdev/bitwalk-comp.h +++ b/include/bfdev/bitwalk-comp.h @@ -14,21 +14,21 @@ BFDEV_BEGIN_DECLS extern unsigned int bfdev_comp_find_first_bit(const unsigned long *block, unsigned int bits, - unsigned long invert, bool swap); + unsigned long invert, bfdev_bool swap); extern unsigned int bfdev_comp_find_last_bit(const unsigned long *block, unsigned int bits, - unsigned long invert, bool swap); + unsigned long invert, bfdev_bool swap); extern unsigned int bfdev_comp_find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned int bits, unsigned int start, - unsigned long invert, bool swap); + unsigned long invert, bfdev_bool swap); extern unsigned int bfdev_comp_find_prev_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned int bits, unsigned int start, - unsigned long invert, bool swap); + unsigned long invert, bfdev_bool swap); BFDEV_END_DECLS diff --git a/include/bfdev/bitwalk.h b/include/bfdev/bitwalk.h index 496a2208..59a03d30 100644 --- a/include/bfdev/bitwalk.h +++ b/include/bfdev/bitwalk.h @@ -29,7 +29,7 @@ bfdev_find_first_bit(const unsigned long *addr, unsigned int bits) unsigned long value; if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_first_bit(addr, bits, 0UL, false); + return bfdev_comp_find_first_bit(addr, bits, 0UL, bfdev_false); value = *addr & BFDEV_BIT_LOW_MASK(bits); if (value == BFDEV_ULONG_MIN) @@ -46,7 +46,7 @@ bfdev_find_last_bit(const unsigned long *addr, unsigned int bits) unsigned long value; if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_last_bit(addr, bits, 0UL, false); + return bfdev_comp_find_last_bit(addr, bits, 0UL, bfdev_false); value = *addr & BFDEV_BIT_LOW_MASK(bits); if (value == BFDEV_ULONG_MIN) @@ -71,7 +71,7 @@ bfdev_find_first_zero(const unsigned long *addr, unsigned int bits) unsigned long value; if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_first_bit(addr, bits, ~0UL, false); + return bfdev_comp_find_first_bit(addr, bits, ~0UL, bfdev_false); value = *addr | BFDEV_BIT_HIGH_MASK(bits); if (value == BFDEV_ULONG_MAX) @@ -88,7 +88,7 @@ bfdev_find_last_zero(const unsigned long *addr, unsigned int bits) unsigned long value; if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_last_bit(addr, bits, ~0UL, false); + return bfdev_comp_find_last_bit(addr, bits, ~0UL, bfdev_false); value = *addr | BFDEV_BIT_HIGH_MASK(bits); if (value == BFDEV_ULONG_MAX) @@ -114,8 +114,10 @@ bfdev_find_next_bit(const unsigned long *addr, { unsigned long value; - if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_next_bit(addr, NULL, bits, offset, 0UL, false); + if (!bfdev_const_small_nbits(bits)) { + return bfdev_comp_find_next_bit(addr, BFDEV_NULL, + bits, offset, 0UL, bfdev_false); + } if (bfdev_unlikely(offset >= bits)) return bits; @@ -135,8 +137,10 @@ bfdev_find_prev_bit(const unsigned long *addr, { unsigned long value; - if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_prev_bit(addr, NULL, bits, offset, 0UL, false); + if (!bfdev_const_small_nbits(bits)) { + return bfdev_comp_find_prev_bit(addr, BFDEV_NULL, + bits, offset, 0UL, bfdev_false); + } if (bfdev_unlikely(offset >= bits)) return bits; @@ -165,8 +169,10 @@ bfdev_find_next_zero(const unsigned long *addr, { unsigned long value; - if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_next_bit(addr, NULL, bits, offset, ~0UL, false); + if (!bfdev_const_small_nbits(bits)) { + return bfdev_comp_find_next_bit(addr, BFDEV_NULL, + bits, offset, ~0UL, bfdev_false); + } if (bfdev_unlikely(offset >= bits)) return bits; @@ -186,8 +192,10 @@ bfdev_find_prev_zero(const unsigned long *addr, { unsigned long value; - if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_prev_bit(addr, NULL, bits, offset, ~0UL, false); + if (!bfdev_const_small_nbits(bits)) { + return bfdev_comp_find_prev_bit(addr, BFDEV_NULL, + bits, offset, ~0UL, bfdev_false); + } if (bfdev_unlikely(offset >= bits)) return bits; @@ -220,8 +228,10 @@ bfdev_find_next_and_bit(const unsigned long *addr1, const unsigned long *addr2, if (bfdev_unlikely(offset >= bits)) return bits; - if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_next_bit(addr1, addr2, bits, offset, 0UL, false); + if (!bfdev_const_small_nbits(bits)) { + return bfdev_comp_find_next_bit(addr1, addr2, + bits, offset, 0UL, bfdev_false); + } value = *addr1 & *addr2 & BFDEV_BIT_RANGE(bits - 1, offset); if (value == BFDEV_ULONG_MIN) @@ -238,8 +248,10 @@ bfdev_find_prev_and_bit(const unsigned long *addr1, const unsigned long *addr2, { unsigned long value; - if (!bfdev_const_small_nbits(bits)) - return bfdev_comp_find_prev_bit(addr1, addr2, bits, offset, 0UL, false); + if (!bfdev_const_small_nbits(bits)) { + return bfdev_comp_find_prev_bit(addr1, addr2, + bits, offset, 0UL, bfdev_false); + } if (bfdev_unlikely(offset >= bits)) return bits; diff --git a/include/bfdev/bloom.h b/include/bfdev/bloom.h index 0a12b150..21855702 100644 --- a/include/bfdev/bloom.h +++ b/include/bfdev/bloom.h @@ -36,7 +36,7 @@ struct bfdev_bloom { * * @return: object value. */ -extern bool +extern bfdev_bool bfdev_bloom_peek(bfdev_bloom_t *bloom, void *key); /** @@ -46,7 +46,7 @@ bfdev_bloom_peek(bfdev_bloom_t *bloom, void *key); * * @return: object value before push. */ -extern bool +extern bfdev_bool bfdev_bloom_push(bfdev_bloom_t *bloom, void *key); /** diff --git a/include/bfdev/bsearch.h b/include/bfdev/bsearch.h index 6b927455..04f4746d 100644 --- a/include/bfdev/bsearch.h +++ b/include/bfdev/bsearch.h @@ -13,7 +13,7 @@ BFDEV_BEGIN_DECLS static inline void * -bfdev_bsearch_inline(const void *base, size_t num, size_t esize, +bfdev_bsearch_inline(const void *base, bfdev_size_t num, bfdev_size_t esize, bfdev_find_t find, void *pdata) { const void *pivot; @@ -34,7 +34,7 @@ bfdev_bsearch_inline(const void *base, size_t num, size_t esize, num >>= 1; } - return NULL; + return BFDEV_NULL; } /** @@ -46,7 +46,7 @@ bfdev_bsearch_inline(const void *base, size_t num, size_t esize, * @pdata: pointer to item being searched for. */ extern void * -bfdev_bsearch(const void *base, size_t num, size_t esize, +bfdev_bsearch(const void *base, bfdev_size_t num, bfdev_size_t esize, bfdev_find_t find, void *pdata); BFDEV_END_DECLS diff --git a/include/bfdev/btree.h b/include/bfdev/btree.h index d71b1b17..b32988ea 100644 --- a/include/bfdev/btree.h +++ b/include/bfdev/btree.h @@ -23,11 +23,11 @@ struct bfdev_btree_layout { unsigned int keylen; unsigned int keynum; unsigned int ptrindex; - size_t nodesize; + bfdev_size_t nodesize; }; struct bfdev_btree_node { - uintptr_t block[0]; + bfdev_uintptr_t block[0]; }; struct bfdev_btree_root { @@ -43,7 +43,7 @@ struct bfdev_btree_root { struct bfdev_btree_ops { void *(*alloc)(bfdev_btree_root_t *root); void (*free)(bfdev_btree_root_t *root, void *block); - long (*find)(bfdev_btree_root_t *root, uintptr_t *node, uintptr_t *key); + long (*find)(bfdev_btree_root_t *root, bfdev_uintptr_t *node, bfdev_uintptr_t *key); int (*clash)(bfdev_btree_root_t *root, void *clash, void *value); void *(*remove)(bfdev_btree_root_t *root, void *value); }; @@ -75,10 +75,12 @@ bfdev_btree_init(bfdev_btree_root_t *root, bfdev_btree_layout_t *layout, } extern long -bfdev_btree_key_find(bfdev_btree_root_t *root, uintptr_t *node, uintptr_t *key); +bfdev_btree_key_find(bfdev_btree_root_t *root, bfdev_uintptr_t *node, + bfdev_uintptr_t *key); extern void -bfdev_btree_key_copy(bfdev_btree_root_t *root, uintptr_t *dest, uintptr_t *src); +bfdev_btree_key_copy(bfdev_btree_root_t *root, bfdev_uintptr_t *dest, + bfdev_uintptr_t *src); extern void * bfdev_btree_alloc(bfdev_btree_root_t *root); @@ -87,32 +89,32 @@ extern void bfdev_btree_free(bfdev_btree_root_t *root, void *node); extern void * -bfdev_btree_lookup(bfdev_btree_root_t *root, uintptr_t *key); +bfdev_btree_lookup(bfdev_btree_root_t *root, bfdev_uintptr_t *key); extern int -bfdev_btree_update(bfdev_btree_root_t *root, uintptr_t *key, void *value); +bfdev_btree_update(bfdev_btree_root_t *root, bfdev_uintptr_t *key, void *value); extern int -bfdev_btree_insert(bfdev_btree_root_t *root, uintptr_t *key, void *value); +bfdev_btree_insert(bfdev_btree_root_t *root, bfdev_uintptr_t *key, void *value); extern void * -bfdev_btree_remove(bfdev_btree_root_t *root, uintptr_t *key); +bfdev_btree_remove(bfdev_btree_root_t *root, bfdev_uintptr_t *key); extern void -bfdev_btree_release(bfdev_btree_root_t *root, bfdev_release_t release, - void *pdata); +bfdev_btree_release(bfdev_btree_root_t *root, + bfdev_release_t release, void *pdata); extern void * -bfdev_btree_first(bfdev_btree_root_t *root, uintptr_t *key); +bfdev_btree_first(bfdev_btree_root_t *root, bfdev_uintptr_t *key); extern void * -bfdev_btree_last(bfdev_btree_root_t *root, uintptr_t *key); +bfdev_btree_last(bfdev_btree_root_t *root, bfdev_uintptr_t *key); extern void * -bfdev_btree_next(bfdev_btree_root_t *root, uintptr_t *key); +bfdev_btree_next(bfdev_btree_root_t *root, bfdev_uintptr_t *key); extern void * -bfdev_btree_prev(bfdev_btree_root_t *root, uintptr_t *key); +bfdev_btree_prev(bfdev_btree_root_t *root, bfdev_uintptr_t *key); /** * bfdev_btree_for_each - iterate over a btree. diff --git a/include/bfdev/bug.h b/include/bfdev/bug.h index 4b5dc2d2..c532d09c 100644 --- a/include/bfdev/bug.h +++ b/include/bfdev/bug.h @@ -7,15 +7,15 @@ #define _BFDEV_BUG_H_ #include -#include #include +#include BFDEV_BEGIN_DECLS #ifndef BFDEV_BUG_MSG # define BFDEV_BUG_MSG(msg...) do { \ bfdev_log_alert(msg); \ - abort(); \ + bfdev_abort(); \ } while (0) #endif @@ -43,7 +43,7 @@ BFDEV_WARN_MSG( \ #ifndef BFDEV_BUG_ON # define BFDEV_BUG_ON(condition) ({ \ - bool __cond = !!(condition); \ + bfdev_bool __cond = !!(condition); \ if (bfdev_unlikely(__cond)) \ BFDEV_BUG(); \ bfdev_unlikely(__cond); \ @@ -52,7 +52,7 @@ BFDEV_WARN_MSG( \ #ifndef BFDEV_WARN_ON # define BFDEV_WARN_ON(condition) ({ \ - bool __cond = !!(condition); \ + bfdev_bool __cond = !!(condition); \ if (bfdev_unlikely(__cond)) \ BFDEV_WARN(); \ bfdev_unlikely(__cond); \ diff --git a/include/bfdev/byteorder/big-endian.h b/include/bfdev/byteorder/big-endian.h index ccda12e7..572a6c5b 100644 --- a/include/bfdev/byteorder/big-endian.h +++ b/include/bfdev/byteorder/big-endian.h @@ -16,38 +16,38 @@ BFDEV_BEGIN_DECLS # define __BFDEV_BIG_ENDIAN__ #endif -#define bfdev_htons_const(x) ((__bfdev_force bfdev_be16)(uint16_t)(x)) -#define bfdev_htonl_const(x) ((__bfdev_force bfdev_be32)(uint32_t)(x)) -#define bfdev_ntohl_const(x) ((__bfdev_force uint32_t)(bfdev_be32)(x)) -#define bfdev_ntohs_const(x) ((__bfdev_force uint16_t)(bfdev_be16)(x)) +#define bfdev_htons_const(x) ((__bfdev_force bfdev_be16)(bfdev_u16)(x)) +#define bfdev_htonl_const(x) ((__bfdev_force bfdev_be32)(bfdev_u32)(x)) +#define bfdev_ntohl_const(x) ((__bfdev_force bfdev_u32)(bfdev_be32)(x)) +#define bfdev_ntohs_const(x) ((__bfdev_force bfdev_u16)(bfdev_be16)(x)) #define bfdev_cpu_to_le16_const(x) ((__bfdev_force bfdev_le16)bfdev_swab16_const((x))) #define bfdev_cpu_to_le32_const(x) ((__bfdev_force bfdev_le32)bfdev_swab32_const((x))) #define bfdev_cpu_to_le64_const(x) ((__bfdev_force bfdev_le64)bfdev_swab64_const((x))) -#define bfdev_le16_to_cpu_const(x) bfdev_swab16_const((__bfdev_force uint16_t)(bfdev_le16)(x)) -#define bfdev_le32_to_cpu_const(x) bfdev_swab32_const((__bfdev_force uint32_t)(bfdev_le32)(x)) -#define bfdev_le64_to_cpu_const(x) bfdev_swab64_const((__bfdev_force uint64_t)(bfdev_le64)(x)) +#define bfdev_le16_to_cpu_const(x) bfdev_swab16_const((__bfdev_force bfdev_u16)(bfdev_le16)(x)) +#define bfdev_le32_to_cpu_const(x) bfdev_swab32_const((__bfdev_force bfdev_u32)(bfdev_le32)(x)) +#define bfdev_le64_to_cpu_const(x) bfdev_swab64_const((__bfdev_force bfdev_u64)(bfdev_le64)(x)) -#define bfdev_cpu_to_be16_const(x) ((__bfdev_force bfdev_be16)(uint16_t)(x)) -#define bfdev_cpu_to_be32_const(x) ((__bfdev_force bfdev_be32)(uint32_t)(x)) -#define bfdev_cpu_to_be64_const(x) ((__bfdev_force bfdev_be64)(uint64_t)(x)) -#define bfdev_be16_to_cpu_const(x) ((__bfdev_force uint16_t)(bfdev_be16)(x)) -#define bfdev_be32_to_cpu_const(x) ((__bfdev_force uint32_t)(bfdev_be32)(x)) -#define bfdev_be64_to_cpu_const(x) ((__bfdev_force uint64_t)(bfdev_be64)(x)) +#define bfdev_cpu_to_be16_const(x) ((__bfdev_force bfdev_be16)(bfdev_u16)(x)) +#define bfdev_cpu_to_be32_const(x) ((__bfdev_force bfdev_be32)(bfdev_u32)(x)) +#define bfdev_cpu_to_be64_const(x) ((__bfdev_force bfdev_be64)(bfdev_u64)(x)) +#define bfdev_be16_to_cpu_const(x) ((__bfdev_force bfdev_u16)(bfdev_be16)(x)) +#define bfdev_be32_to_cpu_const(x) ((__bfdev_force bfdev_u32)(bfdev_be32)(x)) +#define bfdev_be64_to_cpu_const(x) ((__bfdev_force bfdev_u64)(bfdev_be64)(x)) #define bfdev_cpu_to_le16(x) ((__bfdev_force bfdev_le16)bfdev_swab16((x))) #define bfdev_cpu_to_le32(x) ((__bfdev_force bfdev_le32)bfdev_swab32((x))) #define bfdev_cpu_to_le64(x) ((__bfdev_force bfdev_le64)bfdev_swab64((x))) -#define bfdev_le16_to_cpu(x) bfdev_swab16((__bfdev_force uint16_t)(bfdev_le16)(x)) -#define bfdev_le32_to_cpu(x) bfdev_swab32((__bfdev_force uint32_t)(bfdev_le32)(x)) -#define bfdev_le64_to_cpu(x) bfdev_swab64((__bfdev_force uint64_t)(bfdev_le64)(x)) +#define bfdev_le16_to_cpu(x) bfdev_swab16((__bfdev_force bfdev_u16)(bfdev_le16)(x)) +#define bfdev_le32_to_cpu(x) bfdev_swab32((__bfdev_force bfdev_u32)(bfdev_le32)(x)) +#define bfdev_le64_to_cpu(x) bfdev_swab64((__bfdev_force bfdev_u64)(bfdev_le64)(x)) -#define bfdev_be16_to_cpu(x) ((__bfdev_force uint16_t)(bfdev_be16)(x)) -#define bfdev_be32_to_cpu(x) ((__bfdev_force uint32_t)(bfdev_be32)(x)) -#define bfdev_be64_to_cpu(x) ((__bfdev_force uint64_t)(bfdev_be64)(x)) -#define bfdev_cpu_to_be16(x) ((__bfdev_force bfdev_be16)(uint16_t)(x)) -#define bfdev_cpu_to_be32(x) ((__bfdev_force bfdev_be32)(uint32_t)(x)) -#define bfdev_cpu_to_be64(x) ((__bfdev_force bfdev_be64)(uint64_t)(x)) +#define bfdev_be16_to_cpu(x) ((__bfdev_force bfdev_u16)(bfdev_be16)(x)) +#define bfdev_be32_to_cpu(x) ((__bfdev_force bfdev_u32)(bfdev_be32)(x)) +#define bfdev_be64_to_cpu(x) ((__bfdev_force bfdev_u64)(bfdev_be64)(x)) +#define bfdev_cpu_to_be16(x) ((__bfdev_force bfdev_be16)(bfdev_u16)(x)) +#define bfdev_cpu_to_be32(x) ((__bfdev_force bfdev_be32)(bfdev_u32)(x)) +#define bfdev_cpu_to_be64(x) ((__bfdev_force bfdev_be64)(bfdev_u64)(x)) #define bfdev_cpu_to_le16s(x) bfdev_swab16s((x)) #define bfdev_cpu_to_le32s(x) bfdev_swab32s((x)) @@ -64,75 +64,75 @@ BFDEV_BEGIN_DECLS #define bfdev_be64_to_cpus(x) do { (void)(x); } while (0) static __bfdev_always_inline bfdev_le16 -bfdev_cpu_to_le16p(const uint16_t *p) +bfdev_cpu_to_le16p(const bfdev_u16 *p) { return (__bfdev_force bfdev_le16)bfdev_swab16p(p); } static __bfdev_always_inline bfdev_le32 -bfdev_cpu_to_le32p(const uint32_t *p) +bfdev_cpu_to_le32p(const bfdev_u32 *p) { return (__bfdev_force bfdev_le32)bfdev_swab32p(p); } static __bfdev_always_inline bfdev_le64 -bfdev_cpu_to_le64p(const uint64_t *p) +bfdev_cpu_to_le64p(const bfdev_u64 *p) { return (__bfdev_force bfdev_le64)bfdev_swab64p(p); } -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_le16_to_cpup(const bfdev_le16 *p) { - return bfdev_swab16p((__bfdev_force uint16_t *)p); + return bfdev_swab16p((__bfdev_force bfdev_u16 *)p); } -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_le32_to_cpup(const bfdev_le32 *p) { - return bfdev_swab32p((__bfdev_force uint32_t *)p); + return bfdev_swab32p((__bfdev_force bfdev_u32 *)p); } -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_le64_to_cpup(const bfdev_le64 *p) { - return bfdev_swab64p((__bfdev_force uint64_t *)p); + return bfdev_swab64p((__bfdev_force bfdev_u64 *)p); } static __bfdev_always_inline bfdev_be16 -bfdev_cpu_to_be16p(const uint16_t *p) +bfdev_cpu_to_be16p(const bfdev_u16 *p) { return (__bfdev_force bfdev_be16)*p; } static __bfdev_always_inline bfdev_be32 -bfdev_cpu_to_be32p(const uint32_t *p) +bfdev_cpu_to_be32p(const bfdev_u32 *p) { return (__bfdev_force bfdev_be32)*p; } static __bfdev_always_inline bfdev_be64 -bfdev_cpu_to_be64p(const uint64_t *p) +bfdev_cpu_to_be64p(const bfdev_u64 *p) { return (__bfdev_force bfdev_be64)*p; } -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_be16_to_cpup(const bfdev_be16 *p) { - return (__bfdev_force uint16_t)*p; + return (__bfdev_force bfdev_u16)*p; } -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_be32_to_cpup(const bfdev_be32 *p) { - return (__bfdev_force uint32_t)*p; + return (__bfdev_force bfdev_u32)*p; } -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_be64_to_cpup(const bfdev_be64 *p) { - return (__bfdev_force uint64_t)*p; + return (__bfdev_force bfdev_u64)*p; } BFDEV_END_DECLS diff --git a/include/bfdev/byteorder/little-endian.h b/include/bfdev/byteorder/little-endian.h index a7504ab0..9b0dfd4c 100644 --- a/include/bfdev/byteorder/little-endian.h +++ b/include/bfdev/byteorder/little-endian.h @@ -21,33 +21,33 @@ BFDEV_BEGIN_DECLS #define bfdev_ntohl_const(x) bfdev_swab32_const((__bfdev_force bfdev_be32)(x)) #define bfdev_ntohs_const(x) bfdev_swab16_const((__bfdev_force bfdev_be16)(x)) -#define bfdev_cpu_to_le16_const(x) ((__bfdev_force bfdev_le16)(uint16_t)(x)) -#define bfdev_cpu_to_le32_const(x) ((__bfdev_force bfdev_le32)(uint32_t)(x)) -#define bfdev_cpu_to_le64_const(x) ((__bfdev_force bfdev_le64)(uint64_t)(x)) -#define bfdev_le16_to_cpu_const(x) ((__bfdev_force uint16_t)(bfdev_le16)(x)) -#define bfdev_le32_to_cpu_const(x) ((__bfdev_force uint32_t)(bfdev_le32)(x)) -#define bfdev_le64_to_cpu_const(x) ((__bfdev_force uint64_t)(bfdev_le64)(x)) +#define bfdev_cpu_to_le16_const(x) ((__bfdev_force bfdev_le16)(bfdev_u16)(x)) +#define bfdev_cpu_to_le32_const(x) ((__bfdev_force bfdev_le32)(bfdev_u32)(x)) +#define bfdev_cpu_to_le64_const(x) ((__bfdev_force bfdev_le64)(bfdev_u64)(x)) +#define bfdev_le16_to_cpu_const(x) ((__bfdev_force bfdev_u16)(bfdev_le16)(x)) +#define bfdev_le32_to_cpu_const(x) ((__bfdev_force bfdev_u32)(bfdev_le32)(x)) +#define bfdev_le64_to_cpu_const(x) ((__bfdev_force bfdev_u64)(bfdev_le64)(x)) #define bfdev_cpu_to_be16_const(x) ((__bfdev_force bfdev_be16)bfdev_swab16_const((x))) #define bfdev_cpu_to_be32_const(x) ((__bfdev_force bfdev_be32)bfdev_swab32_const((x))) #define bfdev_cpu_to_be64_const(x) ((__bfdev_force bfdev_be64)bfdev_swab64_const((x))) -#define bfdev_be16_to_cpu_const(x) bfdev_swab16_const((__bfdev_force uint16_t)(bfdev_be16)(x)) -#define bfdev_be32_to_cpu_const(x) bfdev_swab32_const((__bfdev_force uint32_t)(bfdev_be32)(x)) -#define bfdev_be64_to_cpu_const(x) bfdev_swab64_const((__bfdev_force uint64_t)(bfdev_be64)(x)) +#define bfdev_be16_to_cpu_const(x) bfdev_swab16_const((__bfdev_force bfdev_u16)(bfdev_be16)(x)) +#define bfdev_be32_to_cpu_const(x) bfdev_swab32_const((__bfdev_force bfdev_u32)(bfdev_be32)(x)) +#define bfdev_be64_to_cpu_const(x) bfdev_swab64_const((__bfdev_force bfdev_u64)(bfdev_be64)(x)) -#define bfdev_cpu_to_le16(x) ((__bfdev_force bfdev_le16)(uint16_t)(x)) -#define bfdev_cpu_to_le32(x) ((__bfdev_force bfdev_le32)(uint32_t)(x)) -#define bfdev_cpu_to_le64(x) ((__bfdev_force bfdev_le64)(uint64_t)(x)) -#define bfdev_le16_to_cpu(x) ((__bfdev_force uint16_t)(bfdev_le16)(x)) -#define bfdev_le32_to_cpu(x) ((__bfdev_force uint32_t)(bfdev_le32)(x)) -#define bfdev_le64_to_cpu(x) ((__bfdev_force uint64_t)(bfdev_le64)(x)) +#define bfdev_cpu_to_le16(x) ((__bfdev_force bfdev_le16)(bfdev_u16)(x)) +#define bfdev_cpu_to_le32(x) ((__bfdev_force bfdev_le32)(bfdev_u32)(x)) +#define bfdev_cpu_to_le64(x) ((__bfdev_force bfdev_le64)(bfdev_u64)(x)) +#define bfdev_le16_to_cpu(x) ((__bfdev_force bfdev_u16)(bfdev_le16)(x)) +#define bfdev_le32_to_cpu(x) ((__bfdev_force bfdev_u32)(bfdev_le32)(x)) +#define bfdev_le64_to_cpu(x) ((__bfdev_force bfdev_u64)(bfdev_le64)(x)) #define bfdev_cpu_to_be16(x) ((__bfdev_force bfdev_be16)bfdev_swab16((x))) #define bfdev_cpu_to_be32(x) ((__bfdev_force bfdev_be32)bfdev_swab32((x))) #define bfdev_cpu_to_be64(x) ((__bfdev_force bfdev_be64)bfdev_swab64((x))) -#define bfdev_be16_to_cpu(x) bfdev_swab16((__bfdev_force uint16_t)(bfdev_be16)(x)) -#define bfdev_be32_to_cpu(x) bfdev_swab32((__bfdev_force uint32_t)(bfdev_be32)(x)) -#define bfdev_be64_to_cpu(x) bfdev_swab64((__bfdev_force uint64_t)(bfdev_be64)(x)) +#define bfdev_be16_to_cpu(x) bfdev_swab16((__bfdev_force bfdev_u16)(bfdev_be16)(x)) +#define bfdev_be32_to_cpu(x) bfdev_swab32((__bfdev_force bfdev_u32)(bfdev_be32)(x)) +#define bfdev_be64_to_cpu(x) bfdev_swab64((__bfdev_force bfdev_u64)(bfdev_be64)(x)) #define bfdev_cpu_to_le16s(x) do { (void)(x); } while (0) #define bfdev_cpu_to_le32s(x) do { (void)(x); } while (0) @@ -64,75 +64,75 @@ BFDEV_BEGIN_DECLS #define bfdev_be64_to_cpus(x) bfdev_swab64s((x)) static __bfdev_always_inline bfdev_le16 -bfdev_cpu_to_le16p(const uint16_t *p) +bfdev_cpu_to_le16p(const bfdev_u16 *p) { return (__bfdev_force bfdev_le16)*p; } static __bfdev_always_inline bfdev_le32 -bfdev_cpu_to_le32p(const uint32_t *p) +bfdev_cpu_to_le32p(const bfdev_u32 *p) { return (__bfdev_force bfdev_le32)*p; } static __bfdev_always_inline bfdev_le64 -bfdev_cpu_to_le64p(const uint64_t *p) +bfdev_cpu_to_le64p(const bfdev_u64 *p) { return (__bfdev_force bfdev_le64)*p; } -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_le16_to_cpup(const bfdev_le16 *p) { - return (__bfdev_force uint16_t)*p; + return (__bfdev_force bfdev_u16)*p; } -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_le32_to_cpup(const bfdev_le32 *p) { - return (__bfdev_force uint32_t)*p; + return (__bfdev_force bfdev_u32)*p; } -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_le64_to_cpup(const bfdev_le64 *p) { - return (__bfdev_force uint64_t)*p; + return (__bfdev_force bfdev_u64)*p; } static __bfdev_always_inline bfdev_be16 -bfdev_cpu_to_be16p(const uint16_t *p) +bfdev_cpu_to_be16p(const bfdev_u16 *p) { return (__bfdev_force bfdev_be16)bfdev_swab16p(p); } static __bfdev_always_inline bfdev_be32 -bfdev_cpu_to_be32p(const uint32_t *p) +bfdev_cpu_to_be32p(const bfdev_u32 *p) { return (__bfdev_force bfdev_be32)bfdev_swab32p(p); } static __bfdev_always_inline bfdev_be64 -bfdev_cpu_to_be64p(const uint64_t *p) +bfdev_cpu_to_be64p(const bfdev_u64 *p) { return (__bfdev_force bfdev_be64)bfdev_swab64p(p); } -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_be16_to_cpup(const bfdev_be16 *p) { - return bfdev_swab16p((__bfdev_force uint16_t *)p); + return bfdev_swab16p((__bfdev_force bfdev_u16 *)p); } -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_be32_to_cpup(const bfdev_be32 *p) { - return bfdev_swab32p((__bfdev_force uint32_t *)p); + return bfdev_swab32p((__bfdev_force bfdev_u32 *)p); } -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_be64_to_cpup(const bfdev_be64 *p) { - return bfdev_swab64p((__bfdev_force uint64_t *)p); + return bfdev_swab64p((__bfdev_force bfdev_u64 *)p); } BFDEV_END_DECLS diff --git a/include/bfdev/cache.h b/include/bfdev/cache.h index 02bb4e65..7680a917 100644 --- a/include/bfdev/cache.h +++ b/include/bfdev/cache.h @@ -92,7 +92,7 @@ struct bfdev_cache_algo { bfdev_list_head_t list; const char *name; - bool (*starving)(bfdev_cache_head_t *head); + bfdev_bool (*starving)(bfdev_cache_head_t *head); bfdev_cache_node_t *(*obtain)(bfdev_cache_head_t *head); void (*get)(bfdev_cache_head_t *head, bfdev_cache_node_t *node); void (*put)(bfdev_cache_head_t *head, bfdev_cache_node_t *node); diff --git a/include/bfdev/cmpxchg.h b/include/bfdev/cmpxchg.h index fe2fe193..759d04d2 100644 --- a/include/bfdev/cmpxchg.h +++ b/include/bfdev/cmpxchg.h @@ -28,7 +28,7 @@ bfdev_cmpxchg(bfdev_atomic_t *atomic, bfdev_atomic_t old, bfdev_atomic_t value) #endif #ifndef bfdev_try_cmpxchg -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool bfdev_try_cmpxchg(bfdev_atomic_t *atomic, bfdev_atomic_t *old, bfdev_atomic_t value) { return bfdev_arch_try_cmpxchg(atomic, old, value); diff --git a/include/bfdev/container.h b/include/bfdev/container.h index 39453b25..866d816c 100644 --- a/include/bfdev/container.h +++ b/include/bfdev/container.h @@ -19,24 +19,24 @@ BFDEV_BEGIN_DECLS */ /* Any const qualifier of @ptr is lost. */ -#define bfdev_container_of(ptr, type, member) ({ \ - const typeof(((type *)0)->member) *__mptr = (ptr); \ - (type *)((char *)__mptr - offsetof(type, member)); \ +#define bfdev_container_of(ptr, type, member) ({ \ + const typeof(((type *)0)->member) *__mptr = (ptr); \ + (type *)((char *)__mptr - bfdev_offsetof(type, member)); \ }) -/* If ptr is NULL, ptr is returned unchanged. */ -#define bfdev_container_of_safe(ptr, type, member) ({ \ - typeof(ptr) __ptr = (ptr); \ - __ptr ? bfdev_container_of(__ptr, type, member) : NULL; \ +/* If ptr is BFDEV_NULL, ptr is returned unchanged. */ +#define bfdev_container_of_safe(ptr, type, member) ({ \ + typeof(ptr) __ptr = (ptr); \ + __ptr ? bfdev_container_of(__ptr, type, member) : BFDEV_NULL; \ }) /* Preserve the const-ness of the pointer. */ -#define bfdev_container_of_const(ptr, type, member) \ -_Generic(ptr, \ - const typeof(*(ptr)) *: \ - ((const type *)bfdev_container_of(ptr, type, member)), \ - default: \ - ((type *)bfdev_container_of(ptr, type, member)) \ +#define bfdev_container_of_const(ptr, type, member) \ +_Generic(ptr, \ + const typeof(*(ptr)) *: \ + ((const type *)bfdev_container_of(ptr, type, member)), \ + default: \ + ((type *)bfdev_container_of(ptr, type, member)) \ ) BFDEV_END_DECLS diff --git a/include/bfdev/crc.h b/include/bfdev/crc.h index 5976a5e4..34373a75 100644 --- a/include/bfdev/crc.h +++ b/include/bfdev/crc.h @@ -11,35 +11,35 @@ BFDEV_BEGIN_DECLS -extern uint8_t -bfdev_crc4(const void *data, size_t bits, uint8_t crc); +extern bfdev_u8 +bfdev_crc4(const void *data, bfdev_size_t bits, bfdev_u8 crc); -extern uint8_t -bfdev_crc7(const void *data, size_t len, uint8_t crc); +extern bfdev_u8 +bfdev_crc7(const void *data, bfdev_size_t len, bfdev_u8 crc); -extern uint8_t -bfdev_crc8(const void *data, size_t len, uint8_t crc); +extern bfdev_u8 +bfdev_crc8(const void *data, bfdev_size_t len, bfdev_u8 crc); -extern uint16_t -bfdev_crc16(const void *data, size_t len, uint16_t crc); +extern bfdev_u16 +bfdev_crc16(const void *data, bfdev_size_t len, bfdev_u16 crc); -extern uint32_t -bfdev_crc32(const void *data, size_t len, uint32_t crc); +extern bfdev_u32 +bfdev_crc32(const void *data, bfdev_size_t len, bfdev_u32 crc); -extern uint64_t -bfdev_crc64(const void *data, size_t len, uint64_t crc); +extern bfdev_u64 +bfdev_crc64(const void *data, bfdev_size_t len, bfdev_u64 crc); -extern uint16_t -bfdev_crc_ccitt(const void *data, size_t len, uint16_t crc); +extern bfdev_u16 +bfdev_crc_ccitt(const void *data, bfdev_size_t len, bfdev_u16 crc); -extern uint16_t -bfdev_crc_itut(const void *data, size_t len, uint16_t crc); +extern bfdev_u16 +bfdev_crc_itut(const void *data, bfdev_size_t len, bfdev_u16 crc); -extern uint16_t -bfdev_crc_t10dif(const void *data, size_t len, uint16_t crc); +extern bfdev_u16 +bfdev_crc_t10dif(const void *data, bfdev_size_t len, bfdev_u16 crc); -extern uint64_t -bfdev_crc_rocksoft(const void *data, size_t len, uint64_t crc); +extern bfdev_u64 +bfdev_crc_rocksoft(const void *data, bfdev_size_t len, bfdev_u64 crc); BFDEV_END_DECLS diff --git a/include/bfdev/crypto/crc-ccitt-inline.h b/include/bfdev/crypto/crc-ccitt-inline.h index f432a575..044c4f24 100644 --- a/include/bfdev/crypto/crc-ccitt-inline.h +++ b/include/bfdev/crypto/crc-ccitt-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc_ccitt, uint16_t, + bfdev_crc_ccitt, bfdev_u16, bfdev_crc_ccitt_table, bfdev_cpu_to_le16 ) diff --git a/include/bfdev/crypto/crc-inline.h b/include/bfdev/crypto/crc-inline.h index 1e670e2a..c9b30486 100644 --- a/include/bfdev/crypto/crc-inline.h +++ b/include/bfdev/crypto/crc-inline.h @@ -16,32 +16,32 @@ BFDEV_BEGIN_DECLS #define BFDEV_CRC_BYTE(name, type, table) \ static inline type \ -name##_byte(type crc, const uint8_t data) \ +name##_byte(type crc, const bfdev_u8 data) \ { \ unsigned int index = (crc ^ data) & 0xff; \ return table[0][index] ^ (crc >> 8); \ } #ifndef BFDEV_CRC_EXTEND -# define BFDEV_CRC_INLINE(name, type, table, bswap) \ -BFDEV_CRC_BYTE(name, type, table) \ -static inline type \ -name##_inline(const uint8_t *src, size_t len, type crc) \ -{ \ - crc = bswap(crc); \ - while (len--) \ - crc = name##_byte(crc, *src++); \ - \ - return bswap(crc); \ +# define BFDEV_CRC_INLINE(name, type, table, bswap) \ +BFDEV_CRC_BYTE(name, type, table) \ +static inline type \ +name##_inline(const bfdev_u8 *src, bfdev_size_t len, type crc) \ +{ \ + crc = bswap(crc); \ + while (len--) \ + crc = name##_byte(crc, *src++); \ + \ + return bswap(crc); \ } #else # define BFDEV_CRC_INLINE(name, type, table, bswap) \ BFDEV_CRC_BYTE(name, type, table) \ static inline type \ -name##_inline(const uint8_t *src, size_t len, type crc) \ +name##_inline(const bfdev_u8 *src, bfdev_size_t len, type crc) \ { \ - const uint32_t *combine; \ - uint32_t value[2]; \ + const bfdev_u32 *combine; \ + bfdev_u32 value[2]; \ \ crc = (__bfdev_force type)bswap(crc); \ while (len && !bfdev_align_ptr_check(src, sizeof(*value))) { \ @@ -50,9 +50,9 @@ name##_inline(const uint8_t *src, size_t len, type crc) \ } \ \ for (combine = (const void *)src; len >= 8; len -= 8) { \ - value[0] = (__bfdev_force uint32_t) \ + value[0] = (__bfdev_force bfdev_u32) \ bfdev_cpu_to_le32p(combine++) ^ crc; \ - value[1] = (__bfdev_force uint32_t) \ + value[1] = (__bfdev_force bfdev_u32) \ bfdev_cpu_to_le32p(combine++); \ \ crc = ( \ diff --git a/include/bfdev/crypto/crc-itut-inline.h b/include/bfdev/crypto/crc-itut-inline.h index 610cfb2d..610d0df9 100644 --- a/include/bfdev/crypto/crc-itut-inline.h +++ b/include/bfdev/crypto/crc-itut-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc_itut, uint16_t, + bfdev_crc_itut, bfdev_u16, bfdev_crc_itut_table, bfdev_cpu_to_be16 ) diff --git a/include/bfdev/crypto/crc-rocksoft-inline.h b/include/bfdev/crypto/crc-rocksoft-inline.h index ab916327..72fb7f47 100644 --- a/include/bfdev/crypto/crc-rocksoft-inline.h +++ b/include/bfdev/crypto/crc-rocksoft-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc_rocksoft, uint64_t, + bfdev_crc_rocksoft, bfdev_u64, bfdev_crc_rocksoft_table, bfdev_cpu_to_le64 ) diff --git a/include/bfdev/crypto/crc-t10dif-inline.h b/include/bfdev/crypto/crc-t10dif-inline.h index fb10eb95..4d8fa622 100644 --- a/include/bfdev/crypto/crc-t10dif-inline.h +++ b/include/bfdev/crypto/crc-t10dif-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc_t10dif, uint16_t, + bfdev_crc_t10dif, bfdev_u16, bfdev_crc_t10dif_table, bfdev_cpu_to_be16 ) diff --git a/include/bfdev/crypto/crc16-inline.h b/include/bfdev/crypto/crc16-inline.h index 9775e9d4..765c39e2 100644 --- a/include/bfdev/crypto/crc16-inline.h +++ b/include/bfdev/crypto/crc16-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc16, uint16_t, + bfdev_crc16, bfdev_u16, bfdev_crc16_table, bfdev_cpu_to_le16 ) diff --git a/include/bfdev/crypto/crc32-inline.h b/include/bfdev/crypto/crc32-inline.h index 2b957a90..994ecf26 100644 --- a/include/bfdev/crypto/crc32-inline.h +++ b/include/bfdev/crypto/crc32-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc32, uint32_t, + bfdev_crc32, bfdev_u32, bfdev_crc32_table, bfdev_cpu_to_le32 ) diff --git a/include/bfdev/crypto/crc4-inline.h b/include/bfdev/crypto/crc4-inline.h index eee84135..41998252 100644 --- a/include/bfdev/crypto/crc4-inline.h +++ b/include/bfdev/crypto/crc4-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS -static const uint8_t +static const bfdev_u8 bfdev_crc4_table[16] = { 0x00, 0x07, 0x0e, 0x09, 0x0b, 0x0c, 0x05, 0x02, @@ -22,8 +22,8 @@ bfdev_crc4_table[16] = { 0x0a, 0x0d, 0x04, 0x03, }; -static inline uint8_t -bfdev_crc4_byte(uint8_t crc, const uint8_t data) +static inline bfdev_u8 +bfdev_crc4_byte(bfdev_u8 crc, const bfdev_u8 data) { unsigned int index; @@ -36,11 +36,11 @@ bfdev_crc4_byte(uint8_t crc, const uint8_t data) return crc; } -static inline uint8_t -bfdev_crc4_inline(const uint8_t *src, size_t bits, uint8_t crc) +static inline bfdev_u8 +bfdev_crc4_inline(const bfdev_u8 *src, bfdev_size_t bits, bfdev_u8 crc) { unsigned int count; - uint8_t value; + bfdev_u8 value; for (; bits >= 32; bits -= 32) { crc = bfdev_crc4_byte(crc, *src++); diff --git a/include/bfdev/crypto/crc64-inline.h b/include/bfdev/crypto/crc64-inline.h index 437cffea..bfd27f47 100644 --- a/include/bfdev/crypto/crc64-inline.h +++ b/include/bfdev/crypto/crc64-inline.h @@ -14,7 +14,7 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc64, uint64_t, + bfdev_crc64, bfdev_u64, bfdev_crc64_table, bfdev_cpu_to_be64 ) diff --git a/include/bfdev/crypto/crc7-inline.h b/include/bfdev/crypto/crc7-inline.h index 58b1eb78..f24eb91f 100644 --- a/include/bfdev/crypto/crc7-inline.h +++ b/include/bfdev/crypto/crc7-inline.h @@ -14,8 +14,8 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc7, uint8_t, - bfdev_crc7_table, (uint8_t) + bfdev_crc7, bfdev_u8, + bfdev_crc7_table, (bfdev_u8) ) BFDEV_END_DECLS diff --git a/include/bfdev/crypto/crc8-inline.h b/include/bfdev/crypto/crc8-inline.h index 710a9295..4f8121ad 100644 --- a/include/bfdev/crypto/crc8-inline.h +++ b/include/bfdev/crypto/crc8-inline.h @@ -14,8 +14,8 @@ BFDEV_BEGIN_DECLS #include BFDEV_CRC_INLINE( - bfdev_crc8, uint8_t, - bfdev_crc8_table, (uint8_t) + bfdev_crc8, bfdev_u8, + bfdev_crc8_table, (bfdev_u8) ) BFDEV_END_DECLS diff --git a/include/bfdev/crypto/md5-base.h b/include/bfdev/crypto/md5-base.h index 189e6e1c..7f4b7800 100644 --- a/include/bfdev/crypto/md5-base.h +++ b/include/bfdev/crypto/md5-base.h @@ -20,77 +20,77 @@ typedef void (*bfdev_md5_bfn_t) static inline void bfdev_md5_base_update(bfdev_md5_ctx_t *ctx, const void *data, - size_t size, bfdev_md5_bfn_t func) + bfdev_size_t size, bfdev_md5_bfn_t func) { - unsigned long avail; - - avail = sizeof(ctx->block) - (ctx->count & 0x3f); - ctx->count += size; - - if (avail > size) { - bfport_memcpy((void *)ctx->block + (sizeof(ctx->block) - avail), - data, size); - return; - } - - bfport_memcpy((char *)ctx->block + (sizeof(ctx->block) - avail), - data, avail); - func(ctx); - data += avail; - size -= avail; - - while (size >= sizeof(ctx->block)) { - memcpy(ctx->block, data, sizeof(ctx->block)); - func(ctx); - data += sizeof(ctx->block); - size -= sizeof(ctx->block); - } - - memcpy(ctx->block, data, size); + unsigned long avail; + + avail = sizeof(ctx->block) - (ctx->count & 0x3f); + ctx->count += size; + + if (avail > size) { + bfdev_memcpy((void *)ctx->block + (sizeof(ctx->block) - avail), + data, size); + return; + } + + bfdev_memcpy((char *)ctx->block + (sizeof(ctx->block) - avail), + data, avail); + func(ctx); + data += avail; + size -= avail; + + while (size >= sizeof(ctx->block)) { + bfdev_memcpy(ctx->block, data, sizeof(ctx->block)); + func(ctx); + data += sizeof(ctx->block); + size -= sizeof(ctx->block); + } + + bfdev_memcpy(ctx->block, data, size); } static inline void bfdev_md5_base_finalize(bfdev_md5_ctx_t *ctx, bfdev_md5_bfn_t func) { - unsigned long offset; - int padding; - char *ptr; - - offset = ctx->count & 0x3f; - ptr = (char *)ctx->block + offset; - *ptr++ = 0x80; - - padding = 56 - (offset + 1); - if (padding < 0) { - bfport_memset(ptr, 0, padding + BFDEV_BYTES_PER_U64); - func(ctx); - ptr = (char *)ctx->block; - padding = 56; - } - - bfport_memset(ptr, 0, padding); - ctx->block[14] = ctx->count << 3; - ctx->block[15] = ctx->count >> 29; - bfdev_le32_to_cpu_array(ctx->block, (bfdev_le32 *)ctx->block, (sizeof(ctx->block) - - BFDEV_BYTES_PER_U64) / BFDEV_BYTES_PER_U32); - func(ctx); + unsigned long offset; + int padding; + char *ptr; + + offset = ctx->count & 0x3f; + ptr = (char *)ctx->block + offset; + *ptr++ = 0x80; + + padding = 56 - (offset + 1); + if (padding < 0) { + bfdev_memset(ptr, 0, padding + BFDEV_BYTES_PER_U64); + func(ctx); + ptr = (char *)ctx->block; + padding = 56; + } + + bfdev_memset(ptr, 0, padding); + ctx->block[14] = ctx->count << 3; + ctx->block[15] = ctx->count >> 29; + bfdev_le32_to_cpu_array(ctx->block, (bfdev_le32 *)ctx->block, + (sizeof(ctx->block) - BFDEV_BYTES_PER_U64) / BFDEV_BYTES_PER_U32); + func(ctx); } static inline void bfdev_md5_base_final(bfdev_md5_ctx_t *ctx, void *buff) { - bfdev_cpu_to_le32_array((bfdev_le32 *)ctx->digest, ctx->digest, - sizeof(ctx->digest) / BFDEV_BYTES_PER_U32); - bfport_memcpy(buff, ctx->digest, sizeof(ctx->digest)); + bfdev_cpu_to_le32_array((bfdev_le32 *)ctx->digest, ctx->digest, + sizeof(ctx->digest) / BFDEV_BYTES_PER_U32); + bfdev_memcpy(buff, ctx->digest, sizeof(ctx->digest)); } static inline void -bfdev_md5_digest_init(uint32_t *digest) +bfdev_md5_digest_init(bfdev_u32 *digest) { - digest[0] = BFDEV_MD5_H0; - digest[1] = BFDEV_MD5_H1; - digest[2] = BFDEV_MD5_H2; - digest[3] = BFDEV_MD5_H3; + digest[0] = BFDEV_MD5_H0; + digest[1] = BFDEV_MD5_H1; + digest[2] = BFDEV_MD5_H2; + digest[3] = BFDEV_MD5_H3; } BFDEV_END_DECLS diff --git a/include/bfdev/crypto/md5.h b/include/bfdev/crypto/md5.h index 6bd346a7..1455a1b0 100644 --- a/include/bfdev/crypto/md5.h +++ b/include/bfdev/crypto/md5.h @@ -23,9 +23,9 @@ BFDEV_BEGIN_DECLS }) static inline void -bfdev_md5_transform(uint32_t *hash, const uint32_t *data) +bfdev_md5_transform(bfdev_u32 *hash, const bfdev_u32 *data) { - uint32_t A, B, C, D; + bfdev_u32 A, B, C, D; A = hash[0]; B = hash[1]; diff --git a/include/bfdev/crypto/sha1-base.h b/include/bfdev/crypto/sha1-base.h index 31ddeb9f..e8384eb9 100644 --- a/include/bfdev/crypto/sha1-base.h +++ b/include/bfdev/crypto/sha1-base.h @@ -15,14 +15,14 @@ BFDEV_BEGIN_DECLS typedef void (*bfdev_sha1_bfn_t) -(bfdev_sha1_ctx_t *ctx, const void *src, size_t block); +(bfdev_sha1_ctx_t *ctx, const void *src, bfdev_size_t block); static inline void bfdev_sha1_base_update(bfdev_sha1_ctx_t *ctx, const void *data, - size_t size, bfdev_sha1_bfn_t func) + bfdev_size_t size, bfdev_sha1_bfn_t func) { unsigned int partial; - size_t length, blocks; + bfdev_size_t length, blocks; partial = ctx->count % BFDEV_SHA1_BLOCK_SIZE; ctx->count += size; @@ -30,7 +30,7 @@ bfdev_sha1_base_update(bfdev_sha1_ctx_t *ctx, const void *data, if (bfdev_unlikely((partial + size) >= BFDEV_SHA1_BLOCK_SIZE)) { if (partial) { length = BFDEV_SHA1_BLOCK_SIZE - partial; - bfport_memcpy(ctx->buffer + partial, data, length); + bfdev_memcpy(ctx->buffer + partial, data, length); func(ctx, ctx->buffer, 1); data += length; @@ -49,7 +49,7 @@ bfdev_sha1_base_update(bfdev_sha1_ctx_t *ctx, const void *data, } if (size) - bfport_memcpy(ctx->buffer + partial, data, size); + bfdev_memcpy(ctx->buffer + partial, data, size); } static inline void @@ -65,13 +65,13 @@ bfdev_sha1_base_finalize(bfdev_sha1_ctx_t *ctx, bfdev_sha1_bfn_t func) ctx->buffer[partial++] = 0x80; if (offset < partial) { - bfport_memset(ctx->buffer + partial, 0, BFDEV_SHA1_BLOCK_SIZE - partial); + bfdev_memset(ctx->buffer + partial, 0, BFDEV_SHA1_BLOCK_SIZE - partial); func(ctx, ctx->buffer, 1); partial = 0; } - bfport_memset(ctx->buffer + partial, 0, offset - partial); - bfdev_unaligned_set_be64(plen, (uint64_t)ctx->count << 3); + bfdev_memset(ctx->buffer + partial, 0, offset - partial); + bfdev_unaligned_set_be64(plen, (bfdev_u64)ctx->count << 3); func(ctx, ctx->buffer, 1); } @@ -87,7 +87,7 @@ bfdev_sha1_base_finish(bfdev_sha1_ctx_t *ctx, void *buff) } static inline void -bfdev_sha1_digest_init(uint32_t *digest) +bfdev_sha1_digest_init(bfdev_u32 *digest) { digest[0] = BFDEV_SHA1_DIGEST0; digest[1] = BFDEV_SHA1_DIGEST1; diff --git a/include/bfdev/crypto/sha1.h b/include/bfdev/crypto/sha1.h index 06bcad8e..9cfbcb12 100644 --- a/include/bfdev/crypto/sha1.h +++ b/include/bfdev/crypto/sha1.h @@ -14,14 +14,14 @@ BFDEV_BEGIN_DECLS #define BFDEV_SHA1_W(c, b) (b[(c) & 0x0f]) -#define BFDEV_SHA1_SRC(c, b, d) bfdev_unaligned_get_be32((uint32_t *)d + c) +#define BFDEV_SHA1_SRC(c, b, d) bfdev_unaligned_get_be32((bfdev_u32 *)d + c) #define BFDEV_SHA1_MIX(c, b, d) \ bfdev_rol32(BFDEV_SHA1_W(c + 13, b) ^ BFDEV_SHA1_W(c + 8, b) ^ \ BFDEV_SHA1_W(c + 2, b) ^ BFDEV_SHA1_W(c, b), 1) #define BFDEV_SHA1_ROUND(c, b, d, A, B, C, D, E, func, const, exp) do { \ - uint32_t __value; \ + bfdev_u32 __value; \ __value = func(c, b, d); \ BFDEV_SHA1_W(c, b) = __value; \ E += __value + bfdev_rol32(A, 5) + (exp) + (const); \ @@ -50,9 +50,9 @@ BFDEV_BEGIN_DECLS 0xca62c1d6, (B ^ C ^ D)) static inline void -bfdev_sha1_transform(uint32_t *digest, uint32_t *block, const uint8_t *data) +bfdev_sha1_transform(bfdev_u32 *digest, bfdev_u32 *block, const bfdev_u8 *data) { - uint32_t A, B, C, D, E; + bfdev_u32 A, B, C, D, E; unsigned int count; /* Load state */ @@ -63,23 +63,23 @@ bfdev_sha1_transform(uint32_t *digest, uint32_t *block, const uint8_t *data) E = digest[4]; count = 0; - /* Round 1 MIX */ + /* Round 1 MIX */ for (; count < 16; ++count) BFDEV_SHA1_00_15(count, block, data, A, B, C, D, E); - /* Round 1 SRC */ + /* Round 1 SRC */ for (; count < 20; ++count) BFDEV_SHA1_16_19(count, block, data, A, B, C, D, E); - /* Round 2 */ + /* Round 2 */ for (; count < 40; ++count) BFDEV_SHA1_20_39(count, block, data, A, B, C, D, E); - /* Round 3 */ + /* Round 3 */ for (; count < 60; ++count) BFDEV_SHA1_40_59(count, block, data, A, B, C, D, E); - /* Round 4 */ + /* Round 4 */ for (; count < 80; ++count) BFDEV_SHA1_60_79(count, block, data, A, B, C, D, E); diff --git a/include/bfdev/crypto/sha2-base.h b/include/bfdev/crypto/sha2-base.h index 0a766d4c..1061bcf9 100644 --- a/include/bfdev/crypto/sha2-base.h +++ b/include/bfdev/crypto/sha2-base.h @@ -15,14 +15,14 @@ BFDEV_BEGIN_DECLS typedef void (*bfdev_sha2_bfn_t) -(bfdev_sha2_ctx_t *ctx, const void *src, size_t block); +(bfdev_sha2_ctx_t *ctx, const void *src, bfdev_size_t block); static inline void bfdev_sha2_base_update(bfdev_sha2_ctx_t *ctx, const void *data, - size_t size, bfdev_sha2_bfn_t func) + bfdev_size_t size, bfdev_sha2_bfn_t func) { unsigned int partial; - size_t length, blocks; + bfdev_size_t length, blocks; partial = ctx->count % BFDEV_SHA2_BLOCK_SIZE; ctx->count += size; @@ -30,7 +30,7 @@ bfdev_sha2_base_update(bfdev_sha2_ctx_t *ctx, const void *data, if (bfdev_unlikely((partial + size) >= BFDEV_SHA2_BLOCK_SIZE)) { if (partial) { length = BFDEV_SHA2_BLOCK_SIZE - partial; - bfport_memcpy(ctx->buffer + partial, data, length); + bfdev_memcpy(ctx->buffer + partial, data, length); func(ctx, ctx->buffer, 1); data += length; @@ -49,7 +49,7 @@ bfdev_sha2_base_update(bfdev_sha2_ctx_t *ctx, const void *data, } if (size) - bfport_memcpy(ctx->buffer + partial, data, size); + bfdev_memcpy(ctx->buffer + partial, data, size); } static inline void @@ -65,13 +65,13 @@ bfdev_sha2_base_finalize(bfdev_sha2_ctx_t *ctx, bfdev_sha2_bfn_t func) ctx->buffer[partial++] = 0x80; if (offset < partial) { - bfport_memset(ctx->buffer + partial, 0, BFDEV_SHA2_BLOCK_SIZE - partial); + bfdev_memset(ctx->buffer + partial, 0, BFDEV_SHA2_BLOCK_SIZE - partial); func(ctx, ctx->buffer, 1); partial = 0; } - bfport_memset(ctx->buffer + partial, 0, offset - partial); - bfdev_unaligned_set_be64(plen, (uint64_t)ctx->count << 3); + bfdev_memset(ctx->buffer + partial, 0, offset - partial); + bfdev_unaligned_set_be64(plen, (bfdev_u64)ctx->count << 3); func(ctx, ctx->buffer, 1); } @@ -87,7 +87,7 @@ bfdev_sha2_base_finish(bfdev_sha2_ctx_t *ctx, unsigned int dsize, void *buff) } static inline void -bfdev_sha224_digest_init(uint32_t *digest) +bfdev_sha224_digest_init(bfdev_u32 *digest) { digest[0] = BFDEV_SHA224_DIGEST0; digest[1] = BFDEV_SHA224_DIGEST1; @@ -100,7 +100,7 @@ bfdev_sha224_digest_init(uint32_t *digest) } static inline void -bfdev_sha256_digest_init(uint32_t *digest) +bfdev_sha256_digest_init(bfdev_u32 *digest) { digest[0] = BFDEV_SHA256_DIGEST0; digest[1] = BFDEV_SHA256_DIGEST1; diff --git a/include/bfdev/crypto/sha2.h b/include/bfdev/crypto/sha2.h index f23471ac..186ece10 100644 --- a/include/bfdev/crypto/sha2.h +++ b/include/bfdev/crypto/sha2.h @@ -13,7 +13,7 @@ BFDEV_BEGIN_DECLS -static const uint32_t +static const bfdev_u32 bfdev_sha2_k[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, @@ -53,7 +53,7 @@ bfdev_sha2_k[64] = { #define BFDEV_SHA2_MAJ(x, y, z) ((x & y) | (z & (x | y))) #define BFDEV_SHA2_LOAD(c, b, d) ( \ - b[c] = bfdev_unaligned_get_be32((uint32_t *)d + c) \ + b[c] = bfdev_unaligned_get_be32((bfdev_u32 *)d + c) \ ) #define BFDEV_SHA2_BLEND(c, b) ( \ @@ -62,7 +62,7 @@ bfdev_sha2_k[64] = { ) #define BFDEV_SHA2_ROUND(c, b, A, B, C, D, E, F, G, H) do { \ - uint32_t __tmp1, __tmp2; \ + bfdev_u32 __tmp1, __tmp2; \ __tmp1 = H + BFDEV_SHA2_E1(E) + BFDEV_SHA2_CH(E, F, G) + \ bfdev_sha2_k[c] + b[c]; \ __tmp2 = BFDEV_SHA2_E0(A) + BFDEV_SHA2_MAJ(A, B, C); \ @@ -70,9 +70,9 @@ bfdev_sha2_k[64] = { } while (0) static inline void -bfdev_sha2_transform(uint32_t *digest, uint32_t *block, const uint8_t *data) +bfdev_sha2_transform(bfdev_u32 *digest, bfdev_u32 *block, const bfdev_u8 *data) { - uint32_t A, B, C, D, E, F, G, H; + bfdev_u32 A, B, C, D, E, F, G, H; unsigned int count; /* Load state */ diff --git a/include/bfdev/ctype.h b/include/bfdev/ctype.h index fb30d45e..c6cbe1f5 100644 --- a/include/bfdev/ctype.h +++ b/include/bfdev/ctype.h @@ -7,7 +7,6 @@ #define _BFDEV_CTYPE_H_ #include -#include BFDEV_BEGIN_DECLS @@ -258,7 +257,7 @@ bfdev_toascii(int c) static inline int bfdev_tolower(int c) { - if (isupper(c)) + if (bfdev_isupper(c)) return (unsigned char)c | 32; return (unsigned char)c; } @@ -266,7 +265,7 @@ bfdev_tolower(int c) static inline int bfdev_toupper(int c) { - if (islower(c)) + if (bfdev_islower(c)) return (unsigned char)c & 0x5f; return (unsigned char)c; } diff --git a/include/bfdev/errptr.h b/include/bfdev/errptr.h index f2c4173d..e949ad7a 100644 --- a/include/bfdev/errptr.h +++ b/include/bfdev/errptr.h @@ -20,7 +20,7 @@ BFDEV_BEGIN_DECLS static inline void * BFDEV_ERR_PTR(int error) { - return (void *)(intptr_t)error; + return (void *)(bfdev_intptr_t)error; } /** @@ -30,7 +30,7 @@ BFDEV_ERR_PTR(int error) static inline int BFDEV_PTR_ERR(const void *ptr) { - return (int)(intptr_t)ptr; + return (int)(bfdev_intptr_t)ptr; } /** @@ -47,17 +47,17 @@ BFDEV_PTR_INVAL(const void *ptr) * BFDEV_IS_ERR - Check whether pointer is error value. * @ptr: the pointer to check. */ -static inline bool +static inline bfdev_bool BFDEV_IS_ERR(const void *ptr) { - return (uintptr_t)ptr >= (uintptr_t)-BFDEV_ERRNO_MAX; + return (bfdev_uintptr_t)ptr >= (bfdev_uintptr_t)-BFDEV_ERRNO_MAX; } /** * BFDEV_IS_INVAL - Check whether pointer is error value or null. * @ptr: the pointer to check. */ -static inline bool +static inline bfdev_bool BFDEV_IS_INVAL(const void *ptr) { return bfdev_unlikely(!ptr) || BFDEV_IS_ERR(ptr); diff --git a/include/bfdev/fifo.h b/include/bfdev/fifo.h index 7475dd1b..55b06147 100644 --- a/include/bfdev/fifo.h +++ b/include/bfdev/fifo.h @@ -85,7 +85,8 @@ struct bfdev_fifo { #define BFDEV_FIFO_DYNAMIC_INIT(ptr) \ (typeof(*(ptr))) { \ .fifo = { \ - .in = 0, .out = 0, .mask = 0, .data = NULL, \ + .in = 0, .out = 0, .mask = 0, \ + .data = BFDEV_NULL, \ .esize = sizeof(*(ptr)->buff), \ }, \ } @@ -452,7 +453,7 @@ bfdev_fifo_in_record(bfdev_fifo_t *fifo, const void *buff, unsigned long len, extern int bfdev_fifo_dynamic_alloc(bfdev_fifo_t *fifo, const bfdev_alloc_t *alloc, - size_t esize, size_t size); + bfdev_size_t esize, bfdev_size_t size); extern void bfdev_fifo_dynamic_free(bfdev_fifo_t *fifo); diff --git a/include/bfdev/fsm.h b/include/bfdev/fsm.h index ff85286e..1f607d2d 100644 --- a/include/bfdev/fsm.h +++ b/include/bfdev/fsm.h @@ -48,7 +48,7 @@ struct bfdev_fsm_transition { const void *cond; const bfdev_fsm_state_t *next; - bool cross; + bfdev_bool cross; int stack; bfdev_fsm_guard_t guard; @@ -74,12 +74,9 @@ struct bfdev_fsm_state { * @state: State history table, including current and previous states. * @error: Pointer to a state that will be entered whenever an error occurs * in the state machine. - * @stack: - * @count: * * The previous state is stored for convenience in case the user needs to * keep track of previous states. - * */ struct bfdev_fsm { const bfdev_fsm_state_t *state[2]; @@ -156,11 +153,11 @@ bfdev_fsm_prev(const bfdev_fsm_t *fsm) * * Return true if the state machine has reached a final state. */ -static inline bool +static inline bfdev_bool bfdev_fsm_finished(bfdev_fsm_t *fsm) { const bfdev_fsm_state_t *state; - bool retval; + bfdev_bool retval; state = bfdev_fsm_curr(fsm); retval = !state->tnum && !state->exception; @@ -175,16 +172,16 @@ bfdev_fsm_finished(bfdev_fsm_t *fsm) * * Return true if the transition meeted. */ -static inline bool +static inline bfdev_bool bfdev_fsm_cond(const bfdev_fsm_transition_t *trans, bfdev_fsm_event_t *event) { /* A transition for the given event has been found. */ if (trans->type != event->type) - return false; + return bfdev_false; /* If transition is guarded, ensure that the condition is held. */ if (!trans->guard) - return true; + return bfdev_true; return !trans->guard(event, trans->cond); } diff --git a/include/bfdev/glob.h b/include/bfdev/glob.h index f3cd0bd0..12618bd0 100644 --- a/include/bfdev/glob.h +++ b/include/bfdev/glob.h @@ -12,7 +12,7 @@ BFDEV_BEGIN_DECLS -extern bool +extern bfdev_bool bfdev_glob(const char *patten, const char *string); BFDEV_END_DECLS diff --git a/include/bfdev/guards.h b/include/bfdev/guards.h index 737add79..c79a186a 100644 --- a/include/bfdev/guards.h +++ b/include/bfdev/guards.h @@ -22,7 +22,7 @@ __bfdev_cleanup_##name(void *object) \ #define bfdev_clean_lasting(object) ({ \ __auto_type __ptr = (object); \ - (object) = NULL; __ptr; \ + (object) = BFDEV_NULL; __ptr; \ }) #define bfdev_clean(name) \ diff --git a/include/bfdev/hash.h b/include/bfdev/hash.h index dc2a887d..d8c4b466 100644 --- a/include/bfdev/hash.h +++ b/include/bfdev/hash.h @@ -30,15 +30,15 @@ BFDEV_BEGIN_DECLS * bfdev_hashv{32/64}_generic() - General func for calc hash value. * @value: value to hash. */ -static __bfdev_always_inline -uint32_t bfdev_hashv32_generic(uint32_t value) +static __bfdev_always_inline bfdev_u32 +bfdev_hashv32_generic(bfdev_u32 value) { /* Gold ratio method calc hash value. */ return value * BFDEV_GOLDEN_RATIO_32; } -static __bfdev_always_inline -uint64_t bfdev_hashv64_generic(uint64_t value) +static __bfdev_always_inline bfdev_u64 +bfdev_hashv64_generic(bfdev_u64 value) { return value * BFDEV_GOLDEN_RATIO_64; } @@ -48,15 +48,15 @@ uint64_t bfdev_hashv64_generic(uint64_t value) * @value: value to hash. * @bits: bit number of result. */ -static __bfdev_always_inline -uint32_t bfdev_hash32(uint32_t value, unsigned int bits) +static __bfdev_always_inline bfdev_u32 +bfdev_hash32(bfdev_u32 value, unsigned int bits) { /* High bits are more random, so use them. */ return bfdev_hashv32(value) >> (BFDEV_BITS_PER_U32 - bits); } -static __bfdev_always_inline -uint64_t bfdev_hash64(uint64_t value, unsigned int bits) +static __bfdev_always_inline bfdev_u64 +bfdev_hash64(bfdev_u64 value, unsigned int bits) { return bfdev_hashv64(value) >> (BFDEV_BITS_PER_U64 - bits); } diff --git a/include/bfdev/hashmap.h b/include/bfdev/hashmap.h index c3c5a2d0..8b52b970 100644 --- a/include/bfdev/hashmap.h +++ b/include/bfdev/hashmap.h @@ -52,8 +52,8 @@ struct bfdev_hashmap_ops { long (*equal)(const bfdev_hlist_node_t *node1, const bfdev_hlist_node_t *node2, void *pdata); long (*find)(const bfdev_hlist_node_t *node, const void *key, void *pdata); - bool (*extend)(const bfdev_hashmap_t *hashmap, void *pdata); - bool (*shrink)(const bfdev_hashmap_t *hashmap, void *pdata); + bfdev_bool (*extend)(const bfdev_hashmap_t *hashmap, void *pdata); + bfdev_bool (*shrink)(const bfdev_hashmap_t *hashmap, void *pdata); }; #define BFDEV_HASHMAP_STATIC(ALLOC, OPS, PDATA) { \ @@ -119,7 +119,7 @@ bfdev_hashmap_release(bfdev_hashmap_t *hashmap); static __bfdev_always_inline int bfdev_hashmap_add(bfdev_hashmap_t *hashmap, bfdev_hlist_node_t *node) { - return bfdev_hashmap_insert(hashmap, node, NULL, BFDEV_HASHMAP_ADD); + return bfdev_hashmap_insert(hashmap, node, BFDEV_NULL, BFDEV_HASHMAP_ADD); } static __bfdev_always_inline int @@ -139,7 +139,7 @@ bfdev_hashmap_update(bfdev_hashmap_t *hashmap, bfdev_hlist_node_t *node, static __bfdev_always_inline int bfdev_hashmap_append(bfdev_hashmap_t *hashmap, bfdev_hlist_node_t *node) { - return bfdev_hashmap_insert(hashmap, node, NULL, BFDEV_HASHMAP_APPEND); + return bfdev_hashmap_insert(hashmap, node, BFDEV_NULL, BFDEV_HASHMAP_APPEND); } /** diff --git a/include/bfdev/hashtbl.h b/include/bfdev/hashtbl.h index a07f53b4..84e09303 100644 --- a/include/bfdev/hashtbl.h +++ b/include/bfdev/hashtbl.h @@ -56,17 +56,17 @@ bfdev_hashtbl_init(bfdev_hlist_head_t *head, unsigned long size) * bfdev_hash_empty - check whether a hashtable is empty. * @hashtable: hashtable to check. */ -static inline bool +static inline bfdev_bool bfdev_hashtbl_empty(bfdev_hlist_head_t *head, unsigned long size) { unsigned long count; for (count = 0; count < size; ++count) { if (!bfdev_hlist_check_empty(&head[count])) - return false; + return bfdev_false; } - return true; + return bfdev_true; } /** diff --git a/include/bfdev/heap.h b/include/bfdev/heap.h index 3c112727..19fc6084 100644 --- a/include/bfdev/heap.h +++ b/include/bfdev/heap.h @@ -29,7 +29,7 @@ struct bfdev_heap_root { }; #define BFDEV_HEAP_STATIC() { \ - .node = NULL, .count = 0, \ + .node = BFDEV_NULL, .count = 0, \ } #define BFDEV_HEAP_INIT() \ @@ -63,11 +63,11 @@ struct bfdev_heap_root { bfdev_container_of_safe(ptr, type, member) #ifdef BFDEV_DEBUG_HEAP -extern bool +extern bfdev_bool bfdev_heap_check_link(bfdev_heap_node_t *parent, bfdev_heap_node_t **link, bfdev_heap_node_t *node); -extern bool +extern bfdev_bool bfdev_heap_check_delete(bfdev_heap_node_t *node); #endif @@ -82,7 +82,7 @@ bfdev_heap_init(bfdev_heap_root_t *root) *root = BFDEV_HEAP_INIT(); } -static inline bool +static inline bfdev_bool bfdev_heap_empty_root(bfdev_heap_root_t *root) { return !root->node; @@ -153,7 +153,7 @@ bfdev_heap_link(bfdev_heap_root_t *root, bfdev_heap_node_t *parent, /* link = &parent->left/right */ *link = node; node->parent = parent; - node->left = node->right = NULL; + node->left = node->right = BFDEV_NULL; root->count++; } diff --git a/include/bfdev/hlist.h b/include/bfdev/hlist.h index fe93023a..a24637d2 100644 --- a/include/bfdev/hlist.h +++ b/include/bfdev/hlist.h @@ -27,7 +27,7 @@ struct bfdev_hlist_head { }; #define BFDEV_HLIST_HEAD_STATIC() { \ - .node = NULL, \ + .node = BFDEV_NULL, \ } #define BFDEV_HLIST_HEAD_INIT() \ @@ -37,16 +37,16 @@ struct bfdev_hlist_head { bfdev_hlist_head_t name = BFDEV_HLIST_HEAD_INIT() #ifdef BFDEV_DEBUG_HLIST -extern bool +extern bfdev_bool bfdev_hlist_check_head_add(bfdev_hlist_head_t *head, bfdev_hlist_node_t *newn); -extern bool +extern bfdev_bool bfdev_hlist_check_next_add(bfdev_hlist_node_t *next, bfdev_hlist_node_t *newn); -extern bool +extern bfdev_bool bfdev_hlist_check_prev_add(bfdev_hlist_node_t *prev, bfdev_hlist_node_t *newn); -extern bool +extern bfdev_bool bfdev_hlist_check_del(bfdev_hlist_node_t *node); #endif @@ -67,8 +67,8 @@ bfdev_hlist_head_init(bfdev_hlist_head_t *head) static inline void bfdev_hlist_node_init(bfdev_hlist_node_t *node) { - node->pprev = NULL; - node->next = NULL; + node->pprev = BFDEV_NULL; + node->next = BFDEV_NULL; } /** @@ -94,7 +94,7 @@ bfdev_hlist_head_add(bfdev_hlist_head_t *head, bfdev_hlist_node_t *newn) /** * bfdev_hlist_next_add() - add a new entry before the one specified. - * @node: hlist node to add it after, which must be non-NULL. + * @node: hlist node to add it after, which must be non-BFDEV_NULL. * @newn: new entry to be added. */ static inline void @@ -115,7 +115,7 @@ bfdev_hlist_next_add(bfdev_hlist_node_t *node, bfdev_hlist_node_t *newn) /** * bfdev_hlist_prev_add() - add a new entry before the one specified. - * @node: hlist node to add it before, which must be non-NULL. + * @node: hlist node to add it before, which must be non-BFDEV_NULL. * @newn: new entry to be added. */ static inline void @@ -170,7 +170,7 @@ bfdev_hlist_del(bfdev_hlist_node_t *node) * bfdev_hlist_check_empty() - check whether the node is head. * @head: hlist head to check. */ -static inline bool +static inline bfdev_bool bfdev_hlist_check_empty(const bfdev_hlist_head_t *head) { return !head->node; @@ -181,7 +181,7 @@ bfdev_hlist_check_empty(const bfdev_hlist_head_t *head) * @head: the head of the hlist. * @node: the entry to test. */ -static inline bool +static inline bfdev_bool bfdev_hlist_check_first(const bfdev_hlist_head_t *head, const bfdev_hlist_node_t *node) { @@ -192,7 +192,7 @@ bfdev_hlist_check_first(const bfdev_hlist_head_t *head, * bfdev_hlist_check_end() - check whether the node is a ending. * @node: the entry to test. */ -static inline bool +static inline bfdev_bool bfdev_hlist_check_end(const bfdev_hlist_node_t *node) { return !node->next; @@ -203,18 +203,18 @@ bfdev_hlist_check_end(const bfdev_hlist_node_t *node) * @head: hlist head to check. * @node: the unique node. */ -static inline bool +static inline bfdev_bool bfdev_hlist_check_another(const bfdev_hlist_head_t *head, const bfdev_hlist_node_t *node) { - return head->node == node && node->next == NULL; + return head->node == node && node->next == BFDEV_NULL; } /** * bfdev_hlist_check_unhashed() - check whether the node is reinitialized. * @node: hlist node to check. */ -static inline bool +static inline bfdev_bool bfdev_hlist_check_unhashed(const bfdev_hlist_node_t *node) { return !node->pprev; @@ -229,7 +229,7 @@ static inline void bfdev_hlist_head_replace(bfdev_hlist_head_t *oldn, bfdev_hlist_head_t *newn) { newn->node = oldn->node; - oldn->node = NULL; + oldn->node = BFDEV_NULL; if (newn->node) newn->node->pprev = &newn->node; } diff --git a/include/bfdev/ilist.h b/include/bfdev/ilist.h index a14ddc09..be594c3d 100644 --- a/include/bfdev/ilist.h +++ b/include/bfdev/ilist.h @@ -105,7 +105,7 @@ bfdev_ilist_last(const bfdev_ilist_head_t *ihead) * bfdev_list_check_empty() - check whether a head is empty. * @ihead: list head to check. */ -static inline bool +static inline bfdev_bool bfdev_ilist_head_empty(bfdev_ilist_head_t *ihead) { return bfdev_list_check_empty(&ihead->node_list); @@ -115,7 +115,7 @@ bfdev_ilist_head_empty(bfdev_ilist_head_t *ihead) * bfdev_list_check_empty() - check whether a node index is empty. * @inode: list node to check. */ -static inline bool +static inline bfdev_bool bfdev_ilist_node_empty(bfdev_ilist_node_t *inode) { return bfdev_list_check_empty(&inode->index_list); diff --git a/include/bfdev/jhash.h b/include/bfdev/jhash.h index 4c15cdb7..5c9fa8f6 100644 --- a/include/bfdev/jhash.h +++ b/include/bfdev/jhash.h @@ -17,12 +17,12 @@ BFDEV_BEGIN_DECLS /* Mix 3 32-bit values reversibly */ #define bfdev_jhash_mix(a, b, c) { \ - a -= c; a ^= bfdev_rol32(c, 4); c += b; \ - b -= a; b ^= bfdev_rol32(a, 6); a += c; \ - c -= b; c ^= bfdev_rol32(b, 8); b += a; \ - a -= c; a ^= bfdev_rol32(c, 16); c += b; \ - b -= a; b ^= bfdev_rol32(a, 19); a += c; \ - c -= b; c ^= bfdev_rol32(b, 4); b += a; \ + a -= c; a ^= bfdev_rol32(c, 4); c += b; \ + b -= a; b ^= bfdev_rol32(a, 6); a += c; \ + c -= b; c ^= bfdev_rol32(b, 8); b += a; \ + a -= c; a ^= bfdev_rol32(c, 16); c += b; \ + b -= a; b ^= bfdev_rol32(a, 19); a += c; \ + c -= b; c ^= bfdev_rol32(b, 4); b += a; \ } /* Final mixing of 3 32-bit values (a,b,c) into c */ @@ -36,8 +36,8 @@ BFDEV_BEGIN_DECLS c ^= b; c -= bfdev_rol32(b, 24); \ } -extern uint32_t -bfdev_jhash(const void *data, size_t length, uint32_t initval); +extern bfdev_u32 +bfdev_jhash(const void *data, bfdev_size_t length, bfdev_u32 initval); BFDEV_END_DECLS diff --git a/include/bfdev/levenshtein.h b/include/bfdev/levenshtein.h index df556511..de249785 100644 --- a/include/bfdev/levenshtein.h +++ b/include/bfdev/levenshtein.h @@ -27,7 +27,7 @@ BFDEV_BEGIN_DECLS extern unsigned int bfdev_levenshtein_len(const bfdev_alloc_t *alloc, const char *str1, const char *str2, - size_t len1, size_t len2, + bfdev_size_t len1, bfdev_size_t len2, unsigned int s, unsigned int w, unsigned int a, unsigned int d); diff --git a/include/bfdev/limits.h b/include/bfdev/limits.h index 49592af1..6d7bfdb9 100644 --- a/include/bfdev/limits.h +++ b/include/bfdev/limits.h @@ -7,7 +7,6 @@ #define _BFDEV_LIMITS_H_ #include -#include BFDEV_BEGIN_DECLS @@ -52,48 +51,48 @@ BFDEV_BEGIN_DECLS #define BFDEV_LLONG_MIN ((signed long long)(-BFDEV_LLONG_MAX - 1)) /* Maximum of unsigned integral types */ -#define BFDEV_UINT8_MAX ((uint8_t)~0U) -#define BFDEV_UINT16_MAX ((uint16_t)~0U) -#define BFDEV_UINT32_MAX ((uint32_t)~0U) -#define BFDEV_UINT64_MAX ((uint64_t)~0ULL) +#define BFDEV_UINT8_MAX ((bfdev_u8)~0U) +#define BFDEV_UINT16_MAX ((bfdev_u16)~0U) +#define BFDEV_UINT32_MAX ((bfdev_u32)~0U) +#define BFDEV_UINT64_MAX ((bfdev_u64)~0ULL) /* Minimum of unsigned integral types */ -#define BFDEV_UINT8_MIN ((uint8_t)0U) -#define BFDEV_UINT16_MIN ((uint16_t)0U) -#define BFDEV_UINT32_MIN ((uint32_t)0U) -#define BFDEV_UINT64_MIN ((uint64_t)0ULL) +#define BFDEV_UINT8_MIN ((bfdev_u8)0U) +#define BFDEV_UINT16_MIN ((bfdev_u16)0U) +#define BFDEV_UINT32_MIN ((bfdev_u32)0U) +#define BFDEV_UINT64_MIN ((bfdev_u64)0ULL) /* Maximum of signed integral types */ -#define BFDEV_INT8_MAX ((int8_t)(BFDEV_UINT8_MAX >> 1)) -#define BFDEV_INT16_MAX ((int16_t)(BFDEV_UINT16_MAX >> 1)) -#define BFDEV_INT32_MAX ((int32_t)(BFDEV_UINT32_MAX >> 1)) -#define BFDEV_INT64_MAX ((int64_t)(BFDEV_UINT64_MAX >> 1)) +#define BFDEV_INT8_MAX ((bfdev_s8)(BFDEV_UINT8_MAX >> 1)) +#define BFDEV_INT16_MAX ((bfdev_s16)(BFDEV_UINT16_MAX >> 1)) +#define BFDEV_INT32_MAX ((bfdev_s32)(BFDEV_UINT32_MAX >> 1)) +#define BFDEV_INT64_MAX ((bfdev_s64)(BFDEV_UINT64_MAX >> 1)) /* Minimum of signed integral types */ -#define BFDEV_INT8_MIN ((int8_t)(-BFDEV_INT8_MAX - 1)) -#define BFDEV_INT16_MIN ((int16_t)(-BFDEV_INT16_MAX - 1)) -#define BFDEV_INT32_MIN ((int32_t)(-BFDEV_INT32_MAX - 1)) -#define BFDEV_INT64_MIN ((int64_t)(-BFDEV_INT64_MAX - 1)) +#define BFDEV_INT8_MIN ((bfdev_s8)(-BFDEV_INT8_MAX - 1)) +#define BFDEV_INT16_MIN ((bfdev_s16)(-BFDEV_INT16_MAX - 1)) +#define BFDEV_INT32_MIN ((bfdev_s32)(-BFDEV_INT32_MAX - 1)) +#define BFDEV_INT64_MIN ((bfdev_s64)(-BFDEV_INT64_MAX - 1)) /* Maximum of unsigned pointer types */ -#define BFDEV_UINTPTR_MAX ((uintptr_t)~0UL) +#define BFDEV_UINTPTR_MAX ((bfdev_uintptr_t)~0UL) #define BFDEV_UINTMAX_MAX ((uintmax_t)~0ULL) -#define BFDEV_SIZE_MAX ((size_t)~0UL) +#define BFDEV_SIZE_MAX ((bfdev_size_t)~0UL) /* Minimum of unsigned pointer types */ -#define BFDEV_UINTPTR_MIN ((uintptr_t)0UL) +#define BFDEV_UINTPTR_MIN ((bfdev_uintptr_t)0UL) #define BFDEV_UINTMAX_MIN ((uintmax_t)0ULL) -#define BFDEV_SIZE_MIN ((size_t)0UL) +#define BFDEV_SIZE_MIN ((bfdev_size_t)0UL) /* Maximum of signed pointer types */ -#define BFDEV_INTPTR_MAX ((intptr_t)(BFDEV_UINTPTR_MAX >> 1)) -#define BFDEV_PTRDIFF_MAX ((ptrdiff_t)(BFDEV_UINTPTR_MAX >> 1)) +#define BFDEV_INTPTR_MAX ((bfdev_intptr_t)(BFDEV_UINTPTR_MAX >> 1)) +#define BFDEV_PTRDIFF_MAX ((bfdev_ptrdiff_t)(BFDEV_UINTPTR_MAX >> 1)) #define BFDEV_INTMAX_MAX ((intmax_t)(BFDEV_UINTMAX_MAX >> 1)) #define BFDEV_SSIZE_MAX ((ssize_t)(BFDEV_SIZE_MAX >> 1)) /* Minimum of signed pointer types */ -#define BFDEV_INTPTR_MIN ((intptr_t)(-BFDEV_INTPTR_MAX - 1)) -#define BFDEV_PTRDIFF_MIN ((ptrdiff_t)(-BFDEV_PTRDIFF_MAX - 1)) +#define BFDEV_INTPTR_MIN ((bfdev_intptr_t)(-BFDEV_INTPTR_MAX - 1)) +#define BFDEV_PTRDIFF_MIN ((bfdev_ptrdiff_t)(-BFDEV_PTRDIFF_MAX - 1)) #define BFDEV_INTMAX_MIN ((intmax_t)(-BFDEV_INTMAX_MAX - 1)) #define BFDEV_SSIZE_MIN ((ssize_t)(-BFDEV_SSIZE_MAX - 1)) diff --git a/include/bfdev/list.h b/include/bfdev/list.h index 9b58a307..53425af5 100644 --- a/include/bfdev/list.h +++ b/include/bfdev/list.h @@ -41,11 +41,11 @@ bfdev_list_sort(bfdev_list_head_t *head, bfdev_list_cmp_t cmp, void *pdata); #ifdef BFDEV_DEBUG_LIST -extern bool +extern bfdev_bool bfdev_list_check_add(bfdev_list_head_t *prev, bfdev_list_head_t *next, bfdev_list_head_t *node); -extern bool +extern bfdev_bool bfdev_list_check_del(bfdev_list_head_t *node); #endif @@ -128,7 +128,7 @@ bfdev_list_del(bfdev_list_head_t *node) * bfdev_list_check_empty() - check whether a list is empty. * @head: list head to check. */ -static inline bool +static inline bfdev_bool bfdev_list_check_empty(const bfdev_list_head_t *head) { return head->next == head; @@ -139,7 +139,7 @@ bfdev_list_check_empty(const bfdev_list_head_t *head) * @head: the head of the list * @list: the entry to test */ -static inline bool +static inline bfdev_bool bfdev_list_check_head(const bfdev_list_head_t *head, const bfdev_list_head_t *node) { @@ -151,7 +151,7 @@ bfdev_list_check_head(const bfdev_list_head_t *head, * @head: the head of the list. * @node: the entry to test. */ -static inline bool +static inline bfdev_bool bfdev_list_check_first(const bfdev_list_head_t *head, const bfdev_list_head_t *node) { @@ -163,7 +163,7 @@ bfdev_list_check_first(const bfdev_list_head_t *head, * @head: the head of the list. * @node: the entry to test. */ -static inline bool +static inline bfdev_bool bfdev_list_check_end(const bfdev_list_head_t *head, const bfdev_list_head_t *node) { @@ -175,7 +175,7 @@ bfdev_list_check_end(const bfdev_list_head_t *head, * @head: list head to check. * @node: the unique node. */ -static inline bool +static inline bfdev_bool bfdev_list_check_another(const bfdev_list_head_t *head, const bfdev_list_head_t *node) { @@ -393,7 +393,7 @@ bfdev_list_splice_tail_init(bfdev_list_head_t *head, bfdev_list_head_t *list) #define bfdev_list_first_entry_or_null(ptr, type, member) ({ \ bfdev_list_head_t *__head = (ptr); \ bfdev_list_head_t *__pos = __head->next; \ - __pos != __head ? bfdev_list_entry(__pos, type, member) : NULL; \ + __pos != __head ? bfdev_list_entry(__pos, type, member) : BFDEV_NULL; \ }) /** @@ -405,7 +405,7 @@ bfdev_list_splice_tail_init(bfdev_list_head_t *head, bfdev_list_head_t *list) #define bfdev_list_last_entry_or_null(ptr, type, member) ({ \ bfdev_list_head_t *__head = (ptr); \ bfdev_list_head_t *__pos = __head->prev; \ - __pos != __head ? bfdev_list_entry(__pos, type, member) : NULL; \ + __pos != __head ? bfdev_list_entry(__pos, type, member) : BFDEV_NULL; \ }) /** @@ -417,7 +417,7 @@ bfdev_list_splice_tail_init(bfdev_list_head_t *head, bfdev_list_head_t *list) #define bfdev_list_next_entry_or_null(pos, head, member) ({ \ typeof(*(pos)) *__pos; \ __pos = bfdev_list_entry((pos)->member.next, typeof(*(pos)), member); \ - bfdev_list_entry_check_head(__pos, head, member) ? NULL : __pos; \ + bfdev_list_entry_check_head(__pos, head, member) ? BFDEV_NULL : __pos; \ }) /** @@ -429,7 +429,7 @@ bfdev_list_splice_tail_init(bfdev_list_head_t *head, bfdev_list_head_t *list) #define bfdev_list_prev_entry_or_null(pos, head, member) ({ \ typeof(*(pos)) *__pos; \ __pos = bfdev_list_entry((pos)->member.prev, typeof(*(pos)), member); \ - bfdev_list_entry_check_head(__pos, head, member) ? NULL : __pos; \ + bfdev_list_entry_check_head(__pos, head, member) ? BFDEV_NULL : __pos; \ }) /** diff --git a/include/bfdev/llist.h b/include/bfdev/llist.h index 638f98d9..9dae6bc5 100644 --- a/include/bfdev/llist.h +++ b/include/bfdev/llist.h @@ -21,7 +21,7 @@ BFDEV_BEGIN_DECLS * * Return whether list is empty before adding. */ -extern bool +extern bfdev_bool bfdev_llist_split(bfdev_slist_head_t *head, bfdev_slist_head_t *node, bfdev_slist_head_t *end); @@ -39,7 +39,7 @@ bfdev_llist_del(bfdev_slist_head_t *head); * * Return whether list is empty before adding. */ -static inline bool +static inline bfdev_bool bfdev_llist_add(bfdev_slist_head_t *head, bfdev_slist_head_t *node) { return bfdev_llist_split(head, node, node); @@ -52,7 +52,8 @@ bfdev_llist_add(bfdev_slist_head_t *head, bfdev_slist_head_t *node) static inline bfdev_slist_head_t * bfdev_llist_destroy(bfdev_slist_head_t *head) { - return (void *)bfdev_xchg((bfdev_atomic_t *)&head->next, (bfdev_atomic_t)NULL); + return (void *)bfdev_xchg((bfdev_atomic_t *)&head->next, + (bfdev_atomic_t)BFDEV_NULL); } BFDEV_END_DECLS diff --git a/include/bfdev/log.h b/include/bfdev/log.h index 91971561..54320576 100644 --- a/include/bfdev/log.h +++ b/include/bfdev/log.h @@ -50,7 +50,7 @@ struct bfdev_log { struct bfdev_log_message { unsigned int level; char *buff; - size_t length; + bfdev_size_t length; }; #define BFDEV_LOG_STATIC(HEAD, DEFAULT, RECORD, FLAGS, WRITE, PDATA) { \ @@ -90,7 +90,7 @@ extern unsigned int bfdev_log_level(const char *str, const char **endptr); extern __bfdev_printf(2, 0) int -bfdev_vlog_core(bfdev_log_t *log, const char *fmt, va_list args); +bfdev_vlog_core(bfdev_log_t *log, const char *fmt, bfdev_va_list args); extern __bfdev_printf(2, 3) int bfdev_log_core(bfdev_log_t *log, const char *fmt, ...); @@ -113,7 +113,7 @@ bfdev_log_core(bfdev_log_t *log, const char *fmt, ...); #endif #ifndef bfdev_log_conf -# define bfdev_log_conf NULL +# define bfdev_log_conf BFDEV_NULL #endif #define bfdev_vlog(fmt, args) \ diff --git a/include/bfdev/log2.h b/include/bfdev/log2.h index cd4cc4f8..6e8fbf43 100644 --- a/include/bfdev/log2.h +++ b/include/bfdev/log2.h @@ -101,7 +101,7 @@ bfdev_ilog2_dynamic(unsigned long value) * @value: dynamic 64-bit value to log base 2. */ static inline __bfdev_attribute_const unsigned int -bfdev_ilog2_64_dynamic(uint64_t value) +bfdev_ilog2_64_dynamic(bfdev_u64 value) { if (value < 2) return 0; @@ -139,7 +139,7 @@ bfdev_pow2_rounddown_dynamic(unsigned long value) * bfdev_pow2_check - check if a value is a power of two. * @value: the value to check. */ -static inline bool +static inline bfdev_bool bfdev_pow2_check(unsigned long value) { return value != 0 && ((value & (value - 1)) == 0); diff --git a/include/bfdev/math.h b/include/bfdev/math.h index 8de107cf..899df358 100644 --- a/include/bfdev/math.h +++ b/include/bfdev/math.h @@ -80,14 +80,14 @@ BFDEV_BEGIN_DECLS * @var2: the second argument. */ #define bfdev_abs_diff(var1, var2) ({ \ - typeof(var1) __var1, __var2; \ + typeof(var1) __var1, __var2; \ \ __var1 = (typeof(var1))(var1); \ __var2 = (typeof(var1))(var2); \ \ - __var1 > __var2 \ + __var1 > __var2 \ ? (__var1 - __var2) \ - : (__var2 - __var1); \ + : (__var2 - __var1); \ }) /** diff --git a/include/bfdev/md5.h b/include/bfdev/md5.h index 773d40f4..18ff708d 100644 --- a/include/bfdev/md5.h +++ b/include/bfdev/md5.h @@ -24,13 +24,13 @@ BFDEV_BEGIN_DECLS typedef struct bfdev_md5_ctx bfdev_md5_ctx_t; struct bfdev_md5_ctx { - uint32_t digest[BFDEV_MD5_HASH_WORDS]; - uint32_t block[BFDEV_MD5_BLOCK_WORDS]; - unsigned long count; + bfdev_u32 digest[BFDEV_MD5_HASH_WORDS]; + bfdev_u32 block[BFDEV_MD5_BLOCK_WORDS]; + unsigned long count; }; extern void -bfdev_md5_update(bfdev_md5_ctx_t *ctx, const char *data, size_t size); +bfdev_md5_update(bfdev_md5_ctx_t *ctx, const char *data, bfdev_size_t size); extern void bfdev_md5_finish(bfdev_md5_ctx_t *ctx, void *hash); diff --git a/include/bfdev/memalloc.h b/include/bfdev/memalloc.h index 9201a88f..c5d36b80 100644 --- a/include/bfdev/memalloc.h +++ b/include/bfdev/memalloc.h @@ -19,19 +19,19 @@ typedef struct bfdev_memalloc_head bfdev_memalloc_head_t; typedef struct bfdev_memalloc_chunk bfdev_memalloc_chunk_t; typedef bfdev_memalloc_chunk_t * -(*bfdev_memalloc_find_t)(bfdev_memalloc_head_t *head, size_t size); +(*bfdev_memalloc_find_t)(bfdev_memalloc_head_t *head, bfdev_size_t size); struct bfdev_memalloc_head { bfdev_list_head_t block_list; bfdev_list_head_t free_list; bfdev_memalloc_find_t find; - size_t avail; + bfdev_size_t avail; }; struct bfdev_memalloc_chunk { bfdev_list_head_t block; bfdev_list_head_t free; - size_t usize; + bfdev_size_t usize; char data[0]; }; @@ -41,7 +41,7 @@ struct bfdev_memalloc_chunk { * @size: size to get. */ extern bfdev_memalloc_chunk_t * -bfdev_memalloc_first_fit(bfdev_memalloc_head_t *head, size_t size); +bfdev_memalloc_first_fit(bfdev_memalloc_head_t *head, bfdev_size_t size); /** * bfdev_memalloc_best_fit() - best qualified node. @@ -49,7 +49,7 @@ bfdev_memalloc_first_fit(bfdev_memalloc_head_t *head, size_t size); * @size: size to get. */ extern bfdev_memalloc_chunk_t * -bfdev_memalloc_best_fit(bfdev_memalloc_head_t *head, size_t size); +bfdev_memalloc_best_fit(bfdev_memalloc_head_t *head, bfdev_size_t size); /** * bfdev_memalloc_worst_fit() - worst qualified node. @@ -57,7 +57,7 @@ bfdev_memalloc_best_fit(bfdev_memalloc_head_t *head, size_t size); * @size: size to get. */ extern bfdev_memalloc_chunk_t * -bfdev_memalloc_worst_fit(bfdev_memalloc_head_t *head, size_t size); +bfdev_memalloc_worst_fit(bfdev_memalloc_head_t *head, bfdev_size_t size); /** * bfdev_memalloc_alloc() - memory allocator allocation. @@ -65,7 +65,7 @@ bfdev_memalloc_worst_fit(bfdev_memalloc_head_t *head, size_t size); * @size: size to allocation. */ extern void __bfdev_malloc * -bfdev_memalloc_alloc(bfdev_memalloc_head_t *head, size_t size); +bfdev_memalloc_alloc(bfdev_memalloc_head_t *head, bfdev_size_t size); /** * bfdev_memalloc_free() - memory allocator release. @@ -82,7 +82,8 @@ bfdev_memalloc_free(bfdev_memalloc_head_t *head, void *block); * @resize: size to realloc. */ extern void __bfdev_malloc * -bfdev_memalloc_realloc(bfdev_memalloc_head_t *head, void *block, size_t resize); +bfdev_memalloc_realloc(bfdev_memalloc_head_t *head, + void *block, bfdev_size_t resize); /** * bfdev_memalloc_init() - memory allocator setup. @@ -93,7 +94,7 @@ bfdev_memalloc_realloc(bfdev_memalloc_head_t *head, void *block, size_t resize); */ extern void bfdev_memalloc_init(bfdev_memalloc_head_t *head, bfdev_memalloc_find_t find, - void *memory, size_t size); + void *memory, bfdev_size_t size); BFDEV_END_DECLS diff --git a/include/bfdev/mpi.h b/include/bfdev/mpi.h index 6861c4b6..f4ddfab0 100644 --- a/include/bfdev/mpi.h +++ b/include/bfdev/mpi.h @@ -24,11 +24,11 @@ typedef struct bfdev_mpi bfdev_mpi_t; struct bfdev_mpi { const bfdev_alloc_t *alloc; bfdev_array_t value; - bool plus; + bfdev_bool plus; }; #define BFDEV_MPI_STATIC(ALLOC) { \ - .alloc = (ALLOC), .plus = true, \ + .alloc = (ALLOC), .plus = bfdev_true, \ .value = BFDEV_ARRAY_STATIC(ALLOC, BFDEV_MPI_SIZE), \ } @@ -50,7 +50,7 @@ bfdev_mpi_length(const bfdev_mpi_t *mpi) return bfdev_array_index(&mpi->value); } -static inline size_t +static inline bfdev_size_t bfdev_mpi_size(const bfdev_mpi_t *mpi) { return bfdev_array_size(&mpi->value); @@ -122,7 +122,7 @@ extern int bfdev_mpi_shri(bfdev_mpi_t *dest, const bfdev_mpi_t *va, BFDEV_MPI_TYPE shift); -extern bool +extern bfdev_bool bfdev_mpi_btesti(bfdev_mpi_t *dest, BFDEV_MPI_TYPE bit); extern int @@ -139,10 +139,10 @@ bfdev_mpi_set(bfdev_mpi_t *dest, const bfdev_mpi_t *src); extern int bfdev_mpi_import(bfdev_mpi_t *var, const BFDEV_MPI_TYPE *buffer, - unsigned long length, bool sign); + unsigned long length, bfdev_bool sign); extern const BFDEV_MPI_TYPE * -bfdev_mpi_data(const bfdev_mpi_t *var, bool *sign); +bfdev_mpi_data(const bfdev_mpi_t *var, bfdev_bool *sign); extern void bfdev_mpi_release(bfdev_mpi_t *var); diff --git a/include/bfdev/once.h b/include/bfdev/once.h index d70a9032..8322b1cc 100644 --- a/include/bfdev/once.h +++ b/include/bfdev/once.h @@ -13,27 +13,27 @@ BFDEV_BEGIN_DECLS #define BFDEV_DO_ONCE_DONE(condition) ({ \ - static bool __already; \ - bool ___cond = !!(condition); \ - bool __retval = false; \ + static bfdev_bool __already; \ + bfdev_bool ___cond = !!(condition); \ + bfdev_bool __retval = bfdev_false; \ \ if (bfdev_unlikely(___cond && !__already)) { \ - __already = true; \ - __retval = true; \ + __already = bfdev_true; \ + __retval = bfdev_true; \ } \ \ bfdev_unlikely(__retval); \ }) #define BFDEV_DO_ONCE_ON(condition, func, ...) ({ \ - bool __cond = !!(condition); \ + bfdev_bool __cond = !!(condition); \ if (BFDEV_DO_ONCE_DONE(__cond)) \ func(__VA_ARGS__); \ bfdev_unlikely(__cond); \ }) #define BFDEV_DO_ONCE(func, ...) \ - BFDEV_DO_ONCE_ON(true, func, ##__VA_ARGS__) + BFDEV_DO_ONCE_ON(bfdev_true, func, ##__VA_ARGS__) BFDEV_END_DECLS diff --git a/include/bfdev/overflow.h b/include/bfdev/overflow.h index 2928f4d7..3523b00b 100644 --- a/include/bfdev/overflow.h +++ b/include/bfdev/overflow.h @@ -90,8 +90,8 @@ bfdev_overflow_check(({ \ ? (type)~0ULL : __d; \ }) -static inline __bfdev_must_check bool -bfdev_overflow_check(bool overflow) +static inline __bfdev_must_check bfdev_bool +bfdev_overflow_check(bfdev_bool overflow) { return bfdev_unlikely(overflow); } @@ -145,15 +145,15 @@ bfdev_overflow_mul_##name(type a, type b) \ return bfdev_overflow_mul_type(type, a, b); \ } -BFDEV_GENERIC_OVERFLOW_OPS(s8, int8_t) -BFDEV_GENERIC_OVERFLOW_OPS(s16, int16_t) -BFDEV_GENERIC_OVERFLOW_OPS(s32, int32_t) -BFDEV_GENERIC_OVERFLOW_OPS(s64, int64_t) +BFDEV_GENERIC_OVERFLOW_OPS(s8, bfdev_s8) +BFDEV_GENERIC_OVERFLOW_OPS(s16, bfdev_s16) +BFDEV_GENERIC_OVERFLOW_OPS(s32, bfdev_s32) +BFDEV_GENERIC_OVERFLOW_OPS(s64, bfdev_s64) -BFDEV_GENERIC_OVERFLOW_OPS(u8, uint8_t) -BFDEV_GENERIC_OVERFLOW_OPS(u16, uint16_t) -BFDEV_GENERIC_OVERFLOW_OPS(u32, uint32_t) -BFDEV_GENERIC_OVERFLOW_OPS(u64, uint64_t) +BFDEV_GENERIC_OVERFLOW_OPS(u8, bfdev_u8) +BFDEV_GENERIC_OVERFLOW_OPS(u16, bfdev_u16) +BFDEV_GENERIC_OVERFLOW_OPS(u32, bfdev_u32) +BFDEV_GENERIC_OVERFLOW_OPS(u64, bfdev_u64) BFDEV_END_DECLS diff --git a/include/bfdev/popcount.h b/include/bfdev/popcount.h index 38e4b296..e2a318fd 100644 --- a/include/bfdev/popcount.h +++ b/include/bfdev/popcount.h @@ -17,7 +17,7 @@ BFDEV_BEGIN_DECLS */ static __bfdev_attribute_const __bfdev_always_inline -unsigned int bfdev_popcount8_const(uint8_t value) +unsigned int bfdev_popcount8_const(bfdev_u8 value) { value = (value & 0x55) + ((value >> 1) & 0x55); value = (value & 0x33) + ((value >> 2) & 0x33); @@ -26,7 +26,7 @@ unsigned int bfdev_popcount8_const(uint8_t value) } static __bfdev_attribute_const __bfdev_always_inline -unsigned int bfdev_popcount16_const(uint16_t value) +unsigned int bfdev_popcount16_const(bfdev_u16 value) { value = (value & 0x5555) + ((value >> 1) & 0x5555); value = (value & 0x3333) + ((value >> 2) & 0x3333); @@ -36,7 +36,7 @@ unsigned int bfdev_popcount16_const(uint16_t value) } static __bfdev_attribute_const __bfdev_always_inline -unsigned int bfdev_popcount32_const(uint32_t value) +unsigned int bfdev_popcount32_const(bfdev_u32 value) { value = (value & 0x55555555UL) + ((value >> 1) & 0x55555555); value = (value & 0x33333333UL) + ((value >> 2) & 0x33333333); @@ -47,7 +47,7 @@ unsigned int bfdev_popcount32_const(uint32_t value) } static __bfdev_attribute_const __bfdev_always_inline -unsigned int bfdev_popcount64_const(uint64_t value) +unsigned int bfdev_popcount64_const(bfdev_u64 value) { value = (value & 0x5555555555555555ULL) + ((value >> 1) & 0x5555555555555555ULL); value = (value & 0x3333333333333333ULL) + ((value >> 2) & 0x3333333333333333ULL); @@ -59,7 +59,7 @@ unsigned int bfdev_popcount64_const(uint64_t value) } static __bfdev_attribute_const __bfdev_always_inline -bool bfdev_popparity8_const(uint8_t value) +bfdev_bool bfdev_popparity8_const(bfdev_u8 value) { value ^= value >> 4; value &= 0xf; @@ -67,7 +67,7 @@ bool bfdev_popparity8_const(uint8_t value) } static __bfdev_attribute_const __bfdev_always_inline -bool bfdev_popparity16_const(uint16_t value) +bfdev_bool bfdev_popparity16_const(bfdev_u16 value) { value ^= value >> 8; value ^= value >> 4; @@ -76,7 +76,7 @@ bool bfdev_popparity16_const(uint16_t value) } static __bfdev_attribute_const __bfdev_always_inline -bool bfdev_popparity32_const(uint32_t value) +bfdev_bool bfdev_popparity32_const(bfdev_u32 value) { value ^= value >> 16; value ^= value >> 8; @@ -86,7 +86,7 @@ bool bfdev_popparity32_const(uint32_t value) } static __bfdev_attribute_const __bfdev_always_inline -bool bfdev_popparity64_const(uint64_t value) +bfdev_bool bfdev_popparity64_const(bfdev_u64 value) { value ^= value >> 32; value ^= value >> 16; @@ -100,69 +100,69 @@ bool bfdev_popparity64_const(uint64_t value) * Interface for known dynamic arguments */ -extern const uint8_t +extern const bfdev_u8 bfdev_popcount_table[256]; -extern const bool +extern const bfdev_bool bfdev_popparity_table[256]; static inline __bfdev_attribute_const -unsigned int bfdev_popcount8_dynamic(uint8_t value) +unsigned int bfdev_popcount8_dynamic(bfdev_u8 value) { return bfdev_popcount_table[value]; } static inline __bfdev_attribute_const -unsigned int bfdev_popcount16_dynamic(uint16_t value) +unsigned int bfdev_popcount16_dynamic(bfdev_u16 value) { - uint8_t high = value >> 8; + bfdev_u8 high = value >> 8; return bfdev_popcount8_dynamic(high) + - bfdev_popcount8_dynamic((uint8_t)value); + bfdev_popcount8_dynamic((bfdev_u8)value); } static inline __bfdev_attribute_const -unsigned int bfdev_popcount32_dynamic(uint32_t value) +unsigned int bfdev_popcount32_dynamic(bfdev_u32 value) { - uint16_t high = value >> 16; + bfdev_u16 high = value >> 16; return bfdev_popcount16_dynamic(high) + - bfdev_popcount16_dynamic((uint16_t)value); + bfdev_popcount16_dynamic((bfdev_u16)value); } static inline __bfdev_attribute_const -unsigned int bfdev_popcount64_dynamic(uint64_t value) +unsigned int bfdev_popcount64_dynamic(bfdev_u64 value) { - uint32_t high = value >> 32; + bfdev_u32 high = value >> 32; return bfdev_popcount32_dynamic(high) + - bfdev_popcount32_dynamic((uint32_t)value); + bfdev_popcount32_dynamic((bfdev_u32)value); } static inline __bfdev_attribute_const -bool bfdev_popparity8_dynamic(uint8_t value) +bfdev_bool bfdev_popparity8_dynamic(bfdev_u8 value) { return bfdev_popparity_table[value]; } static inline __bfdev_attribute_const -bool bfdev_popparity16_dynamic(uint16_t value) +bfdev_bool bfdev_popparity16_dynamic(bfdev_u16 value) { - uint8_t high = value >> 8; - return (bfdev_popparity8_dynamic((uint8_t)value) + + bfdev_u8 high = value >> 8; + return (bfdev_popparity8_dynamic((bfdev_u8)value) + bfdev_popparity8_dynamic(high)) & 1; } static inline __bfdev_attribute_const -bool bfdev_popparity32_dynamic(uint32_t value) +bfdev_bool bfdev_popparity32_dynamic(bfdev_u32 value) { - uint16_t high = value >> 16; - return (bfdev_popparity16_dynamic((uint16_t)value) + + bfdev_u16 high = value >> 16; + return (bfdev_popparity16_dynamic((bfdev_u16)value) + bfdev_popparity16_dynamic(high)) & 1; } static inline __bfdev_attribute_const -bool bfdev_popparity64_dynamic(uint64_t value) +bfdev_bool bfdev_popparity64_dynamic(bfdev_u64 value) { - uint32_t high = value >> 32; - return (bfdev_popparity32_dynamic((uint32_t)value) + + bfdev_u32 high = value >> 32; + return (bfdev_popparity32_dynamic((bfdev_u32)value) + bfdev_popparity32_dynamic(high)) & 1; } @@ -173,28 +173,28 @@ bool bfdev_popparity64_dynamic(uint64_t value) * Returns the number of 1-bits in x. */ #define bfdev_popcount8(value) ({ \ - uint8_t __value = (value); \ + bfdev_u8 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popcount8_const(__value) \ : bfdev_popcount8_dynamic(__value); \ }) #define bfdev_popcount16(value) ({ \ - uint16_t __value = (value); \ + bfdev_u16 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popcount16_const(__value) \ : bfdev_popcount16_dynamic(__value); \ }) #define bfdev_popcount32(value) ({ \ - uint32_t __value = (value); \ + bfdev_u32 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popcount32_const(__value) \ : bfdev_popcount32_dynamic(__value); \ }) #define bfdev_popcount64(value) ({ \ - uint64_t __value = (value); \ + bfdev_u64 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popcount64_const(__value) \ : bfdev_popcount64_dynamic(__value); \ @@ -207,28 +207,28 @@ bool bfdev_popparity64_dynamic(uint64_t value) * Returns the parity of x, i.e. the number of 1-bits in x modulo 2. */ #define bfdev_popparity8(value) ({ \ - uint8_t __value = (value); \ + bfdev_u8 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popparity8_const(__value) \ : bfdev_popparity8_dynamic(__value); \ }) #define bfdev_popparity16(value) ({ \ - uint16_t __value = (value); \ + bfdev_u16 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popparity16_const(__value) \ : bfdev_popparity16_dynamic(__value); \ }) #define bfdev_popparity32(value) ({ \ - uint32_t __value = (value); \ + bfdev_u32 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popparity32_const(__value) \ : bfdev_popparity32_dynamic(__value); \ }) #define bfdev_popparity64(value) ({ \ - uint64_t __value = (value); \ + bfdev_u64 __value = (value); \ __builtin_constant_p(__value) \ ? bfdev_popparity64_const(__value) \ : bfdev_popparity64_dynamic(__value); \ diff --git a/include/bfdev/port/ctype.h b/include/bfdev/port/ctype.h deleted file mode 100644 index 883cc24f..00000000 --- a/include/bfdev/port/ctype.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * Copyright(c) 2023 John Sanpe - */ - -#ifndef _BFDEV_PORT_CTYPE_H_ -#define _BFDEV_PORT_CTYPE_H_ - -#include - -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include -#endif - -BFDEV_BEGIN_DECLS - -BFDEV_END_DECLS - -#endif /* _BFDEV_PORT_CTYPE_H_ */ diff --git a/include/bfdev/port/limits.h b/include/bfdev/port/limits.h deleted file mode 100644 index d8a1351c..00000000 --- a/include/bfdev/port/limits.h +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * Copyright(c) 2023 John Sanpe - */ - -#ifndef _BFDEV_PORT_LIMITS_H_ -#define _BFDEV_PORT_LIMITS_H_ - -#include - -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -# include -#else -# include -#endif - -BFDEV_BEGIN_DECLS - -BFDEV_END_DECLS - -#endif /* _BFDEV_PORT_LIMITS_H_ */ diff --git a/include/bfdev/port/stdarg.h b/include/bfdev/port/stdarg.h index aa8103d6..7a8efdbb 100644 --- a/include/bfdev/port/stdarg.h +++ b/include/bfdev/port/stdarg.h @@ -8,14 +8,14 @@ #include -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include -#endif - BFDEV_BEGIN_DECLS +typedef __builtin_va_list bfdev_va_list; +#define bfdev_va_start(v, l) __builtin_va_start(v, l) +#define bfdev_va_arg(v, l) __builtin_va_arg(v, l) +#define bfdev_va_end(v) __builtin_va_end(v) +#define bfdev_va_copy(d, s) __builtin_va_copy(d, s) + BFDEV_END_DECLS #endif /* _BFDEV_PORT_STDARG_H_ */ diff --git a/include/bfdev/port/stdbool.h b/include/bfdev/port/stdbool.h index 63026efe..0a851553 100644 --- a/include/bfdev/port/stdbool.h +++ b/include/bfdev/port/stdbool.h @@ -8,14 +8,16 @@ #include -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include -#endif - BFDEV_BEGIN_DECLS +/* C language standard type */ +typedef _Bool bfdev_bool; + +enum bfdev_bool { + bfdev_false = 0, + bfdev_true = 1, +}; + BFDEV_END_DECLS #endif /* _BFDEV_PORT_STDBOOL_H_ */ diff --git a/include/bfdev/port/stddef.h b/include/bfdev/port/stddef.h index cb9d6460..c33d2864 100644 --- a/include/bfdev/port/stddef.h +++ b/include/bfdev/port/stddef.h @@ -8,13 +8,19 @@ #include -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include +BFDEV_BEGIN_DECLS + +#ifndef BFDEV_NULL +# define BFDEV_NULL ((void *)0) #endif -BFDEV_BEGIN_DECLS +#if __GNUC__ > 3 +#define bfdev_offsetof(type, member) \ + __builtin_offsetof(type, member) +#else +#define bfdev_offsetof(type, member) \ + ((unsigned long)((char *)&(((type *)0)->member) - (char *)0)) +#endif BFDEV_END_DECLS diff --git a/include/bfdev/port/stdint.h b/include/bfdev/port/stdint.h deleted file mode 100644 index 470d33a4..00000000 --- a/include/bfdev/port/stdint.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * Copyright(c) 2023 John Sanpe - */ - -#ifndef _BFDEV_PORT_STDINT_H_ -#define _BFDEV_PORT_STDINT_H_ - -#include - -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include -#endif - -BFDEV_BEGIN_DECLS - -BFDEV_END_DECLS - -#endif /* _BFDEV_PORT_STDINT_H_ */ diff --git a/include/bfdev/port/stdio.h b/include/bfdev/port/stdio.h deleted file mode 100644 index 6f288eb7..00000000 --- a/include/bfdev/port/stdio.h +++ /dev/null @@ -1,62 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * Copyright(c) 2023 John Sanpe - */ - -#ifndef _BFDEV_PORT_STDIO_H_ -#define _BFDEV_PORT_STDIO_H_ - -#include - -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include -#endif - -BFDEV_BEGIN_DECLS - -#ifndef bfport_file -# define bfport_file FILE -#endif - -#ifndef bfport_stdout -# define bfport_stdout stdout -#endif - -#ifndef bfport_stderr -# define bfport_stderr stderr -#endif - -#ifndef bfport_fwrite -# define bfport_fwrite bfport_fwrite -static __bfdev_always_inline unsigned long -bfport_fwrite(const void *restrict ptr, size_t size, - size_t n, FILE *restrict stream) -{ - return fwrite(ptr, size, n, stream); -} -#endif - -#ifndef bfport_fflush -# define bfport_fflush bfport_fflush -static __bfdev_always_inline int -bfport_fflush(FILE *restrict stream) -{ - return fflush(stream); -} -#endif - -#ifndef bfport_vsnprintf -# define bfport_vsnprintf bfport_vsnprintf -static __bfdev_always_inline int -bfport_vsnprintf(char *restrict s, size_t maxlen, - const char *restrict format, va_list arg) -{ - return vsnprintf(s, maxlen, format, arg); -} -#endif - -BFDEV_END_DECLS - -#endif /* _BFDEV_PORT_STDIO_H_ */ diff --git a/include/bfdev/port/stdlib.h b/include/bfdev/port/stdlib.h index 466d1267..4090bdde 100644 --- a/include/bfdev/port/stdlib.h +++ b/include/bfdev/port/stdlib.h @@ -8,58 +8,10 @@ #include -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include -#endif - BFDEV_BEGIN_DECLS -#ifndef bfport_rand -# define bfport_rand bfport_rand -static __bfdev_always_inline int -bfport_rand(void) -{ - return rand(); -} -#endif - -#ifndef bfport_malloc -# define bfport_malloc bfport_malloc -static __bfdev_always_inline __bfdev_malloc void * -bfport_malloc(size_t size) -{ - return malloc(size); -} -#endif - -#ifndef bfport_calloc -# define bfport_calloc bfport_calloc -static __bfdev_always_inline __bfdev_malloc void * -bfport_calloc(size_t nmemb, size_t size) -{ - return calloc(nmemb, size); -} -#endif - -#ifndef bfport_realloc -# define bfport_realloc bfport_realloc -static __bfdev_always_inline __bfdev_malloc void * -bfport_realloc(void *ptr, size_t size) -{ - return realloc(ptr, size); -} -#endif - -#ifndef bfport_free -# define bfport_free bfport_free -static __bfdev_always_inline void -bfport_free(void *ptr) -{ - free(ptr); -} -#endif +extern __bfdev_noreturn void +bfdev_abort(void); BFDEV_END_DECLS diff --git a/include/bfdev/port/string.h b/include/bfdev/port/string.h index 155bdd32..fd100bbb 100644 --- a/include/bfdev/port/string.h +++ b/include/bfdev/port/string.h @@ -7,113 +7,42 @@ #define _BFDEV_PORT_STRING_H_ #include - -#if defined(__FreeBSD__) && defined(_KERNEL) -# include -#else -# include -#endif +#include BFDEV_BEGIN_DECLS -#ifndef bfport_memcpy -# define bfport_memcpy bfport_memcpy -static __bfdev_always_inline void * -bfport_memcpy(void *restrict dest, const void *restrict src, size_t n) -{ - return memcpy(dest, src, n); -} -#endif - -#ifndef bfport_memset -# define bfport_memset bfport_memset -static __bfdev_always_inline void * -bfport_memset(void *s, int c, size_t n) -{ - return memset(s, c, n); -} -#endif - -#ifndef bfport_memcmp -# define bfport_memcmp bfport_memcmp -static __bfdev_always_inline int -bfport_memcmp(const void *s1, const void *s2, size_t n) -{ - return memcmp(s1, s2, n); -} -#endif - -#ifndef bfport_strcmp -# define bfport_strcmp bfport_strcmp -static __bfdev_always_inline int -bfport_strcmp(const char *s1, const char *s2) -{ - return strcmp(s1, s2); -} -#endif - -#ifndef bfport_strchr -# define bfport_strchr bfport_strchr -static __bfdev_always_inline char * -bfport_strchr(const char *s, int c) -{ - return strchr(s, c); -} -#endif - -#ifndef bfport_strspn -# define bfport_strspn bfport_strspn -static __bfdev_always_inline size_t -bfport_strspn(const char *s, const char *accept) -{ - return strspn(s, accept); -} -#endif - -#ifndef bfport_strcspn -# define bfport_strcspn bfport_strcspn -static __bfdev_always_inline size_t -bfport_strcspn(const char *s, const char *reject) -{ - return strcspn(s, reject); -} -#endif - -#ifndef bfport_strcpy -# define bfport_strcpy bfport_strcpy -static __bfdev_always_inline char * -bfport_strcpy(char *restrict dest, const char *restrict src) -{ - return strcpy(dest, src); -} -#endif - -#ifndef bfport_strncpy -# define bfport_strncpy bfport_strncpy -static __bfdev_always_inline char * -bfport_strncpy(char *restrict dest, const char *restrict src, size_t n) -{ - return strncpy(dest, src, n); -} -#endif - -#ifndef bfport_strlen -# define bfport_strlen bfport_strlen -static __bfdev_always_inline size_t -bfport_strlen(const char *s) -{ - return strlen(s); -} -#endif - -#ifndef bfport_strnlen -# define bfport_strnlen bfport_strnlen -static __bfdev_always_inline size_t -bfport_strnlen(const char *s, size_t len) -{ - return strnlen(s, len); -} -#endif +extern void * +bfdev_memcpy(void *dest, const void *src, bfdev_size_t n); + +extern void * +bfdev_memset(void *s, int c, bfdev_size_t n); + +extern int +bfdev_memcmp(const void *s1, const void *s2, bfdev_size_t n); + +extern int +bfdev_strcmp(const char *s1, const char *s2); + +extern char * +bfdev_strchr(const char *s, int c); + +extern bfdev_size_t +bfdev_strspn(const char *s, const char *accept); + +extern bfdev_size_t +bfdev_strcspn(const char *s, const char *reject); + +extern char * +bfdev_strcpy(char *dest, const char *src); + +extern char * +bfdev_strncpy(char *dest, const char *src, bfdev_size_t n); + +extern bfdev_size_t +bfdev_strlen(const char *s); + +extern bfdev_size_t +bfdev_strnlen(const char *s, bfdev_size_t len); BFDEV_END_DECLS diff --git a/include/bfdev/prandom.h b/include/bfdev/prandom.h index c241b1eb..3e696a60 100644 --- a/include/bfdev/prandom.h +++ b/include/bfdev/prandom.h @@ -24,8 +24,10 @@ BFDEV_BEGIN_DECLS typedef struct bfdev_prandom bfdev_prandom_t; struct bfdev_prandom { - uint32_t s1, s2; - uint32_t s3, s4; + bfdev_u32 s1; + bfdev_u32 s2; + bfdev_u32 s3; + bfdev_u32 s4; }; #define BFDEV_PRANDOM_STATIC() { \ @@ -57,24 +59,24 @@ bfdev_prandom_init(bfdev_prandom_t *pstate) * @seed: arbitrary 64-bit value to use as a seed. */ extern void -bfdev_prandom_seed(bfdev_prandom_t *pstate, uint64_t seed); +bfdev_prandom_seed(bfdev_prandom_t *pstate, bfdev_u64 seed); /** * bfdev_prandom_value() - seeded pseudo-random number generator. * @state: pointer to state structure holding seeded state. */ -extern uint32_t +extern bfdev_u32 bfdev_prandom_value(bfdev_prandom_t *pstate); -static inline uint64_t +static inline bfdev_u64 bfdev_prandom_u64(bfdev_prandom_t *pstate) { - uint32_t high, low; + bfdev_u32 high, low; high = bfdev_prandom_value(pstate); low = bfdev_prandom_value(pstate); - return ((uint64_t)high << 32) | low; + return ((bfdev_u64)high << 32) | low; } static inline unsigned long diff --git a/include/bfdev/radix.h b/include/bfdev/radix.h index 21655374..34aa5225 100644 --- a/include/bfdev/radix.h +++ b/include/bfdev/radix.h @@ -37,7 +37,7 @@ struct bfdev_radix_node { unsigned int refcount; }; struct { /* leaf */ - uint8_t block[BFDEV_RADIX_BLOCK]; + bfdev_u8 block[BFDEV_RADIX_BLOCK]; BFDEV_DEFINE_BITMAP(bitmap, BFDEV_RADIX_BLOCK); }; }; @@ -66,10 +66,10 @@ struct bfdev_radix_node { #define BFDEV_DEFINE_RADIX(name, type, alloc) \ BFDEV_DECLARE_RADIX(name, type) = BFDEV_RADIX_INIT(&name, alloc) -static inline uintptr_t -bfdev_radix_offset(uintptr_t index, size_t cells) +static inline bfdev_uintptr_t +bfdev_radix_offset(bfdev_uintptr_t index, bfdev_size_t cells) { - size_t num; + bfdev_size_t num; if (bfdev_pow2_check(cells)) return index * cells; @@ -80,10 +80,10 @@ bfdev_radix_offset(uintptr_t index, size_t cells) (index % num) * cells; } -static inline uintptr_t -bfdev_radix_index(uintptr_t offset, size_t cells) +static inline bfdev_uintptr_t +bfdev_radix_index(bfdev_uintptr_t offset, bfdev_size_t cells) { - size_t num; + bfdev_size_t num; if (bfdev_pow2_check(cells)) return offset / cells; @@ -151,7 +151,7 @@ bfdev_radix_index(uintptr_t offset, size_t cells) #define bfdev_radix_first(radix, index) ({ \ bfdev_radix_root_t *__root; \ - uintptr_t __off; \ + bfdev_uintptr_t __off; \ void *__retval; \ __root = &(radix)->tree; \ __retval = bfdev_radix_root_first(__root, &__off); \ @@ -161,7 +161,7 @@ bfdev_radix_index(uintptr_t offset, size_t cells) #define bfdev_radix_last(radix, index) ({ \ bfdev_radix_root_t *__root; \ - uintptr_t __off; \ + bfdev_uintptr_t __off; \ void *__retval; \ __root = &(radix)->tree; \ __retval = bfdev_radix_root_last(__root, &__off); \ @@ -171,7 +171,7 @@ bfdev_radix_index(uintptr_t offset, size_t cells) #define bfdev_radix_next(radix, index) ({ \ bfdev_radix_root_t *__root; \ - uintptr_t __off; \ + bfdev_uintptr_t __off; \ void *__retval; \ __root = &(radix)->tree; \ __off = bfdev_radix_to_offset(radix, *(index)); \ @@ -182,7 +182,7 @@ bfdev_radix_index(uintptr_t offset, size_t cells) #define bfdev_radix_prev(radix, index) ({ \ bfdev_radix_root_t *__root; \ - uintptr_t __off; \ + bfdev_uintptr_t __off; \ void *__retval; \ __root = &(radix)->tree; \ __off = bfdev_radix_to_offset(radix, *(index)); \ @@ -246,31 +246,32 @@ bfdev_radix_index(uintptr_t offset, size_t cells) ((tval) = bfdev_radix_prev(radix, tidx)))) extern void * -bfdev_radix_root_find(bfdev_radix_root_t *root, uintptr_t offset); +bfdev_radix_root_find(bfdev_radix_root_t *root, bfdev_uintptr_t offset); extern void * -bfdev_radix_root_alloc(bfdev_radix_root_t *root, uintptr_t offset); +bfdev_radix_root_alloc(bfdev_radix_root_t *root, bfdev_uintptr_t offset); extern int -bfdev_radix_root_free(bfdev_radix_root_t *root, uintptr_t offset); +bfdev_radix_root_free(bfdev_radix_root_t *root, bfdev_uintptr_t offset); extern int -bfdev_radix_root_charge(bfdev_radix_root_t *root, uintptr_t offset, size_t size); +bfdev_radix_root_charge(bfdev_radix_root_t *root, bfdev_uintptr_t offset, + bfdev_size_t size); extern void bfdev_radix_root_release(bfdev_radix_root_t *root); extern void * -bfdev_radix_root_first(bfdev_radix_root_t *root, uintptr_t *offsetp); +bfdev_radix_root_first(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp); extern void * -bfdev_radix_root_last(bfdev_radix_root_t *root, uintptr_t *offsetp); +bfdev_radix_root_last(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp); extern void * -bfdev_radix_root_next(bfdev_radix_root_t *root, uintptr_t *offsetp); +bfdev_radix_root_next(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp); extern void * -bfdev_radix_root_prev(bfdev_radix_root_t *root, uintptr_t *offsetp); +bfdev_radix_root_prev(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp); BFDEV_END_DECLS diff --git a/include/bfdev/ratelimit.h b/include/bfdev/ratelimit.h index 30e73b2f..68efe85b 100644 --- a/include/bfdev/ratelimit.h +++ b/include/bfdev/ratelimit.h @@ -65,7 +65,7 @@ bfdev_ratelimit_reset(bfdev_ratelimit_t *limit) * 0 means function will be suppressed. * 1 means go ahead and do it. */ -extern bool +extern bfdev_bool bfdev_ratelimit(bfdev_ratelimit_t *limit, bfdev_time_t current); BFDEV_END_DECLS diff --git a/include/bfdev/rbtree.h b/include/bfdev/rbtree.h index f8ef9fcc..92e5c733 100644 --- a/include/bfdev/rbtree.h +++ b/include/bfdev/rbtree.h @@ -28,7 +28,7 @@ struct bfdev_rb_node { bfdev_rb_node_t *parent; bfdev_rb_node_t *left; bfdev_rb_node_t *right; - bool color; + bfdev_bool color; }; struct bfdev_rb_root { @@ -47,12 +47,12 @@ struct bfdev_rb_callbacks { }; #define BFDEV_RB_STATIC() { \ - .node = NULL, \ + .node = BFDEV_NULL, \ } #define BFDEV_RB_CACHED_STATIC() { \ .root = BFDEV_RB_STATIC(), \ - .leftmost = NULL, \ + .leftmost = BFDEV_NULL, \ } #define BFDEV_RB_INIT() \ @@ -68,10 +68,10 @@ struct bfdev_rb_callbacks { bfdev_rb_root_cached_t name = BFDEV_RB_CACHED_INIT() #define BFDEV_RB_EMPTY_ROOT(root) \ - ((root)->node == NULL) + ((root)->node == BFDEV_NULL) #define BFDEV_RB_EMPTY_ROOT_CACHED(cached) \ - ((cached)->root.node == NULL) + ((cached)->root.node == BFDEV_NULL) /** * bfdev_rb_entry - get the struct for this entry. @@ -92,11 +92,11 @@ struct bfdev_rb_callbacks { bfdev_container_of_safe(ptr, type, member) #ifdef BFDEV_DEBUG_RBTREE -extern bool +extern bfdev_bool bfdev_rb_check_link(bfdev_rb_node_t *parent, bfdev_rb_node_t **link, bfdev_rb_node_t *node); -extern bool +extern bfdev_bool bfdev_rb_check_delete(bfdev_rb_node_t *node); #endif @@ -207,7 +207,7 @@ bfdev_rb_find(const bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find); extern bfdev_rb_node_t * bfdev_rb_find_last(bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find, bfdev_rb_node_t **parentp, bfdev_rb_node_t ***linkp, - bool *leftmostp); + bfdev_bool *leftmostp); /** * bfdev_rb_parent() - find the parent node. @@ -220,7 +220,7 @@ bfdev_rb_find_last(bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find, extern bfdev_rb_node_t ** bfdev_rb_parent(bfdev_rb_root_t *root, bfdev_rb_node_t **parentp, bfdev_rb_node_t *node, bfdev_rb_cmp_t cmp, void *pdata, - bool *leftmostp); + bfdev_bool *leftmostp); #define bfdev_rb_cached_erase_augmented(cached, parent, callbacks) \ bfdev_rb_erase_augmented(&(cached)->root, parent, callbacks) @@ -625,7 +625,7 @@ bfdev_rb_link(bfdev_rb_node_t *parent, bfdev_rb_node_t **link, bfdev_rb_node_t * *link = node; node->parent = parent; node->color = BFDEV_RB_RED; - node->left = node->right = NULL; + node->left = node->right = BFDEV_NULL; } /** @@ -649,18 +649,18 @@ bfdev_rb_insert_node(bfdev_rb_root_t *root, bfdev_rb_node_t *parent, * @node: new node to insert. * @cmp: operator defining the node order. */ -static inline bool +static inline bfdev_bool bfdev_rb_insert(bfdev_rb_root_t *root, bfdev_rb_node_t *node, bfdev_rb_cmp_t cmp, void *pdata) { bfdev_rb_node_t *parent, **link; - link = bfdev_rb_parent(root, &parent, node, cmp, pdata, NULL); + link = bfdev_rb_parent(root, &parent, node, cmp, pdata, BFDEV_NULL); if (bfdev_unlikely(!link)) - return false; + return bfdev_false; bfdev_rb_insert_node(root, parent, link, node); - return true; + return bfdev_true; } /** @@ -710,19 +710,19 @@ bfdev_rb_insert_node_augmented(bfdev_rb_root_t *root, bfdev_rb_node_t *parent, * @cmp: operator defining the node order. * @callbacks: augmented callback function. */ -static inline bool +static inline bfdev_bool bfdev_rb_insert_augmented(bfdev_rb_root_t *root, bfdev_rb_node_t *node, bfdev_rb_cmp_t cmp, void *pdata, const bfdev_rb_callbacks_t *callbacks) { bfdev_rb_node_t *parent, **link; - link = bfdev_rb_parent(root, &parent, node, cmp, pdata, NULL); + link = bfdev_rb_parent(root, &parent, node, cmp, pdata, BFDEV_NULL); if (bfdev_unlikely(!link)) - return false; + return bfdev_false; bfdev_rb_insert_node_augmented(root, parent, link, node, callbacks); - return true; + return bfdev_true; } /** @@ -862,7 +862,7 @@ bfdev_rb_delete_augmented(bfdev_rb_root_t *root, bfdev_rb_node_t *node, */ static inline void bfdev_rb_cached_fixup(bfdev_rb_root_cached_t *cached, - bfdev_rb_node_t *node, bool leftmost) + bfdev_rb_node_t *node, bfdev_bool leftmost) { if (leftmost) cached->leftmost = node; @@ -880,7 +880,7 @@ bfdev_rb_cached_fixup(bfdev_rb_root_cached_t *cached, */ static inline void bfdev_rb_cached_insert_node(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *parent, - bfdev_rb_node_t **link, bfdev_rb_node_t *node, bool leftmost) + bfdev_rb_node_t **link, bfdev_rb_node_t *node, bfdev_bool leftmost) { bfdev_rb_link(parent, link, node); bfdev_rb_cached_fixup(cached, node, leftmost); @@ -892,19 +892,19 @@ bfdev_rb_cached_insert_node(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *par * @node: new node to insert. * @cmp: operator defining the node order. */ -static inline bool +static inline bfdev_bool bfdev_rb_cached_insert(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *node, bfdev_rb_cmp_t cmp, void *pdata) { bfdev_rb_node_t *parent, **link; - bool leftmost; + bfdev_bool leftmost; link = bfdev_rb_cached_parent(cached, &parent, node, cmp, pdata, &leftmost); if (bfdev_unlikely(!link)) - return false; + return bfdev_false; bfdev_rb_cached_insert_node(cached, parent, link, node, leftmost); - return true; + return bfdev_true; } /** @@ -918,7 +918,7 @@ bfdev_rb_cached_delete(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *node) bfdev_rb_node_t *leftmost; if (cached->leftmost != node) - leftmost = NULL; + leftmost = BFDEV_NULL; else { leftmost = bfdev_rb_next(node); cached->leftmost = leftmost; @@ -937,7 +937,7 @@ bfdev_rb_cached_delete(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *node) */ static inline void bfdev_rb_cached_fixup_augmented(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *node, - bool leftmost, const bfdev_rb_callbacks_t *callbacks) + bfdev_bool leftmost, const bfdev_rb_callbacks_t *callbacks) { if (leftmost) cached->leftmost = node; @@ -957,7 +957,7 @@ bfdev_rb_cached_fixup_augmented(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t static inline void bfdev_rb_cached_insert_node_augmented(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *parent, bfdev_rb_node_t **link, bfdev_rb_node_t *node, - bool leftmost, const bfdev_rb_callbacks_t *callbacks) + bfdev_bool leftmost, const bfdev_rb_callbacks_t *callbacks) { bfdev_rb_link(parent, link, node); bfdev_rb_cached_fixup_augmented(cached, node, leftmost, callbacks); @@ -970,20 +970,20 @@ bfdev_rb_cached_insert_node_augmented(bfdev_rb_root_cached_t *cached, bfdev_rb_n * @cmp: operator defining the node order. * @callbacks: augmented callback function. */ -static inline bool +static inline bfdev_bool bfdev_rb_cached_insert_augmented(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t *node, bfdev_rb_cmp_t cmp, void *pdata, const bfdev_rb_callbacks_t *callbacks) { bfdev_rb_node_t *parent, **link; - bool leftmost; + bfdev_bool leftmost; link = bfdev_rb_cached_parent(cached, &parent, node, cmp, pdata, &leftmost); if (bfdev_unlikely(!link)) - return false; + return bfdev_false; bfdev_rb_cached_insert_node_augmented(cached, parent, link, node, leftmost, callbacks); - return true; + return bfdev_true; } /** @@ -999,7 +999,7 @@ bfdev_rb_cached_delete_augmented(bfdev_rb_root_cached_t *cached, bfdev_rb_node_t bfdev_rb_node_t *leftmost; if (cached->leftmost != node) - leftmost = NULL; + leftmost = BFDEV_NULL; else { leftmost = bfdev_rb_next(node); cached->leftmost = leftmost; @@ -1036,7 +1036,7 @@ RBNAME##_rotate(bfdev_rb_node_t *rb_node, bfdev_rb_node_t *rb_successor) \ successor = bfdev_rb_entry(rb_successor, RBSTRUCT, RBFIELD); \ \ successor->RBAUGMENTED = node->RBAUGMENTED; \ - RBCOMPUTE(node, false); \ + RBCOMPUTE(node, bfdev_false); \ } \ \ static void \ @@ -1057,7 +1057,7 @@ RBNAME##_propagate(bfdev_rb_node_t *rb_node, bfdev_rb_node_t *rb_stop) \ \ while (rb_node != rb_stop) { \ node = bfdev_rb_entry(rb_node, RBSTRUCT, RBFIELD); \ - if (RBCOMPUTE(node, true)) \ + if (RBCOMPUTE(node, bfdev_true)) \ break; \ rb_node = node->RBFIELD.parent; \ } \ @@ -1071,8 +1071,8 @@ RBSTATIC bfdev_rb_callbacks_t RBNAME = { \ #define BFDEV_RB_DECLARE_CALLBACKS_MAX(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD, \ RBTYPE, RBAUGMENTED, RBCOMPUTE) \ -static inline bool \ -RBNAME##_compute_max(RBSTRUCT *node, bool exit) \ +static inline bfdev_bool \ +RBNAME##_compute_max(RBSTRUCT *node, bfdev_bool exit) \ { \ RBSTRUCT *child; \ RBTYPE max; \ @@ -1090,10 +1090,10 @@ RBNAME##_compute_max(RBSTRUCT *node, bool exit) \ } \ \ if (exit && node->RBAUGMENTED == max) \ - return true; \ + return bfdev_true; \ node->RBAUGMENTED = max; \ \ - return false; \ + return bfdev_false; \ } \ \ BFDEV_RB_DECLARE_CALLBACKS( \ diff --git a/include/bfdev/refcount.h b/include/bfdev/refcount.h index ad9dd2c7..a025827f 100644 --- a/include/bfdev/refcount.h +++ b/include/bfdev/refcount.h @@ -79,7 +79,7 @@ bfdev_refcnt_fetch_add(bfdev_refcnt_t *ref, bfdev_atomic_t cnt, #endif } -static inline bool +static inline bfdev_bool bfdev_refcnt_fetch_sub_test(bfdev_refcnt_t *ref, bfdev_atomic_t nr, bfdev_atomic_t *oldp) { @@ -90,7 +90,7 @@ bfdev_refcnt_fetch_sub_test(bfdev_refcnt_t *ref, bfdev_atomic_t nr, *oldp = prev; if (prev == nr) - return true; + return bfdev_true; #ifdef BFDEV_DEBUG_REFCNT if (bfdev_unlikely(!prev)) @@ -101,10 +101,10 @@ bfdev_refcnt_fetch_sub_test(bfdev_refcnt_t *ref, bfdev_atomic_t nr, bfdev_refcnt_report(ref, BFDEV_REFCNT_SUB_OVF); #endif - return false; + return bfdev_false; } -static inline bool +static inline bfdev_bool bfdev_refcnt_fetch_addnz_test(bfdev_refcnt_t *ref, bfdev_atomic_t nr, bfdev_atomic_t *oldp) { @@ -128,23 +128,23 @@ bfdev_refcnt_fetch_addnz_test(bfdev_refcnt_t *ref, bfdev_atomic_t nr, return !prev; } -#define BFDEV_REFCNT_OPS(addsub, incdec, operation) \ -static inline void \ -bfdev_generic_refcnt_##addsub(bfdev_refcnt_t *ref, bfdev_atomic_t nr) \ -{ \ - operation(ref, nr, NULL); \ -} \ - \ -static inline void \ -bfdev_generic_refcnt_##incdec(bfdev_refcnt_t *ref) \ -{ \ - operation(ref, 1, NULL); \ -} \ - \ -static inline void \ -bfdev_generic_refcnt_fetch_##incdec(bfdev_refcnt_t *ref, bfdev_atomic_t *oldp) \ -{ \ - operation(ref, 1, oldp); \ +#define BFDEV_REFCNT_OPS(addsub, incdec, operation) \ +static inline void \ +bfdev_generic_refcnt_##addsub(bfdev_refcnt_t *ref, bfdev_atomic_t nr) \ +{ \ + operation(ref, nr, BFDEV_NULL); \ +} \ + \ +static inline void \ +bfdev_generic_refcnt_##incdec(bfdev_refcnt_t *ref) \ +{ \ + operation(ref, 1, BFDEV_NULL); \ +} \ + \ +static inline void \ +bfdev_generic_refcnt_fetch_##incdec(bfdev_refcnt_t *ref, bfdev_atomic_t *oldp) \ +{ \ + operation(ref, 1, oldp); \ } #define BFDEV_REFCNT_TEST_OPS(addsub, incdec, operation) \ @@ -155,19 +155,19 @@ bfdev_generic_refcnt_fetch_##addsub(bfdev_refcnt_t *ref, operation(ref, nr, oldp); \ } \ \ -static inline bool \ +static inline bfdev_bool \ bfdev_generic_refcnt_test_##addsub(bfdev_refcnt_t *ref, bfdev_atomic_t nr) \ { \ - return operation(ref, nr, NULL); \ + return operation(ref, nr, BFDEV_NULL); \ } \ \ -static inline bool \ +static inline bfdev_bool \ bfdev_generic_refcnt_test_##incdec(bfdev_refcnt_t *ref) \ { \ - return operation(ref, 1, NULL); \ + return operation(ref, 1, BFDEV_NULL); \ } \ \ -static inline bool \ +static inline bfdev_bool \ bfdev_generic_refcnt_fetch_test_##incdec(bfdev_refcnt_t *ref, bfdev_atomic_t *oldp) \ { \ return operation(ref, 1, oldp); \ diff --git a/include/bfdev/respool.h b/include/bfdev/respool.h index a619d3c6..962754a4 100644 --- a/include/bfdev/respool.h +++ b/include/bfdev/respool.h @@ -49,7 +49,7 @@ bfdev_respool_init(bfdev_respool_t *pool) *pool = BFDEV_RESPOOL_INIT(pool); } -static inline bool +static inline bfdev_bool bfdev_respool_check_empty(bfdev_respool_t *pool) { return bfdev_list_check_empty(&pool->nodes); diff --git a/include/bfdev/ringbuf.h b/include/bfdev/ringbuf.h index 19e46b71..0ac05f94 100644 --- a/include/bfdev/ringbuf.h +++ b/include/bfdev/ringbuf.h @@ -85,7 +85,7 @@ struct bfdev_ringbuf { #define BFDEV_RINGBUF_DYNAMIC_INIT(ptr) \ (typeof(*(ptr))) { \ .ringbuf = { \ - .in = 0, .out = 0, .mask = 0, .data = NULL, \ + .in = 0, .out = 0, .mask = 0, .data = BFDEV_NULL, \ .esize = sizeof(*(ptr)->buff), \ }, \ } @@ -452,7 +452,7 @@ bfdev_ringbuf_in_record(bfdev_ringbuf_t *ringbuf, const void *buff, unsigned lon extern int bfdev_ringbuf_dynamic_alloc(bfdev_ringbuf_t *ringbuf, const bfdev_alloc_t *alloc, - size_t esize, size_t size); + bfdev_size_t esize, bfdev_size_t size); extern void bfdev_ringbuf_dynamic_free(bfdev_ringbuf_t *ringbuf); diff --git a/include/bfdev/scnprintf.h b/include/bfdev/scnprintf.h index bc7ad8bd..c805e37b 100644 --- a/include/bfdev/scnprintf.h +++ b/include/bfdev/scnprintf.h @@ -25,7 +25,8 @@ BFDEV_BEGIN_DECLS * buffer overflows. */ extern __bfdev_printf(3, 0) int -bfdev_vscnprintf(char *buf, size_t size, const char *fmt, va_list args); +bfdev_vscnprintf(char *buf, bfdev_size_t size, + const char *fmt, bfdev_va_list args); /** * bfdev_scnprintf - Format a string and place it in a buffer. @@ -39,7 +40,7 @@ bfdev_vscnprintf(char *buf, size_t size, const char *fmt, va_list args); * buffer overflows. */ extern __bfdev_printf(3, 4) int -bfdev_scnprintf(char *buf, size_t size, const char *fmt, ...); +bfdev_scnprintf(char *buf, bfdev_size_t size, const char *fmt, ...); BFDEV_END_DECLS diff --git a/include/bfdev/segtree.h b/include/bfdev/segtree.h index d536671a..a0de3790 100644 --- a/include/bfdev/segtree.h +++ b/include/bfdev/segtree.h @@ -152,14 +152,14 @@ STNAME##_insert(bfdev_rb_root_cached_t *cached, STSTRUCT *node) \ bfdev_rb_node_t **link; \ STSTRUCT *parent; \ STTYPE start, end; \ - bool leftmost; \ + bfdev_bool leftmost; \ \ link = &cached->root.node; \ start = STSTART(node); \ end = STEND(node); \ \ - parent = NULL; \ - leftmost = true; \ + parent = BFDEV_NULL; \ + leftmost = bfdev_true; \ \ while (*link) { \ parent = bfdev_rb_entry(*link, STSTRUCT, STRB); \ @@ -169,12 +169,12 @@ STNAME##_insert(bfdev_rb_root_cached_t *cached, STSTRUCT *node) \ link = &parent->STRB.left; \ else { \ link = &parent->STRB.right; \ - leftmost = false; \ + leftmost = bfdev_false; \ } \ } \ \ bfdev_rb_cached_insert_node_augmented( \ - cached, parent ? &parent->STRB : NULL, \ + cached, parent ? &parent->STRB : BFDEV_NULL, \ link, &node->STRB, leftmost, &STNAME##_callbacks \ ); \ node->STSUBTREE = end; \ @@ -210,7 +210,7 @@ STNAME##_search(STSTRUCT *node, STTYPE start, STTYPE end) \ continue; \ } \ } \ - return NULL; \ + return BFDEV_NULL; \ } \ } \ \ @@ -221,14 +221,14 @@ STNAME##_first(bfdev_rb_root_cached_t *cached, STTYPE start, STTYPE end) \ \ node = bfdev_rb_entry_safe(cached->root.node, STSTRUCT, STRB); \ if (!node) \ - return NULL; \ + return BFDEV_NULL; \ \ if (node->STSUBTREE < start) \ - return NULL; \ + return BFDEV_NULL; \ \ leftmost = bfdev_rb_cached_first_entry(cached, STSTRUCT, STRB); \ if (STSTART(leftmost) > end) \ - return NULL; \ + return BFDEV_NULL; \ \ return STNAME##_search(node, start, end); \ } \ @@ -248,14 +248,14 @@ STNAME##_next(STSTRUCT *node, STTYPE start, STTYPE end) \ do { \ walk = node->STRB.parent; \ if (!walk) \ - return NULL; \ + return BFDEV_NULL; \ prev = &node->STRB; \ node = bfdev_rb_entry(walk, STSTRUCT, STRB); \ walk = node->STRB.right; \ } while (walk == prev); \ \ if (end < STSTART(node)) \ - return NULL; \ + return BFDEV_NULL; \ else if (start <= STEND(node)) \ return node; \ } \ diff --git a/include/bfdev/sha1.h b/include/bfdev/sha1.h index 4c6ff04a..7c072499 100644 --- a/include/bfdev/sha1.h +++ b/include/bfdev/sha1.h @@ -26,13 +26,13 @@ BFDEV_BEGIN_DECLS typedef struct bfdev_sha1_ctx bfdev_sha1_ctx_t; struct bfdev_sha1_ctx { - uint32_t state[BFDEV_SHA1_DIGEST_WORDS]; - uint8_t buffer[BFDEV_SHA1_BLOCK_SIZE]; + bfdev_u32 state[BFDEV_SHA1_DIGEST_WORDS]; + bfdev_u8 buffer[BFDEV_SHA1_BLOCK_SIZE]; unsigned long count; }; extern void -bfdev_sha1_update(bfdev_sha1_ctx_t *ctx, const void *data, size_t size); +bfdev_sha1_update(bfdev_sha1_ctx_t *ctx, const void *data, bfdev_size_t size); extern void bfdev_sha1_finish(bfdev_sha1_ctx_t *ctx, void *hash); diff --git a/include/bfdev/sha2.h b/include/bfdev/sha2.h index b6b8a28f..1a31af44 100644 --- a/include/bfdev/sha2.h +++ b/include/bfdev/sha2.h @@ -41,13 +41,13 @@ BFDEV_BEGIN_DECLS typedef struct bfdev_sha2_ctx bfdev_sha2_ctx_t; struct bfdev_sha2_ctx { - uint32_t state[BFDEV_SHA256_DIGEST_WORDS]; - uint8_t buffer[BFDEV_SHA2_BLOCK_SIZE]; + bfdev_u32 state[BFDEV_SHA256_DIGEST_WORDS]; + bfdev_u8 buffer[BFDEV_SHA2_BLOCK_SIZE]; unsigned long count; }; extern void -bfdev_sha2_update(bfdev_sha2_ctx_t *ctx, const void *data, size_t size); +bfdev_sha2_update(bfdev_sha2_ctx_t *ctx, const void *data, bfdev_size_t size); extern void bfdev_sha224_finish(bfdev_sha2_ctx_t *ctx, void *hash); diff --git a/include/bfdev/slist.h b/include/bfdev/slist.h index b239fa3e..467f354b 100644 --- a/include/bfdev/slist.h +++ b/include/bfdev/slist.h @@ -21,7 +21,7 @@ struct bfdev_slist_head { }; #define BFDEV_SLIST_HEAD_STATIC() { \ - .next = NULL, \ + .next = BFDEV_NULL, \ } #define BFDEV_SLIST_HEAD_INIT() \ @@ -31,10 +31,10 @@ struct bfdev_slist_head { bfdev_slist_head_t name = BFDEV_SLIST_HEAD_INIT() #ifdef BFDEV_DEBUG_SLIST -extern bool +extern bfdev_bool bfdev_slist_check_add(bfdev_slist_head_t *node, bfdev_slist_head_t *newn); -extern bool +extern bfdev_bool bfdev_slist_check_del(bfdev_slist_head_t *node); #endif @@ -92,7 +92,7 @@ bfdev_slist_del(bfdev_slist_head_t *head, bfdev_slist_head_t *node) * bfdev_slist_check_empty() - check whether the node is head. * @head: slist head to check. */ -static inline bool +static inline bfdev_bool bfdev_slist_check_empty(const bfdev_slist_head_t *head) { return !head->next; @@ -103,7 +103,7 @@ bfdev_slist_check_empty(const bfdev_slist_head_t *head) * @head: the head of the slist. * @node: the entry to test. */ -static inline bool +static inline bfdev_bool bfdev_slist_check_first(const bfdev_slist_head_t *head, const bfdev_slist_head_t *node) { @@ -114,7 +114,7 @@ bfdev_slist_check_first(const bfdev_slist_head_t *head, * bfdev_slist_check_next() - check whether the node is a ending. * @node: the node to check. */ -static inline bool +static inline bfdev_bool bfdev_slist_check_end(const bfdev_slist_head_t *node) { return !node->next; @@ -125,11 +125,11 @@ bfdev_slist_check_end(const bfdev_slist_head_t *node) * @head: slist head to check. * @node: the unique node. */ -static inline bool +static inline bfdev_bool bfdev_slist_check_another(const bfdev_slist_head_t *head, const bfdev_slist_head_t *node) { - return head->next == node && node->next == NULL; + return head->next == node && node->next == BFDEV_NULL; } /** diff --git a/include/bfdev/sort.h b/include/bfdev/sort.h index 5c9b7384..19571584 100644 --- a/include/bfdev/sort.h +++ b/include/bfdev/sort.h @@ -24,7 +24,8 @@ BFDEV_BEGIN_DECLS * O(n^2) worst-case behavior and extra memory requirements. */ extern int -bfdev_sort(void *base, size_t num, size_t cells, bfdev_cmp_t cmp, void *pdata); +bfdev_sort(void *base, bfdev_size_t num, bfdev_size_t cells, + bfdev_cmp_t cmp, void *pdata); BFDEV_END_DECLS diff --git a/include/bfdev/stdio.h b/include/bfdev/stdio.h deleted file mode 100644 index 42e20ca1..00000000 --- a/include/bfdev/stdio.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * Copyright(c) 2023 John Sanpe - */ - -#ifndef _BFDEV_STDIO_H_ -#define _BFDEV_STDIO_H_ - -#include -#include - -BFDEV_BEGIN_DECLS - -BFDEV_END_DECLS - -#endif /* _BFDEV_STDIO_H_ */ diff --git a/include/bfdev/string.h b/include/bfdev/string.h index a0413b68..30975529 100644 --- a/include/bfdev/string.h +++ b/include/bfdev/string.h @@ -16,15 +16,13 @@ extern char * bfdev_strdiff(const char *addr, int c); extern void * -bfdev_memdiff(const void *addr, int c, size_t size); +bfdev_memdiff(const void *addr, int c, bfdev_size_t size); extern char * -bfdev_strdup(const bfdev_alloc_t *alloc, - const char *string); +bfdev_strdup(const bfdev_alloc_t *alloc, const char *string); extern char * -bfdev_strndup(const bfdev_alloc_t *alloc, - const char *string, size_t len); +bfdev_strndup(const bfdev_alloc_t *alloc, const char *string, bfdev_size_t len); BFDEV_END_DECLS diff --git a/include/bfdev/swab.h b/include/bfdev/swab.h index 6a42972f..b5eeb717 100644 --- a/include/bfdev/swab.h +++ b/include/bfdev/swab.h @@ -14,55 +14,55 @@ BFDEV_BEGIN_DECLS /* * casts are necessary for constants, because we never know how for sure - * how U/UL/ULL map to uint16_t, uint32_t, uint64_t. At least not in a portable way. + * how U/UL/ULL map to bfdev_u16, bfdev_u32, bfdev_u64. At least not in a portable way. */ -#define bfdev_swab16_const(x) ((uint16_t)( \ - (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \ - (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) \ +#define bfdev_swab16_const(x) ((bfdev_u16)( \ + (((bfdev_u16)(x) & (bfdev_u16)0x00ffU) << 8) | \ + (((bfdev_u16)(x) & (bfdev_u16)0xff00U) >> 8) \ )) -#define bfdev_swab32_const(x) ((uint32_t)( \ - (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) \ +#define bfdev_swab32_const(x) ((bfdev_u32)( \ + (((bfdev_u32)(x) & (bfdev_u32)0x000000ffUL) << 24) | \ + (((bfdev_u32)(x) & (bfdev_u32)0x0000ff00UL) << 8) | \ + (((bfdev_u32)(x) & (bfdev_u32)0x00ff0000UL) >> 8) | \ + (((bfdev_u32)(x) & (bfdev_u32)0xff000000UL) >> 24) \ )) -#define bfdev_swab64_const(x) ((uint64_t)( \ - (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) \ +#define bfdev_swab64_const(x) ((bfdev_u64)( \ + (((bfdev_u64)(x) & (bfdev_u64)0x00000000000000ffULL) << 56) | \ + (((bfdev_u64)(x) & (bfdev_u64)0x000000000000ff00ULL) << 40) | \ + (((bfdev_u64)(x) & (bfdev_u64)0x0000000000ff0000ULL) << 24) | \ + (((bfdev_u64)(x) & (bfdev_u64)0x00000000ff000000ULL) << 8) | \ + (((bfdev_u64)(x) & (bfdev_u64)0x000000ff00000000ULL) >> 8) | \ + (((bfdev_u64)(x) & (bfdev_u64)0x0000ff0000000000ULL) >> 24) | \ + (((bfdev_u64)(x) & (bfdev_u64)0x00ff000000000000ULL) >> 40) | \ + (((bfdev_u64)(x) & (bfdev_u64)0xff00000000000000ULL) >> 56) \ )) -#define bfdev_swahb32_const(x) ((uint32_t)( \ - (((uint32_t)(x) & (uint32_t)0x00ff00ffUL) << 8) | \ - (((uint32_t)(x) & (uint32_t)0xff00ff00UL) >> 8) \ +#define bfdev_swahb32_const(x) ((bfdev_u32)( \ + (((bfdev_u32)(x) & (bfdev_u32)0x00ff00ffUL) << 8) | \ + (((bfdev_u32)(x) & (bfdev_u32)0xff00ff00UL) >> 8) \ )) -#define bfdev_swahw32_const(x) ((uint32_t)( \ - (((uint32_t)(x) & (uint32_t)0x0000ffffUL) << 16) | \ - (((uint32_t)(x) & (uint32_t)0xffff0000UL) >> 16) \ +#define bfdev_swahw32_const(x) ((bfdev_u32)( \ + (((bfdev_u32)(x) & (bfdev_u32)0x0000ffffUL) << 16) | \ + (((bfdev_u32)(x) & (bfdev_u32)0xffff0000UL) >> 16) \ )) -#define bfdev_swahb64_const(x) ((uint64_t)( \ - (((uint64_t)(x) & (uint64_t)0x00ff00ff00ff00ffULL) << 8) | \ - (((uint64_t)(x) & (uint64_t)0xff00ff00ff00ff00ULL) >> 8) \ +#define bfdev_swahb64_const(x) ((bfdev_u64)( \ + (((bfdev_u64)(x) & (bfdev_u64)0x00ff00ff00ff00ffULL) << 8) | \ + (((bfdev_u64)(x) & (bfdev_u64)0xff00ff00ff00ff00ULL) >> 8) \ )) -#define bfdev_swahw64_const(x) ((uint64_t)( \ - (((uint64_t)(x) & (uint64_t)0x0000ffff0000ffffULL) << 16) | \ - (((uint64_t)(x) & (uint64_t)0xffff0000ffff0000ULL) >> 16) \ +#define bfdev_swahw64_const(x) ((bfdev_u64)( \ + (((bfdev_u64)(x) & (bfdev_u64)0x0000ffff0000ffffULL) << 16) | \ + (((bfdev_u64)(x) & (bfdev_u64)0xffff0000ffff0000ULL) >> 16) \ )) -#define bfdev_swahl64_const(x) ((uint64_t)( \ - (((uint64_t)(x) & (uint64_t)0x00000000ffffffffULL) << 32) | \ - (((uint64_t)(x) & (uint64_t)0xffffffff00000000ULL) >> 32) \ +#define bfdev_swahl64_const(x) ((bfdev_u64)( \ + (((bfdev_u64)(x) & (bfdev_u64)0x00000000ffffffffULL) << 32) | \ + (((bfdev_u64)(x) & (bfdev_u64)0xffffffff00000000ULL) >> 32) \ )) /* @@ -72,7 +72,7 @@ BFDEV_BEGIN_DECLS */ static inline __bfdev_attribute_const -uint16_t bfdev_fswab16(uint16_t val) +bfdev_u16 bfdev_fswab16(bfdev_u16 val) { #ifdef bfdev_arch_swab16 return bfdev_arch_swab16(val); @@ -82,7 +82,7 @@ uint16_t bfdev_fswab16(uint16_t val) } static inline __bfdev_attribute_const -uint32_t bfdev_fswab32(uint32_t val) +bfdev_u32 bfdev_fswab32(bfdev_u32 val) { #ifdef bfdev_arch_swab32 return bfdev_arch_swab32(val); @@ -92,7 +92,7 @@ uint32_t bfdev_fswab32(uint32_t val) } static inline __bfdev_attribute_const -uint64_t bfdev_fswab64(uint64_t val) +bfdev_u64 bfdev_fswab64(bfdev_u64 val) { #ifdef bfdev_arch_swab64 return bfdev_arch_swab64(val); @@ -102,7 +102,7 @@ uint64_t bfdev_fswab64(uint64_t val) } static inline __bfdev_attribute_const -uint32_t bfdev_fswahb32(uint32_t val) +bfdev_u32 bfdev_fswahb32(bfdev_u32 val) { #ifdef bfdev_arch_swahb32 return bfdev_arch_swahb32(val); @@ -112,7 +112,7 @@ uint32_t bfdev_fswahb32(uint32_t val) } static inline __bfdev_attribute_const -uint32_t bfdev_fswahw32(uint32_t val) +bfdev_u32 bfdev_fswahw32(bfdev_u32 val) { #ifdef bfdev_arch_swahw32 return bfdev_arch_swahw32(val); @@ -122,7 +122,7 @@ uint32_t bfdev_fswahw32(uint32_t val) } static inline __bfdev_attribute_const -uint64_t bfdev_fswahb64(uint64_t val) +bfdev_u64 bfdev_fswahb64(bfdev_u64 val) { #ifdef bfdev_arch_swahb64 return bfdev_arch_swahb64(val); @@ -132,7 +132,7 @@ uint64_t bfdev_fswahb64(uint64_t val) } static inline __bfdev_attribute_const -uint64_t bfdev_fswahw64(uint64_t val) +bfdev_u64 bfdev_fswahw64(bfdev_u64 val) { #ifdef bfdev_arch_swahw64 return bfdev_arch_swahw64(val); @@ -142,7 +142,7 @@ uint64_t bfdev_fswahw64(uint64_t val) } static inline __bfdev_attribute_const -uint64_t bfdev_fswahl64(uint64_t val) +bfdev_u64 bfdev_fswahl64(bfdev_u64 val) { #ifdef bfdev_arch_swahl64 return bfdev_arch_swahl64(val); @@ -156,10 +156,10 @@ uint64_t bfdev_fswahl64(uint64_t val) * @x: value to byteswap. */ #ifdef __HAVE_BUILTIN_BSWAP16__ -# define bfdev_swab16(x) (uint16_t)__builtin_bswap16((uint16_t)(x)) +# define bfdev_swab16(x) (bfdev_u16)__builtin_bswap16((bfdev_u16)(x)) #else # define bfdev_swab16(x) ( \ - __builtin_constant_p((uint16_t)(x)) ? \ + __builtin_constant_p((bfdev_u16)(x)) ? \ bfdev_swab16_const(x) : \ bfdev_fswab16(x) \ ) @@ -170,10 +170,10 @@ uint64_t bfdev_fswahl64(uint64_t val) * @x: value to byteswap. */ #ifdef __HAVE_BUILTIN_BSWAP32__ -# define bfdev_swab32(x) (uint32_t)__builtin_bswap32((uint32_t)(x)) +# define bfdev_swab32(x) (bfdev_u32)__builtin_bswap32((bfdev_u32)(x)) #else # define bfdev_swab32(x) ( \ - __builtin_constant_p((uint32_t)(x)) ? \ + __builtin_constant_p((bfdev_u32)(x)) ? \ bfdev_swab32_const(x) : \ bfdev_fswab32(x) \ ) @@ -184,10 +184,10 @@ uint64_t bfdev_fswahl64(uint64_t val) * @x: value to byteswap. */ #ifdef __HAVE_BUILTIN_BSWAP64__ -# define bfdev_swab64(x) (uint64_t)__builtin_bswap64((uint64_t)(x)) +# define bfdev_swab64(x) (bfdev_u64)__builtin_bswap64((bfdev_u64)(x)) #else # define bfdev_swab64(x) ( \ - __builtin_constant_p((uint64_t)(x)) ? \ + __builtin_constant_p((bfdev_u64)(x)) ? \ bfdev_swab64_const(x) : \ bfdev_fswab64(x) \ ) @@ -212,7 +212,7 @@ unsigned long bfdev_swab(const unsigned long y) * @x: value to byteswap. */ #define bfdev_swahb32(x) ( \ - __builtin_constant_p((uint32_t)(x)) ? \ + __builtin_constant_p((bfdev_u32)(x)) ? \ bfdev_swahb32_const(x) : \ bfdev_fswahb32(x) \ ) @@ -222,7 +222,7 @@ unsigned long bfdev_swab(const unsigned long y) * @x: value to wordswap. */ #define bfdev_swahw32(x) ( \ - __builtin_constant_p((uint32_t)(x)) ? \ + __builtin_constant_p((bfdev_u32)(x)) ? \ bfdev_swahw32_const(x) : \ bfdev_fswahw32(x) \ ) @@ -232,7 +232,7 @@ unsigned long bfdev_swab(const unsigned long y) * @x: value to byteswap. */ #define bfdev_swahb64(x) ( \ - __builtin_constant_p((uint64_t)(x)) ? \ + __builtin_constant_p((bfdev_u64)(x)) ? \ bfdev_swahb64_const(x) : \ bfdev_fswahb64(x) \ ) @@ -242,7 +242,7 @@ unsigned long bfdev_swab(const unsigned long y) * @x: value to wordswap. */ #define bfdev_swahw64(x) ( \ - __builtin_constant_p((uint64_t)(x)) ? \ + __builtin_constant_p((bfdev_u64)(x)) ? \ bfdev_swahw64_const(x) : \ bfdev_fswahw64(x) \ ) @@ -252,7 +252,7 @@ unsigned long bfdev_swab(const unsigned long y) * @x: value to wordswap. */ #define bfdev_swahl64(x) ( \ - __builtin_constant_p((uint64_t)(x)) ? \ + __builtin_constant_p((bfdev_u64)(x)) ? \ bfdev_swahl64_const(x) : \ bfdev_fswahl64(x) \ ) @@ -261,8 +261,8 @@ unsigned long bfdev_swab(const unsigned long y) * bfdev_swab16p - return a byteswapped 16-bit value from a pointer. * @p: pointer to a naturally-aligned 16-bit value. */ -static __bfdev_always_inline uint16_t -bfdev_swab16p(const uint16_t *p) +static __bfdev_always_inline bfdev_u16 +bfdev_swab16p(const bfdev_u16 *p) { #ifdef bfdev_arch_swab16p return bfdev_arch_swab16p(p); @@ -275,8 +275,8 @@ bfdev_swab16p(const uint16_t *p) * bfdev_swab32p - return a byteswapped 32-bit value from a pointer. * @p: pointer to a naturally-aligned 32-bit value. */ -static __bfdev_always_inline uint32_t -bfdev_swab32p(const uint32_t *p) +static __bfdev_always_inline bfdev_u32 +bfdev_swab32p(const bfdev_u32 *p) { #ifdef bfdev_arch_swab32p return bfdev_arch_swab32p(p); @@ -289,8 +289,8 @@ bfdev_swab32p(const uint32_t *p) * bfdev_swab64p - return a byteswapped 64-bit value from a pointer. * @p: pointer to a naturally-aligned 64-bit value. */ -static __bfdev_always_inline uint64_t -bfdev_swab64p(const uint64_t *p) +static __bfdev_always_inline bfdev_u64 +bfdev_swab64p(const bfdev_u64 *p) { #ifdef bfdev_arch_swab64p return bfdev_arch_swab64p(p); @@ -307,9 +307,9 @@ static __bfdev_always_inline unsigned long bfdev_swabp(const unsigned long *y) { #if BFDEV_BITS_PER_LONG == 32 - return bfdev_swab32p((const uint32_t *)y); + return bfdev_swab32p((const bfdev_u32 *)y); #else /* BFDEV_BITS_PER_LONG == 64 */ - return bfdev_swab64p((const uint64_t *)y); + return bfdev_swab64p((const bfdev_u64 *)y); #endif } @@ -317,8 +317,8 @@ unsigned long bfdev_swabp(const unsigned long *y) * bfdev_swahb32p - return a high and low byteswapped 32-bit value from a pointer. * @p: pointer to a naturally-aligned 32-bit value. */ -static inline uint32_t -bfdev_swahb32p(const uint32_t *p) +static inline bfdev_u32 +bfdev_swahb32p(const bfdev_u32 *p) { #ifdef bfdev_arch_swahb32p return bfdev_arch_swahb32p(p); @@ -331,8 +331,8 @@ bfdev_swahb32p(const uint32_t *p) * bfdev_swahw32p - return a wordswapped 32-bit value from a pointer. * @p: pointer to a naturally-aligned 32-bit value. */ -static inline uint32_t -bfdev_swahw32p(const uint32_t *p) +static inline bfdev_u32 +bfdev_swahw32p(const bfdev_u32 *p) { #ifdef bfdev_arch_swahw32p return bfdev_arch_swahw32p(p); @@ -345,8 +345,8 @@ bfdev_swahw32p(const uint32_t *p) * bfdev_swahb64p - return a high and low byteswapped 64-bit value from a pointer. * @p: pointer to a naturally-aligned 64-bit value. */ -static inline uint64_t -bfdev_swahb64p(const uint64_t *p) +static inline bfdev_u64 +bfdev_swahb64p(const bfdev_u64 *p) { #ifdef bfdev_arch_swahb64p return bfdev_arch_swahb64p(p); @@ -359,8 +359,8 @@ bfdev_swahb64p(const uint64_t *p) * bfdev_swahw64p - return a wordswapped 64-bit value from a pointer. * @p: pointer to a naturally-aligned 64-bit value. */ -static inline uint64_t -bfdev_swahw64p(const uint64_t *p) +static inline bfdev_u64 +bfdev_swahw64p(const bfdev_u64 *p) { #ifdef bfdev_arch_swahw64p return bfdev_arch_swahw64p(p); @@ -373,8 +373,8 @@ bfdev_swahw64p(const uint64_t *p) * bfdev_swahl64p - return a longswapped 64-bit value from a pointer. * @p: pointer to a naturally-aligned 64-bit value. */ -static inline uint64_t -bfdev_swahl64p(const uint64_t *p) +static inline bfdev_u64 +bfdev_swahl64p(const bfdev_u64 *p) { #ifdef bfdev_arch_swahl64p return bfdev_arch_swahl64p(p); @@ -388,7 +388,7 @@ bfdev_swahl64p(const uint64_t *p) * @p: pointer to a naturally-aligned 16-bit value. */ static inline void -bfdev_swab16s(uint16_t *p) +bfdev_swab16s(bfdev_u16 *p) { #ifdef bfdev_arch_swab16s bfdev_arch_swab16s(p); @@ -402,7 +402,7 @@ bfdev_swab16s(uint16_t *p) * @p: pointer to a naturally-aligned 32-bit value. */ static __bfdev_always_inline void -bfdev_swab32s(uint32_t *p) +bfdev_swab32s(bfdev_u32 *p) { #ifdef bfdev_arch_swab32s bfdev_arch_swab32s(p); @@ -416,7 +416,7 @@ bfdev_swab32s(uint32_t *p) * @p: pointer to a naturally-aligned 64-bit value. */ static __bfdev_always_inline void -bfdev_swab64s(uint64_t *p) +bfdev_swab64s(bfdev_u64 *p) { #ifdef bfdev_arch_swab64s bfdev_arch_swab64s(p); @@ -433,9 +433,9 @@ static __bfdev_always_inline void bfdev_swabs(unsigned long *p) { #if BFDEV_BITS_PER_LONG == 32 - bfdev_swab32s((uint32_t *)p); + bfdev_swab32s((bfdev_u32 *)p); #else /* BFDEV_BITS_PER_LONG == 64 */ - bfdev_swab64s((uint64_t *)p); + bfdev_swab64s((bfdev_u64 *)p); #endif } @@ -444,7 +444,7 @@ bfdev_swabs(unsigned long *p) * @p: pointer to a naturally-aligned 32-bit value. */ static inline void -bfdev_swahb32s(uint32_t *p) +bfdev_swahb32s(bfdev_u32 *p) { #ifdef bfdev_arch_swahb32s bfdev_arch_swahb32s(p); @@ -458,7 +458,7 @@ bfdev_swahb32s(uint32_t *p) * @p: pointer to a naturally-aligned 32-bit value. */ static inline void -bfdev_swahw32s(uint32_t *p) +bfdev_swahw32s(bfdev_u32 *p) { #ifdef bfdev_arch_swahw32s bfdev_arch_swahw32s(p); @@ -472,7 +472,7 @@ bfdev_swahw32s(uint32_t *p) * @p: pointer to a naturally-aligned 64-bit value. */ static inline void -bfdev_swahb64s(uint64_t *p) +bfdev_swahb64s(bfdev_u64 *p) { #ifdef bfdev_arch_swahb64s bfdev_arch_swahb64s(p); @@ -486,7 +486,7 @@ bfdev_swahb64s(uint64_t *p) * @p: pointer to a naturally-aligned 64-bit value. */ static inline void -bfdev_swahw64s(uint64_t *p) +bfdev_swahw64s(bfdev_u64 *p) { #ifdef bfdev_arch_swahw64s bfdev_arch_swahw64s(p); @@ -500,7 +500,7 @@ bfdev_swahw64s(uint64_t *p) * @p: pointer to a naturally-aligned 64-bit value. */ static inline void -bfdev_swahl64s(uint64_t *p) +bfdev_swahl64s(bfdev_u64 *p) { #ifdef bfdev_arch_swahw64s bfdev_arch_swahw64s(p); @@ -510,7 +510,7 @@ bfdev_swahl64s(uint64_t *p) } static inline void -bfdev_swab16_array(uint16_t *buff, unsigned int count) +bfdev_swab16_array(bfdev_u16 *buff, unsigned int count) { while (count--) { bfdev_swab16s(buff); @@ -519,7 +519,7 @@ bfdev_swab16_array(uint16_t *buff, unsigned int count) } static inline void -bfdev_swab32_array(uint32_t *buff, unsigned int count) +bfdev_swab32_array(bfdev_u32 *buff, unsigned int count) { while (count--) { bfdev_swab32s(buff); @@ -528,7 +528,7 @@ bfdev_swab32_array(uint32_t *buff, unsigned int count) } static inline void -bfdev_swab64_array(uint64_t *buff, unsigned int count) +bfdev_swab64_array(bfdev_u64 *buff, unsigned int count) { while (count--) { bfdev_swab64s(buff); @@ -540,9 +540,9 @@ static inline void bfdev_swab_array(unsigned long *buff, unsigned int count) { #if BFDEV_BITS_PER_LONG == 32 - bfdev_swab32_array((uint32_t *)buff, count); + bfdev_swab32_array((bfdev_u32 *)buff, count); #else /* BFDEV_BITS_PER_LONG == 64 */ - bfdev_swab64_array((uint64_t *)buff, count); + bfdev_swab64_array((bfdev_u64 *)buff, count); #endif } diff --git a/include/bfdev/textsearch.h b/include/bfdev/textsearch.h index 26cb08f7..722caab0 100644 --- a/include/bfdev/textsearch.h +++ b/include/bfdev/textsearch.h @@ -66,14 +66,14 @@ struct bfdev_ts_context { /** * next_block() - fetch next block of data. - * @tsc: search configuration. - * @tss: search state. - * @consumed: number of bytes consumed by the caller. - * @dest: destination buffer. + * @tsc: search configuration. + * @tss: search state. + * @consumed: number of bytes consumed by the caller. + * @dest: destination buffer. * - * Called repeatedly until 0 is returned. Must assign the - * head of the next block of data to &*dst and return the length - * of the block or 0 if at the end. + * Called repeatedly until 0 is returned. Must assign the + * head of the next block of data to &*dst and return the length + * of the block or 0 if at the end. */ unsigned int (*next_block)(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss, @@ -97,32 +97,32 @@ struct bfdev_ts_algorithm { */ bfdev_ts_context_t * (*prepare)(const bfdev_alloc_t *alloc, const void *pattern, - size_t len, unsigned long flags); + bfdev_size_t len, unsigned long flags); /** * destroy() - destroy algorithm specific parts of a search configuration. - * @tsc: search configuration. + * @tsc: search configuration. */ void (*destroy)(bfdev_ts_context_t *tsc); /** * find() - find the next occurrence of the pattern. - * @tsc: search configuration. + * @tsc: search configuration. */ unsigned int (*find)(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss); /** * pattern_get() - return pointer of pattern. - * @tsc: search configuration. + * @tsc: search configuration. */ const void * (*pattern_get)(bfdev_ts_context_t *tsc); /** * pattern_len() - return length of pattern. - * @tsc: search configuration. + * @tsc: search configuration. */ unsigned int (*pattern_len)(bfdev_ts_context_t *tsc); @@ -140,7 +140,7 @@ BFDEV_BITFLAGS_STRUCT( * @tss: search state. * * Returns the position of first occurrence of the pattern or - * UINT_MAX if no match was found. + * BFDEV_UINT_MAX if no match was found. */ static inline unsigned int bfdev_textsearch_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) @@ -163,7 +163,7 @@ bfdev_textsearch_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) * in order to reset the state. * * Returns the position of the next occurrence of the pattern or - * UINT_MAX if not match was found. + * BFDEV_UINT_MAX if not match was found. */ static inline unsigned int bfdev_textsearch_next(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) @@ -231,7 +231,7 @@ bfdev_textsearch_destroy(bfdev_ts_context_t *tsc) * Call bfdev_textsearch_next() to retrieve subsequent matches. * * Returns the position of first occurrence of the pattern or - * %UINT_MAX if no occurrence was found. + * %BFDEV_UINT_MAX if no occurrence was found. */ extern unsigned int bfdev_textsearch_linear(bfdev_ts_context_t *tsc, bfdev_ts_linear_t *linear, @@ -247,7 +247,8 @@ bfdev_textsearch_linear(bfdev_ts_context_t *tsc, bfdev_ts_linear_t *linear, */ extern bfdev_ts_context_t * bfdev_textsearch_create(const bfdev_alloc_t *alloc, const char *name, - const void *pattern, size_t len, unsigned long flags); + const void *pattern, bfdev_size_t len, + unsigned long flags); /** * bfdev_textsearch_register() - register a textsearch module. diff --git a/include/bfdev/time.h b/include/bfdev/time.h index 11bd7895..91e9af04 100644 --- a/include/bfdev/time.h +++ b/include/bfdev/time.h @@ -35,7 +35,7 @@ bfdev_time_compare(const bfdev_time_t va, const bfdev_time_t vb) * @va: the bigger one. * @vb: the smaller one. */ -static inline bool +static inline bfdev_bool bfdev_time_after(const bfdev_time_t va, const bfdev_time_t vb) { return bfdev_time_compare(va, vb) > 0; @@ -46,7 +46,7 @@ bfdev_time_after(const bfdev_time_t va, const bfdev_time_t vb) * @va: the smaller one. * @vb: the bigger one. */ -static inline bool +static inline bfdev_bool bfdev_time_before(const bfdev_time_t va, const bfdev_time_t vb) { return bfdev_time_compare(va, vb) < 0; @@ -57,7 +57,7 @@ bfdev_time_before(const bfdev_time_t va, const bfdev_time_t vb) * @va: the bigger one. * @vb: the smaller one. */ -static inline bool +static inline bfdev_bool bfdev_time_after_equal(const bfdev_time_t va, const bfdev_time_t vb) { return bfdev_time_compare(va, vb) >= 0; @@ -68,7 +68,7 @@ bfdev_time_after_equal(const bfdev_time_t va, const bfdev_time_t vb) * @va: the smaller one. * @vb: the bigger one. */ -static inline bool +static inline bfdev_bool bfdev_time_before_equal(const bfdev_time_t va, const bfdev_time_t vb) { return bfdev_time_compare(va, vb) <= 0; diff --git a/include/bfdev/titer.h b/include/bfdev/titer.h index eb10379a..a9734dac 100644 --- a/include/bfdev/titer.h +++ b/include/bfdev/titer.h @@ -44,7 +44,7 @@ TISTATIC TISTRUCT *TINAME##_left_deep(const TISTRUCT *node) return (TISTRUCT *)node; \ } \ \ - return NULL; \ + return BFDEV_NULL; \ } \ \ TISTATIC TISTRUCT *TINAME##_right_deep(const TISTRUCT *node) \ @@ -59,7 +59,7 @@ TISTATIC TISTRUCT *TINAME##_right_deep(const TISTRUCT *node) return (TISTRUCT *)node; \ } \ \ - return NULL; \ + return BFDEV_NULL; \ } #define BFDEV_TITER_INORDER_DEFINE(TISTATIC, TINAME, BNAME, TIROOT, TINODE, \ @@ -69,7 +69,7 @@ TISTATIC TISTRUCT *TINAME##_first(const TIROOT *root) TISTRUCT *node = root->TINODE; \ \ if (!root || !node) \ - return NULL; \ + return BFDEV_NULL; \ \ /* Get the leftmost node */ \ node = BNAME##_left_far(node); \ @@ -81,7 +81,7 @@ TISTATIC TISTRUCT *TINAME##_last(const TIROOT *root) TISTRUCT *node = root->TINODE; \ \ if (!root || !node) \ - return NULL; \ + return BFDEV_NULL; \ \ /* Get the rightmost node */ \ node = BNAME##_right_far(node); \ @@ -93,7 +93,7 @@ TISTATIC TISTRUCT *TINAME##_prev(const TISTRUCT *node) TISTRUCT *parent; \ \ if (!node) \ - return NULL; \ + return BFDEV_NULL; \ \ /* \ * If there is a left-hand node, go down \ @@ -119,7 +119,7 @@ TISTATIC TISTRUCT *TINAME##_next(const TISTRUCT *node) TISTRUCT *parent; \ \ if (!node) \ - return NULL; \ + return BFDEV_NULL; \ \ /* \ * If there is a right-hand node, go down \ @@ -153,7 +153,7 @@ TISTATIC TISTRUCT *TINAME##_next(const TISTRUCT *node) TISTRUCT *parent; \ \ if (!node) \ - return NULL; \ + return BFDEV_NULL; \ \ /** \ * If there are left and right child nodes, \ @@ -173,7 +173,7 @@ TISTATIC TISTRUCT *TINAME##_next(const TISTRUCT *node) (!parent->TIRIGHT || node == parent->TIRIGHT)) \ node = parent; \ \ - return parent ? parent->TIRIGHT : NULL; \ + return parent ? parent->TIRIGHT : BFDEV_NULL; \ } #define BFDEV_TITER_POSTORDER_DEFINE(TISTATIC, TINAME, BNAME, TIROOT, TINODE, \ @@ -183,7 +183,7 @@ TISTATIC TISTRUCT *TINAME##_first(const TIROOT *root) TISTRUCT *node = root->TINODE; \ \ if (!root || !node) \ - return NULL; \ + return BFDEV_NULL; \ \ /* Get the left deepest node. */ \ return BNAME##_left_deep(node); \ @@ -194,7 +194,7 @@ TISTATIC TISTRUCT *TINAME##_next(const TISTRUCT *node) const TISTRUCT *parent; \ \ if (!node) \ - return NULL; \ + return BFDEV_NULL; \ parent = node->TIPARENT; \ \ /** \ diff --git a/include/bfdev/tokenbucket.h b/include/bfdev/tokenbucket.h index 2a19a80d..31632f5a 100644 --- a/include/bfdev/tokenbucket.h +++ b/include/bfdev/tokenbucket.h @@ -65,7 +65,7 @@ bfdev_tokenbucket_reset(bfdev_tokenbucket_t *limit) * 0 means function will be suppressed. * 1 means go ahead and do it. */ -extern bool +extern bfdev_bool bfdev_tokenbucket(bfdev_tokenbucket_t *limit, bfdev_time_t current); BFDEV_END_DECLS diff --git a/include/bfdev/types.h b/include/bfdev/types.h index 29226fca..85b87c58 100644 --- a/include/bfdev/types.h +++ b/include/bfdev/types.h @@ -7,8 +7,8 @@ #define _BFDEV_TYPES_H_ #include -#include #include +#include #include BFDEV_BEGIN_DECLS @@ -21,12 +21,12 @@ BFDEV_BEGIN_DECLS # define __bfdev_force #endif -typedef uint16_t __bfdev_bitwise bfdev_le16; -typedef uint32_t __bfdev_bitwise bfdev_le32; -typedef uint64_t __bfdev_bitwise bfdev_le64; -typedef uint16_t __bfdev_bitwise bfdev_be16; -typedef uint32_t __bfdev_bitwise bfdev_be32; -typedef uint64_t __bfdev_bitwise bfdev_be64; +typedef bfdev_u16 __bfdev_bitwise bfdev_le16; +typedef bfdev_u32 __bfdev_bitwise bfdev_le32; +typedef bfdev_u64 __bfdev_bitwise bfdev_le64; +typedef bfdev_u16 __bfdev_bitwise bfdev_be16; +typedef bfdev_u32 __bfdev_bitwise bfdev_be32; +typedef bfdev_u64 __bfdev_bitwise bfdev_be64; typedef int bfdev_sqi_t __bfdev_mode(QI); typedef int bfdev_shi_t __bfdev_mode(HI); @@ -49,8 +49,8 @@ typedef bfdev_usi_t bfdev_uhw_t; #endif typedef int bfdev_state_t; -typedef intptr_t bfdev_atomic_t; -typedef int64_t bfdev_time_t; +typedef bfdev_intptr_t bfdev_atomic_t; +typedef bfdev_u64 bfdev_time_t; #define BFDEV_EQ 0 #define BFDEV_BT 1 @@ -62,12 +62,12 @@ typedef int64_t bfdev_time_t; #define BFDEV_BYTES_PER_LONG sizeof(long) #define BFDEV_BYTES_PER_LONG_LONG sizeof(long long) -#define BFDEV_BYTES_PER_U8 sizeof(uint8_t) -#define BFDEV_BYTES_PER_U16 sizeof(uint16_t) -#define BFDEV_BYTES_PER_U32 sizeof(uint32_t) -#define BFDEV_BYTES_PER_U64 sizeof(uint64_t) -#define BFDEV_BYTES_PER_UINTMAX sizeof(uintmax_t) -#define BFDEV_BYTES_PER_UINTPTR sizeof(uintptr_t) +#define BFDEV_BYTES_PER_U8 sizeof(bfdev_u8) +#define BFDEV_BYTES_PER_U16 sizeof(bfdev_u16) +#define BFDEV_BYTES_PER_U32 sizeof(bfdev_u32) +#define BFDEV_BYTES_PER_U64 sizeof(bfdev_u64) +#define BFDEV_BYTES_PER_UINTMAX sizeof(bfdev_uintmax_t) +#define BFDEV_BYTES_PER_UINTPTR sizeof(bfdev_uintptr_t) /* Generic callback functions */ #define BFDEV_CALLBACK_FIND(name, type) \ @@ -83,8 +83,8 @@ BFDEV_CALLBACK_FIND(bfdev_find_t, const void *); BFDEV_CALLBACK_CMP(bfdev_cmp_t, const void *); BFDEV_CALLBACK_RELEASE(bfdev_release_t, void *); -typedef void *(*bfdev_malloc_t)(size_t size, void *pdata); -typedef void *(*bfdev_realloc_t)(void *block, size_t resize, void *pdata); +typedef void *(*bfdev_malloc_t)(bfdev_size_t size, void *pdata); +typedef void *(*bfdev_realloc_t)(void *block, bfdev_size_t resize, void *pdata); typedef void (*bfdev_free_t)(void *block, void *pdata); BFDEV_END_DECLS diff --git a/include/bfdev/unaligned.h b/include/bfdev/unaligned.h index 0c0595d4..d65d59b0 100644 --- a/include/bfdev/unaligned.h +++ b/include/bfdev/unaligned.h @@ -44,7 +44,7 @@ bfdev_unaligned_set_ulong(void *ptr, unsigned long val) #endif #ifndef bfdev_unaligned_get_u16 -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_unaligned_get_u16(const void *ptr) { return bfdev_arch_unaligned_get_u16(ptr); @@ -52,7 +52,7 @@ bfdev_unaligned_get_u16(const void *ptr) #endif #ifndef bfdev_unaligned_get_u32 -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_unaligned_get_u32(const void *ptr) { return bfdev_arch_unaligned_get_u32(ptr); @@ -60,7 +60,7 @@ bfdev_unaligned_get_u32(const void *ptr) #endif #ifndef bfdev_unaligned_get_u64 -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_unaligned_get_u64(const void *ptr) { return bfdev_arch_unaligned_get_u64(ptr); @@ -69,7 +69,7 @@ bfdev_unaligned_get_u64(const void *ptr) #ifndef bfdev_unaligned_set_u16 static __bfdev_always_inline void -bfdev_unaligned_set_u16(void *ptr, uint16_t val) +bfdev_unaligned_set_u16(void *ptr, bfdev_u16 val) { bfdev_arch_unaligned_set_u16(ptr, val); } @@ -77,7 +77,7 @@ bfdev_unaligned_set_u16(void *ptr, uint16_t val) #ifndef bfdev_unaligned_set_u32 static __bfdev_always_inline void -bfdev_unaligned_set_u32(void *ptr, uint32_t val) +bfdev_unaligned_set_u32(void *ptr, bfdev_u32 val) { bfdev_arch_unaligned_set_u32(ptr, val); } @@ -85,14 +85,14 @@ bfdev_unaligned_set_u32(void *ptr, uint32_t val) #ifndef bfdev_unaligned_set_u64 static __bfdev_always_inline void -bfdev_unaligned_set_u64(void *ptr, uint64_t val) +bfdev_unaligned_set_u64(void *ptr, bfdev_u64 val) { bfdev_arch_unaligned_set_u64(ptr, val); } #endif #ifndef bfdev_unaligned_get_le16 -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_unaligned_get_le16(const void *ptr) { return bfdev_arch_unaligned_get_le16(ptr); @@ -100,7 +100,7 @@ bfdev_unaligned_get_le16(const void *ptr) #endif #ifndef bfdev_unaligned_get_le32 -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_unaligned_get_le32(const void *ptr) { return bfdev_arch_unaligned_get_le32(ptr); @@ -108,7 +108,7 @@ bfdev_unaligned_get_le32(const void *ptr) #endif #ifndef bfdev_unaligned_get_le64 -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_unaligned_get_le64(const void *ptr) { return bfdev_arch_unaligned_get_le64(ptr); @@ -117,7 +117,7 @@ bfdev_unaligned_get_le64(const void *ptr) #ifndef bfdev_unaligned_set_le16 static __bfdev_always_inline void -bfdev_unaligned_set_le16(void *ptr, uint16_t val) +bfdev_unaligned_set_le16(void *ptr, bfdev_u16 val) { bfdev_arch_unaligned_set_le16(ptr, val); } @@ -125,7 +125,7 @@ bfdev_unaligned_set_le16(void *ptr, uint16_t val) #ifndef bfdev_unaligned_set_le32 static __bfdev_always_inline void -bfdev_unaligned_set_le32(void *ptr, uint32_t val) +bfdev_unaligned_set_le32(void *ptr, bfdev_u32 val) { bfdev_arch_unaligned_set_le32(ptr, val); } @@ -133,14 +133,14 @@ bfdev_unaligned_set_le32(void *ptr, uint32_t val) #ifndef bfdev_unaligned_set_le64 static __bfdev_always_inline void -bfdev_unaligned_set_le64(void *ptr, uint64_t val) +bfdev_unaligned_set_le64(void *ptr, bfdev_u64 val) { bfdev_arch_unaligned_set_le64(ptr, val); } #endif #ifndef bfdev_unaligned_get_be16 -static __bfdev_always_inline uint16_t +static __bfdev_always_inline bfdev_u16 bfdev_unaligned_get_be16(const void *ptr) { return bfdev_arch_unaligned_get_be16(ptr); @@ -148,7 +148,7 @@ bfdev_unaligned_get_be16(const void *ptr) #endif #ifndef bfdev_unaligned_get_be32 -static __bfdev_always_inline uint32_t +static __bfdev_always_inline bfdev_u32 bfdev_unaligned_get_be32(const void *ptr) { return bfdev_arch_unaligned_get_be32(ptr); @@ -156,7 +156,7 @@ bfdev_unaligned_get_be32(const void *ptr) #endif #ifndef bfdev_unaligned_get_be64 -static __bfdev_always_inline uint64_t +static __bfdev_always_inline bfdev_u64 bfdev_unaligned_get_be64(const void *ptr) { return bfdev_arch_unaligned_get_be64(ptr); @@ -165,7 +165,7 @@ bfdev_unaligned_get_be64(const void *ptr) #ifndef bfdev_unaligned_set_be16 static __bfdev_always_inline void -bfdev_unaligned_set_be16(void *ptr, uint16_t val) +bfdev_unaligned_set_be16(void *ptr, bfdev_u16 val) { bfdev_arch_unaligned_set_be16(ptr, val); } @@ -173,7 +173,7 @@ bfdev_unaligned_set_be16(void *ptr, uint16_t val) #ifndef bfdev_unaligned_set_be32 static __bfdev_always_inline void -bfdev_unaligned_set_be32(void *ptr, uint32_t val) +bfdev_unaligned_set_be32(void *ptr, bfdev_u32 val) { bfdev_arch_unaligned_set_be32(ptr, val); } @@ -181,7 +181,7 @@ bfdev_unaligned_set_be32(void *ptr, uint32_t val) #ifndef bfdev_unaligned_set_be64 static __bfdev_always_inline void -bfdev_unaligned_set_be64(void *ptr, uint64_t val) +bfdev_unaligned_set_be64(void *ptr, bfdev_u64 val) { bfdev_arch_unaligned_set_be64(ptr, val); } diff --git a/include/bfdev/uplower.h b/include/bfdev/uplower.h index 3c516ee6..fc3d2418 100644 --- a/include/bfdev/uplower.h +++ b/include/bfdev/uplower.h @@ -16,7 +16,7 @@ BFDEV_BEGIN_DECLS * @val: the value we're accessing. */ #define bfdev_upper_16_bits(val) ( \ - (uint16_t)((val) >> 16) \ + (bfdev_u16)((val) >> 16) \ ) /** @@ -24,7 +24,7 @@ BFDEV_BEGIN_DECLS * @val: the value we're accessing. */ #define bfdev_lower_16_bits(val) ( \ - (uint16_t)((val) & 0xffff) \ + (bfdev_u16)((val) & 0xffff) \ ) /** @@ -32,7 +32,7 @@ BFDEV_BEGIN_DECLS * @val: the value we're accessing. */ #define bfdev_upper_32_bits(val) ( \ - (uint32_t)(((val) >> 16) >> 16) \ + (bfdev_u32)(((val) >> 16) >> 16) \ ) /** @@ -40,7 +40,7 @@ BFDEV_BEGIN_DECLS * @val: the value we're accessing. */ #define bfdev_lower_32_bits(val) ( \ - (uint32_t)((val) & 0xffffffff) \ + (bfdev_u32)((val) & 0xffffffff) \ ) BFDEV_END_DECLS diff --git a/include/port/allocator.h b/include/port/allocator.h index 810f90b5..cc8de9e0 100644 --- a/include/port/allocator.h +++ b/include/port/allocator.h @@ -8,25 +8,26 @@ #include #include +#include #ifndef __INSIDE_ALLOCATOR__ # error "please don't include this file directly" #endif static __bfdev_always_inline void * -generic_alloc(size_t size, void *pdata) +generic_alloc(bfdev_size_t size, void *pdata) { return bfport_malloc(size); } static __bfdev_always_inline void * -generic_zalloc(size_t size, void *pdata) +generic_zalloc(bfdev_size_t size, void *pdata) { return bfport_calloc(1, size); } static __bfdev_always_inline void * -generic_realloc(void *block, size_t resize, void *pdata) +generic_realloc(void *block, bfdev_size_t resize, void *pdata) { return bfport_realloc(block, resize); } diff --git a/include/port/log.h b/include/port/log.h index e5e3d38a..ed3025b9 100644 --- a/include/port/log.h +++ b/include/port/log.h @@ -8,24 +8,9 @@ #include #include +#include -#ifndef __INSIDE_LOG__ -# error "please don't include this file directly" -#endif - -static inline int -generic_log_write(bfdev_log_message_t *msg) -{ - bfport_file *file; - - if (msg->level > BFDEV_LEVEL_WARNING) - file = bfport_stdout; - else { - file = bfport_stderr; - bfport_fflush(bfport_stdout); - } - - return bfport_fwrite(msg->buff, msg->length, 1, file); -} +extern int +bfport_log_write(bfdev_log_message_t *msg); #endif /* _LOCAL_PORT_LOG_H_ */ diff --git a/include/port/stdio.h b/include/port/stdio.h new file mode 100644 index 00000000..21947506 --- /dev/null +++ b/include/port/stdio.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2023 John Sanpe + */ + +#ifndef _LOCAL_PORT_STDIO_H_ +#define _LOCAL_PORT_STDIO_H_ + +#include +#include +#include + +BFDEV_BEGIN_DECLS + +extern int +bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *format, + bfdev_va_list arg); + +BFDEV_END_DECLS + +#endif /* _LOCAL_PORT_STDIO_H_ */ diff --git a/include/port/stdlib.h b/include/port/stdlib.h new file mode 100644 index 00000000..e5449b54 --- /dev/null +++ b/include/port/stdlib.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2023 John Sanpe + */ + +#ifndef _LOCAL_PORT_STDLIB_H_ +#define _LOCAL_PORT_STDLIB_H_ + +#include +#include + +BFDEV_BEGIN_DECLS + +extern __bfdev_malloc void * +bfport_malloc(bfdev_size_t size); + +extern __bfdev_malloc void * +bfport_calloc(bfdev_size_t nmemb, bfdev_size_t size); + +extern __bfdev_malloc void * +bfport_realloc(void *ptr, bfdev_size_t size); + +extern void +bfport_free(void *ptr); + +extern int +bfport_rand(void); + +extern __bfdev_noreturn void +bfport_abort(void); + +BFDEV_END_DECLS + +#endif /* _LOCAL_PORT_STDLIB_H_ */ diff --git a/include/port/string.h b/include/port/string.h new file mode 100644 index 00000000..dcabeb28 --- /dev/null +++ b/include/port/string.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2023 John Sanpe + */ + +#ifndef _LOCAL_PORT_STRING_H_ +#define _LOCAL_PORT_STRING_H_ + +#include +#include + +BFDEV_BEGIN_DECLS + +extern void * +bfport_memcpy(void *dest, const void *src, bfdev_size_t n); + +extern void * +bfport_memset(void *s, int c, bfdev_size_t n); + +extern int +bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n); + +extern int +bfport_strcmp(const char *s1, const char *s2); + +extern char * +bfport_strchr(const char *s, int c); + +extern bfdev_size_t +bfport_strspn(const char *s, const char *accept); + +extern bfdev_size_t +bfport_strcspn(const char *s, const char *reject); + +extern char * +bfport_strcpy(char *dest, const char *src); + +extern char * +bfport_strncpy(char *dest, const char *src, bfdev_size_t n); + +extern bfdev_size_t +bfport_strlen(const char *s); + +extern bfdev_size_t +bfport_strnlen(const char *s, bfdev_size_t len); + +BFDEV_END_DECLS + +#endif /* _LOCAL_PORT_STRING_H_ */ diff --git a/port/build.cmake b/port/build.cmake new file mode 100644 index 00000000..c543976e --- /dev/null +++ b/port/build.cmake @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# +# Copyright(c) 2025 John Sanpe +# + +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin|GNU") + set(BFDEV_PORT_TYPE "posix") +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN") + set(BFDEV_PORT_TYPE "posix") +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD|FreeBSD|NetBSD|OpenBSD|DragonFly") + set(BFDEV_PORT_TYPE "posix") +endif() + +if(BFDEV_PORT_TYPE) + include(${BFDEV_PORT_PATH}/${BFDEV_PORT_TYPE}/build.cmake) +else() + message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}") +endif() diff --git a/port/posix/build.cmake b/port/posix/build.cmake new file mode 100644 index 00000000..196adb4a --- /dev/null +++ b/port/posix/build.cmake @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# +# Copyright(c) 2025 John Sanpe +# + +set(BFDEV_SOURCE + ${BFDEV_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/log.c + ${CMAKE_CURRENT_LIST_DIR}/stdio.c + ${CMAKE_CURRENT_LIST_DIR}/stdlib.c + ${CMAKE_CURRENT_LIST_DIR}/string.c +) diff --git a/port/posix/log.c b/port/posix/log.c new file mode 100644 index 00000000..070711f5 --- /dev/null +++ b/port/posix/log.c @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include +#include +#include + +export int +bfport_log_write(bfdev_log_message_t *msg) +{ + FILE *file; + + if (msg->level > BFDEV_LEVEL_WARNING) + file = stdout; + else { + file = stderr; + fflush(stdout); + } + + return fwrite(msg->buff, msg->length, 1, file); +} diff --git a/port/posix/stdio.c b/port/posix/stdio.c new file mode 100644 index 00000000..eee380b0 --- /dev/null +++ b/port/posix/stdio.c @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include +#include + +#if defined(__FreeBSD__) && defined(_KERNEL) +# include +#else +# include +#endif + +export int +bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *fmt, + bfdev_va_list arg) +{ + return vsnprintf(s, maxlen, fmt, arg); +} diff --git a/port/posix/stdlib.c b/port/posix/stdlib.c new file mode 100644 index 00000000..378915c4 --- /dev/null +++ b/port/posix/stdlib.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include + +#if defined(__FreeBSD__) && defined(_KERNEL) +# include +#else +# include +#endif + +export __bfdev_malloc void * +bfport_malloc(bfdev_size_t size) +{ + return malloc(size); +} + +export __bfdev_malloc void * +bfport_calloc(bfdev_size_t nmemb, bfdev_size_t size) +{ + return calloc(nmemb, size); +} + +export __bfdev_malloc void * +bfport_realloc(void *ptr, bfdev_size_t size) +{ + return realloc(ptr, size); +} + +export void +bfport_free(void *ptr) +{ + free(ptr); +} + +export int +bfport_rand(void) +{ + return rand(); +} + +export __bfdev_noreturn void +bfport_abort(void) +{ + abort(); +} diff --git a/port/posix/string.c b/port/posix/string.c new file mode 100644 index 00000000..c0e102f5 --- /dev/null +++ b/port/posix/string.c @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include + +#if defined(__FreeBSD__) && defined(_KERNEL) +# include +#else +# include +#endif + +export void * +bfport_memcpy(void *dest, const void *src, bfdev_size_t n) +{ + return memcpy(dest, src, n); +} + +export void * +bfport_memset(void *s, int c, bfdev_size_t n) +{ + return memset(s, c, n); +} + +export int +bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n) +{ + return memcmp(s1, s2, n); +} + +export int +bfport_strcmp(const char *s1, const char *s2) +{ + return strcmp(s1, s2); +} + +export char * +bfport_strchr(const char *s, int c) +{ + return strchr(s, c); +} + +export bfdev_size_t +bfport_strspn(const char *s, const char *accept) +{ + return strspn(s, accept); +} + +export bfdev_size_t +bfport_strcspn(const char *s, const char *reject) +{ + return strcspn(s, reject); +} + +export char * +bfport_strcpy(char *dest, const char *src) +{ + return strcpy(dest, src); +} + +export char * +bfport_strncpy(char *dest, const char *src, bfdev_size_t n) +{ + return strncpy(dest, src, n); +} + +export bfdev_size_t +bfport_strlen(const char *s) +{ + return strlen(s); +} + +export bfdev_size_t +bfport_strnlen(const char *s, bfdev_size_t len) +{ + return strnlen(s, len); +} diff --git a/scripts/gen-crc.c b/scripts/gen-crc.c index 1b93623b..574405b0 100644 --- a/scripts/gen-crc.c +++ b/scripts/gen-crc.c @@ -18,6 +18,8 @@ #define NAME_STRING __stringify(GENCRC_NAME) #define TYPE_STRING __stringify(GENCRC_TYPE) +#define TYPE_NAME_STRING __stringify(GENCRC_TYPE_NAME) + #define BITS_STRING __stringify(GENCRC_BITS) #define WIDE_STRING __stringify(GENCRC_WIDE) @@ -86,11 +88,12 @@ table_dump(unsigned int rows, const char *trans, printf("\n\t\t"); if (trans) { - printf("(__bfdev_force " TYPE_STRING ")(%s((" TYPE_STRING ")0x%" - WIDE_STRING "." WIDE_STRING "llxULL)), ", trans, + printf("(__bfdev_force " TYPE_NAME_STRING ")(%s((" + TYPE_NAME_STRING ")0x%" WIDE_STRING "." + WIDE_STRING "llxULL)), ", trans, (unsigned long long)table[index][count]); } else { - printf("(" TYPE_STRING ")0x%" WIDE_STRING + printf("(" TYPE_NAME_STRING ")0x%" WIDE_STRING "." WIDE_STRING "llxULL, ", (unsigned long long)table[index][count]); } @@ -144,7 +147,7 @@ main(int argc, char *argv[]) " * byteorder = %s-endian\n" " */\n" "\n" - "static const " TYPE_STRING "\n" + "static const " TYPE_NAME_STRING "\n" "%s[%d][%d] = {\n", name, (unsigned long long)poly, GENCRC_BELE ? "little" : "big", diff --git a/scripts/gen-crc16.c b/scripts/gen-crc16.c index ad90da1d..01c4d144 100644 --- a/scripts/gen-crc16.c +++ b/scripts/gen-crc16.c @@ -5,6 +5,7 @@ #define GENCRC_NAME crc16 #define GENCRC_TYPE uint16_t +#define GENCRC_TYPE_NAME bfdev_u16 #define GENCRC_BITS 16 #define GENCRC_WIDE 4 #define GENCRC_BELE 1 diff --git a/scripts/gen-crc16be.c b/scripts/gen-crc16be.c index 74d35666..320f864a 100644 --- a/scripts/gen-crc16be.c +++ b/scripts/gen-crc16be.c @@ -5,6 +5,7 @@ #define GENCRC_NAME crc16be #define GENCRC_TYPE uint16_t +#define GENCRC_TYPE_NAME bfdev_u16 #define GENCRC_BITS 16 #define GENCRC_WIDE 4 #define GENCRC_BELE 0 diff --git a/scripts/gen-crc32.c b/scripts/gen-crc32.c index 80744ac2..c8f33d00 100644 --- a/scripts/gen-crc32.c +++ b/scripts/gen-crc32.c @@ -5,6 +5,7 @@ #define GENCRC_NAME crc32 #define GENCRC_TYPE uint32_t +#define GENCRC_TYPE_NAME bfdev_u32 #define GENCRC_BITS 32 #define GENCRC_WIDE 8 #define GENCRC_BELE 1 diff --git a/scripts/gen-crc32be.c b/scripts/gen-crc32be.c index 132a65ff..4ee7eae7 100644 --- a/scripts/gen-crc32be.c +++ b/scripts/gen-crc32be.c @@ -5,6 +5,7 @@ #define GENCRC_NAME crc32be #define GENCRC_TYPE uint32_t +#define GENCRC_TYPE_NAME bfdev_u32 #define GENCRC_BITS 32 #define GENCRC_WIDE 8 #define GENCRC_BELE 0 diff --git a/scripts/gen-crc64.c b/scripts/gen-crc64.c index 0888ac18..54b43a7b 100644 --- a/scripts/gen-crc64.c +++ b/scripts/gen-crc64.c @@ -5,6 +5,7 @@ #define GENCRC_NAME crc64 #define GENCRC_TYPE uint64_t +#define GENCRC_TYPE_NAME bfdev_u64 #define GENCRC_BITS 64 #define GENCRC_WIDE 16 #define GENCRC_BELE 1 diff --git a/scripts/gen-crc64be.c b/scripts/gen-crc64be.c index 0d7fcfb9..0dfae10d 100644 --- a/scripts/gen-crc64be.c +++ b/scripts/gen-crc64be.c @@ -5,6 +5,7 @@ #define GENCRC_NAME crc64be #define GENCRC_TYPE uint64_t +#define GENCRC_TYPE_NAME bfdev_u64 #define GENCRC_BITS 64 #define GENCRC_WIDE 16 #define GENCRC_BELE 0 diff --git a/scripts/gen-crc8.c b/scripts/gen-crc8.c index 2c398b4f..9fe80c92 100644 --- a/scripts/gen-crc8.c +++ b/scripts/gen-crc8.c @@ -5,6 +5,7 @@ #define GENCRC_NAME crc8 #define GENCRC_TYPE uint8_t +#define GENCRC_TYPE_NAME bfdev_u8 #define GENCRC_BITS 8 #define GENCRC_WIDE 2 #define GENCRC_BELE 0 diff --git a/scripts/sanitize.cmake b/scripts/sanitize.cmake index a9cda3cf..2522813e 100644 --- a/scripts/sanitize.cmake +++ b/scripts/sanitize.cmake @@ -29,8 +29,7 @@ if(BFDEV_UBSAN) -fsanitize=integer-divide-by-zero \ -fsanitize=unreachable \ -fsanitize=bool \ - -fsanitize=enum \ - -fsanitize-undefined-trap-on-error" + -fsanitize=enum" ) endif() diff --git a/src/allocator.c b/src/allocator.c index 079caa6f..521a3c42 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -9,12 +9,12 @@ BFDEV_DEFINE_ALLOC( bfdev_alloc_default, - NULL, NULL + BFDEV_NULL, BFDEV_NULL ); BFDEV_DEFINE_ALLOC_OPS( bfdev_alloc_default_ops, - NULL, NULL, NULL, NULL + BFDEV_NULL, BFDEV_NULL, BFDEV_NULL, BFDEV_NULL ); #define __INSIDE_ALLOCATOR__ @@ -38,13 +38,13 @@ alloc_ops(const bfdev_alloc_t *alloc, void **pdata) } export __bfdev_malloc void * -bfdev_malloc(const bfdev_alloc_t *alloc, size_t size) +bfdev_malloc(const bfdev_alloc_t *alloc, bfdev_size_t size) { const bfdev_alloc_ops_t *ops; void *pdata, *retval; if (bfdev_unlikely(!size)) - return NULL; + return BFDEV_NULL; ops = alloc_ops(alloc, &pdata); if (!ops->alloc) @@ -56,13 +56,13 @@ bfdev_malloc(const bfdev_alloc_t *alloc, size_t size) } export __bfdev_malloc void * -bfdev_zalloc(const bfdev_alloc_t *alloc, size_t size) +bfdev_zalloc(const bfdev_alloc_t *alloc, bfdev_size_t size) { const bfdev_alloc_ops_t *ops; void *pdata, *retval; if (bfdev_unlikely(!size)) - return NULL; + return BFDEV_NULL; ops = alloc_ops(alloc, &pdata); if (!ops->zalloc) @@ -74,7 +74,8 @@ bfdev_zalloc(const bfdev_alloc_t *alloc, size_t size) } export __bfdev_malloc void * -bfdev_realloc(const bfdev_alloc_t *alloc, const void *block, size_t resize) +bfdev_realloc(const bfdev_alloc_t *alloc, const void *block, + bfdev_size_t resize) { const bfdev_alloc_ops_t *ops; void *pdata, *retval; @@ -84,7 +85,7 @@ bfdev_realloc(const bfdev_alloc_t *alloc, const void *block, size_t resize) if (bfdev_unlikely(!resize)) { bfdev_free(alloc, block); - return NULL; + return BFDEV_NULL; } ops = alloc_ops(alloc, &pdata); diff --git a/src/allocpool.c b/src/allocpool.c index b5f63dc4..a212577a 100644 --- a/src/allocpool.c +++ b/src/allocpool.c @@ -8,20 +8,21 @@ #include export __bfdev_malloc void * -bfdev_allocpool_alloc(bfdev_allocpool_t *pool, size_t size, size_t align) +bfdev_allocpool_alloc(bfdev_allocpool_t *pool, bfdev_size_t size, + bfdev_size_t align) { - uintptr_t offset; + bfdev_uintptr_t offset; void *retval; if (bfdev_unlikely(!size)) - return NULL; + return BFDEV_NULL; align = bfdev_align_high(align ?: 1, sizeof(retval)); retval = bfdev_align_ptr_high(pool->block + pool->last, align); offset = (retval - pool->block) + size; if (bfdev_unlikely(offset > pool->size)) - return NULL; + return BFDEV_NULL; pool->last = offset; pool->count++; diff --git a/src/argv.c b/src/argv.c index e22fb53f..71845551 100644 --- a/src/argv.c +++ b/src/argv.c @@ -13,17 +13,17 @@ export unsigned int bfdev_argv_count(const char *args) { unsigned int argc; - size_t offset; + bfdev_size_t offset; argc = 0; for (;;) { - offset = bfport_strspn(args, ARGV_SEPARA); + offset = bfdev_strspn(args, ARGV_SEPARA); if (!args[offset]) break; args += offset; argc++; - offset = bfport_strcspn(args, ARGV_SEPARA); + offset = bfdev_strcspn(args, ARGV_SEPARA); if (!args[offset]) break; args += offset; @@ -42,21 +42,21 @@ bfdev_argv_split(const bfdev_alloc_t *alloc, const char *args, argc = bfdev_argv_count(args); count = (argc + 1) * sizeof(*argv); - argv = bfdev_malloc(alloc, count + bfport_strlen(args) + 1); + argv = bfdev_malloc(alloc, count + bfdev_strlen(args) + 1); if (bfdev_unlikely(!argv)) - return NULL; + return BFDEV_NULL; block = (void *)argv + count; - bfport_strcpy(block, args); + bfdev_strcpy(block, args); for (count = 0; count < argc; ++count) { - block += bfport_strspn(block, ARGV_SEPARA); + block += bfdev_strspn(block, ARGV_SEPARA); argv[count] = block; - block += bfport_strcspn(block, ARGV_SEPARA); + block += bfdev_strcspn(block, ARGV_SEPARA); *block++ = '\0'; } - argv[count] = NULL; + argv[count] = BFDEV_NULL; if (argcp) *argcp = argc; diff --git a/src/array.c b/src/array.c index cae85f8e..f6a4f3c5 100644 --- a/src/array.c +++ b/src/array.c @@ -9,11 +9,11 @@ #include #include -static inline size_t +static inline bfdev_size_t array_reqsize(bfdev_array_t *array, unsigned long count) { unsigned long request; - size_t size; + bfdev_size_t size; request = bfdev_max(BFDEV_ARRAY_MSIZE, count); size = bfdev_pow2_roundup(request * array->cells); @@ -22,7 +22,7 @@ array_reqsize(bfdev_array_t *array, unsigned long count) } static inline int -array_resize(bfdev_array_t *array, size_t size) +array_resize(bfdev_array_t *array, bfdev_size_t size) { const bfdev_alloc_t *alloc; void *data; @@ -41,7 +41,7 @@ array_resize(bfdev_array_t *array, size_t size) static inline int array_apply(bfdev_array_t *array, unsigned long count) { - size_t reqsize; + bfdev_size_t reqsize; if (count <= array->capacity) return -BFDEV_ENOERR; @@ -56,12 +56,12 @@ static inline void * array_peek(const bfdev_array_t *array, unsigned long num, unsigned long *idxp) { unsigned long index; - uintptr_t offset; - bool overflow; + bfdev_uintptr_t offset; + bfdev_bool overflow; overflow = bfdev_overflow_check_sub(array->index, num, &index); if (bfdev_unlikely(overflow)) - return NULL; + return BFDEV_NULL; offset = bfdev_array_offset(array, index); if (idxp) @@ -74,17 +74,17 @@ export void * bfdev_array_push(bfdev_array_t *array, unsigned long num) { unsigned long index, count; - uintptr_t offset; - bool overflow; + bfdev_uintptr_t offset; + bfdev_bool overflow; int retval; overflow = bfdev_overflow_check_add(array->index, num, &count); if (bfdev_unlikely(overflow)) - return NULL; + return BFDEV_NULL; retval = array_apply(array, count); if (bfdev_unlikely(retval)) - return NULL; + return BFDEV_NULL; index = array->index; array->index = count; @@ -102,13 +102,13 @@ bfdev_array_pop(bfdev_array_t *array, unsigned long num) export void * bfdev_array_peek(const bfdev_array_t *array, unsigned long num) { - return array_peek(array, num, NULL); + return array_peek(array, num, BFDEV_NULL); } export int bfdev_array_append(bfdev_array_t *array, const void *data, unsigned long num) { - size_t size; + bfdev_size_t size; void *buff; buff = bfdev_array_push(array, num); @@ -116,7 +116,7 @@ bfdev_array_append(bfdev_array_t *array, const void *data, unsigned long num) return -BFDEV_ENOMEM; size = bfdev_array_offset(array, num); - bfport_memcpy(buff, data, size); + bfdev_memcpy(buff, data, size); return -BFDEV_ENOERR; } @@ -139,7 +139,7 @@ export int bfdev_array_reserve(bfdev_array_t *array, unsigned long num) { unsigned long count; - bool overflow; + bfdev_bool overflow; overflow = bfdev_overflow_check_add(array->index, num, &count); if (bfdev_unlikely(overflow)) @@ -158,5 +158,5 @@ bfdev_array_release(bfdev_array_t *array) alloc = array->alloc; bfdev_free(alloc, array->data); - array->data = NULL; + array->data = BFDEV_NULL; } diff --git a/src/bcd.c b/src/bcd.c index 4ad1794d..dc250fca 100644 --- a/src/bcd.c +++ b/src/bcd.c @@ -6,9 +6,9 @@ #include #include -export const uint8_t +export const bfdev_u8 bfdev_bcd2bin_table[256] = { - [0 ... 255] = UINT8_MAX, + [0 ... 255] = BFDEV_UINT8_MAX, [0x00] = 0, [0x01] = 1, [0x02] = 2, [0x03] = 3, [0x04] = 4, [0x05] = 5, [0x06] = 6, [0x07] = 7, [0x08] = 8, [0x09] = 9, [0x10] = 10, [0x11] = 11, [0x12] = 12, [0x13] = 13, [0x14] = 14, @@ -31,9 +31,9 @@ bfdev_bcd2bin_table[256] = { [0x95] = 95, [0x96] = 96, [0x97] = 97, [0x98] = 98, [0x99] = 99, }; -export const uint8_t +export const bfdev_u8 bfdev_bin2bcd_table[256] = { - [0 ... 255] = UINT8_MAX, + [0 ... 255] = BFDEV_UINT8_MAX, [ 0] = 0x00, [ 1] = 0x01, [ 2] = 0x02, [ 3] = 0x03, [ 4] = 0x04, [ 5] = 0x05, [ 6] = 0x06, [ 7] = 0x07, [ 8] = 0x08, [ 9] = 0x09, [10] = 0x10, [11] = 0x11, [12] = 0x12, [13] = 0x13, [14] = 0x14, diff --git a/src/bitmap.c b/src/bitmap.c index a6312201..4aa54d63 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -7,7 +7,7 @@ #include #include -export bool +export bfdev_bool bfdev_bitmap_comp_equal(const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -17,19 +17,19 @@ bfdev_bitmap_comp_equal(const unsigned long *src1, const unsigned long *src2, length = BFDEV_BITS_DIV_LONG(bits); for (index = 0; index < length; ++index) { if (src1[index] != src2[index]) - return false; + return bfdev_false; } if (BFDEV_BITS_MOD_LONG(bits)) { value = src1[index] ^ src2[index]; if (value & BFDEV_BIT_LOW_MASK(bits)) - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_bitmap_comp_or_equal(const unsigned long *src1, const unsigned long *src2, const unsigned long *src3, unsigned int bits) { @@ -39,19 +39,19 @@ bfdev_bitmap_comp_or_equal(const unsigned long *src1, const unsigned long *src2, length = BFDEV_BITS_DIV_LONG(bits); for (index = 0; index < length; ++index) { if ((src1[index] | src2[index]) != src3[index]) - return false; + return bfdev_false; } if (BFDEV_BITS_MOD_LONG(bits)) { value = (src1[index] | src2[index]) ^ src3[index]; if (value & BFDEV_BIT_LOW_MASK(bits)) - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_bitmap_comp_intersects(const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -61,19 +61,19 @@ bfdev_bitmap_comp_intersects(const unsigned long *src1, const unsigned long *src length = BFDEV_BITS_DIV_LONG(bits); for (index = 0; index < length; ++index) { if ((src1[index] & src2[index])) - return true; + return bfdev_true; } if (BFDEV_BITS_MOD_LONG(bits)) { value = src1[index] & src2[index]; if (value & BFDEV_BIT_LOW_MASK(bits)) - return true; + return bfdev_true; } - return false; + return bfdev_false; } -export bool +export bfdev_bool bfdev_bitmap_comp_and(unsigned long *dest, const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -96,7 +96,7 @@ bfdev_bitmap_comp_and(unsigned long *dest, const unsigned long *src1, return !!result; } -export bool +export bfdev_bool bfdev_bitmap_comp_andnot(unsigned long *dest, const unsigned long *src1, const unsigned long *src2, unsigned int bits) { @@ -168,7 +168,7 @@ bfdev_bitmap_comp_shl(unsigned long *dest, const unsigned long *src, offset = BFDEV_BITS_DIV_LONG(shift); if (length <= offset) { - bfport_memset(dest, 0, length * sizeof(*dest)); + bfdev_memset(dest, 0, length * sizeof(*dest)); return; } @@ -201,7 +201,7 @@ bfdev_bitmap_comp_shl(unsigned long *dest, const unsigned long *src, } if (offset) - bfport_memset(dest, 0, offset * sizeof(*dest)); + bfdev_memset(dest, 0, offset * sizeof(*dest)); } export void @@ -215,7 +215,7 @@ bfdev_bitmap_comp_shr(unsigned long *dest, const unsigned long *src, offset = BFDEV_BITS_DIV_LONG(shift); if (length <= offset) { - bfport_memset(dest, 0, length * sizeof(*dest)); + bfdev_memset(dest, 0, length * sizeof(*dest)); return; } @@ -248,7 +248,7 @@ bfdev_bitmap_comp_shr(unsigned long *dest, const unsigned long *src, } if (offset) - bfport_memset(dest + length - offset, 0, offset * sizeof(*dest)); + bfdev_memset(dest + length - offset, 0, offset * sizeof(*dest)); } export void @@ -305,7 +305,7 @@ bfdev_bitmap_comp_set(unsigned long *bitmap, unsigned int start, while (bits - bits_to_set) { *curr++ |= mask_to_set; bits -= bits_to_set; - mask_to_set = ULONG_MAX; + mask_to_set = BFDEV_ULONG_MAX; bits_to_set = BFDEV_BITS_PER_LONG; } @@ -330,7 +330,7 @@ bfdev_bitmap_comp_clr(unsigned long *bitmap, unsigned int start, while (bits - bits_to_clr) { *curr++ &= ~mask_to_clr; bits -= bits_to_clr; - mask_to_clr = ULONG_MAX; + mask_to_clr = BFDEV_ULONG_MAX; bits_to_clr = BFDEV_BITS_PER_LONG; } diff --git a/src/bitrev.c b/src/bitrev.c index a673055d..6a634f38 100644 --- a/src/bitrev.c +++ b/src/bitrev.c @@ -6,7 +6,7 @@ #include #include -export const uint8_t +export const bfdev_u8 bfdev_bitrev_byte_table[256] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, diff --git a/src/bitwalk.c b/src/bitwalk.c index 78466e1a..82ff2115 100644 --- a/src/bitwalk.c +++ b/src/bitwalk.c @@ -10,7 +10,7 @@ export unsigned int bfdev_comp_find_first_bit(const unsigned long *block, unsigned int bits, - unsigned long invert, bool swap) + unsigned long invert, bfdev_bool swap) { unsigned long value; unsigned int base, offset; @@ -39,7 +39,7 @@ bfdev_comp_find_first_bit(const unsigned long *block, unsigned int bits, export unsigned int bfdev_comp_find_last_bit(const unsigned long *block, unsigned int bits, - unsigned long invert, bool swap) + unsigned long invert, bfdev_bool swap) { unsigned long value, mask; unsigned int base, offset; @@ -74,7 +74,7 @@ bfdev_comp_find_last_bit(const unsigned long *block, unsigned int bits, export unsigned int bfdev_comp_find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned int bits, unsigned int start, - unsigned long invert, bool swap) + unsigned long invert, bfdev_bool swap) { unsigned long value, mask; @@ -113,7 +113,7 @@ bfdev_comp_find_next_bit(const unsigned long *addr1, const unsigned long *addr2, export unsigned int bfdev_comp_find_prev_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned int bits, unsigned int start, - unsigned long invert, bool swap) + unsigned long invert, bfdev_bool swap) { unsigned long value, mask; diff --git a/src/bloom.c b/src/bloom.c index 391e01f8..8706e595 100644 --- a/src/bloom.c +++ b/src/bloom.c @@ -20,33 +20,33 @@ bloom_index(bfdev_bloom_t *bloom, unsigned int func, void *key) return index; } -export bool +export bfdev_bool bfdev_bloom_peek(bfdev_bloom_t *bloom, void *key) { unsigned int index, func; - bool retval; + bfdev_bool retval; - retval = true; + retval = bfdev_true; for (func = 0; func < bloom->funcs; ++func) { index = bloom_index(bloom, func, key); if (!bfdev_bit_test(bloom->bitmap, index)) - retval = false; + retval = bfdev_false; } return retval; } -export bool +export bfdev_bool bfdev_bloom_push(bfdev_bloom_t *bloom, void *key) { unsigned int index, func; - bool retval; + bfdev_bool retval; - retval = true; + retval = bfdev_true; for (func = 0; func < bloom->funcs; ++func) { index = bloom_index(bloom, func, key); if (!bfdev_bit_test_set(bloom->bitmap, index)) - retval = false; + retval = bfdev_false; } return retval; @@ -55,10 +55,10 @@ bfdev_bloom_push(bfdev_bloom_t *bloom, void *key) export void bfdev_bloom_flush(bfdev_bloom_t *bloom) { - size_t size; + bfdev_size_t size; size = BFDEV_BITS_WORD(bloom->capacity); - bfport_memset(bloom->bitmap, 0, size); + bfdev_memset(bloom->bitmap, 0, size); } export bfdev_bloom_t * @@ -66,14 +66,14 @@ bfdev_bloom_create(const bfdev_alloc_t *alloc, unsigned int capacity, bfdev_bloom_hash_t hash, unsigned int funcs, void *pdata) { bfdev_bloom_t *bloom; - size_t size; + bfdev_size_t size; bfdev_align_high_adj(capacity, BFDEV_BITS_PER_LONG); size = BFDEV_BITS_DIV_LONG(capacity); bloom = bfdev_zalloc(alloc, sizeof(*bloom) + sizeof(*bloom->bitmap) * size); if (bfdev_unlikely(!bloom)) - return NULL; + return BFDEV_NULL; bloom->capacity = capacity; bloom->alloc = alloc; diff --git a/src/bsearch.c b/src/bsearch.c index 2001bb3a..6ac69dc8 100644 --- a/src/bsearch.c +++ b/src/bsearch.c @@ -7,7 +7,7 @@ #include export void * -bfdev_bsearch(const void *base, size_t num, size_t esize, +bfdev_bsearch(const void *base, bfdev_size_t num, bfdev_size_t esize, bfdev_find_t find, void *pdata) { return bfdev_bsearch_inline(base, num, esize, find, pdata); diff --git a/src/btree-utils.c b/src/btree-utils.c index 0ce956be..2fadf68e 100644 --- a/src/btree-utils.c +++ b/src/btree-utils.c @@ -15,29 +15,32 @@ export bfdev_btree_layout_t bfdev_btree_layout32 = { .keylen = UINTPTR_PER_U32, - .keynum = NODE_SIZE / sizeof(uintptr_t) / (UINTPTR_PER_U32 + 1), - .ptrindex = UINTPTR_PER_U32 * (NODE_SIZE / sizeof(uintptr_t) / (UINTPTR_PER_U32 + 1)), + .keynum = NODE_SIZE / sizeof(bfdev_uintptr_t) / (UINTPTR_PER_U32 + 1), + .ptrindex = UINTPTR_PER_U32 * (NODE_SIZE / sizeof(bfdev_uintptr_t) / + (UINTPTR_PER_U32 + 1)), .nodesize = NODE_SIZE, }; export bfdev_btree_layout_t bfdev_btree_layout64 = { .keylen = UINTPTR_PER_U64, - .keynum = NODE_SIZE / sizeof(uintptr_t) / (UINTPTR_PER_U64 + 1), - .ptrindex = UINTPTR_PER_U64 * (NODE_SIZE / sizeof(uintptr_t) / (UINTPTR_PER_U64 + 1)), + .keynum = NODE_SIZE / sizeof(bfdev_uintptr_t) / (UINTPTR_PER_U64 + 1), + .ptrindex = UINTPTR_PER_U64 * (NODE_SIZE / sizeof(bfdev_uintptr_t) / + (UINTPTR_PER_U64 + 1)), .nodesize = NODE_SIZE, }; export bfdev_btree_layout_t bfdev_btree_layoutptr = { .keylen = 1, - .keynum = NODE_SIZE / sizeof(uintptr_t) / 2, - .ptrindex = NODE_SIZE / sizeof(uintptr_t) / 2, + .keynum = NODE_SIZE / sizeof(bfdev_uintptr_t) / 2, + .ptrindex = NODE_SIZE / sizeof(bfdev_uintptr_t) / 2, .nodesize = NODE_SIZE, }; export long -bfdev_btree_key_find(bfdev_btree_root_t *root, uintptr_t *node, uintptr_t *key) +bfdev_btree_key_find(bfdev_btree_root_t *root, bfdev_uintptr_t *node, + bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; unsigned int index; diff --git a/src/btree.c b/src/btree.c index 744c83de..6bf13513 100644 --- a/src/btree.c +++ b/src/btree.c @@ -30,10 +30,10 @@ bnode_set_value(bfdev_btree_root_t *root, bfdev_btree_node_t *node, layout = root->layout; offset = layout->ptrindex + index; - node->block[offset] = (uintptr_t)value; + node->block[offset] = (bfdev_uintptr_t)value; } -static __bfdev_always_inline uintptr_t * +static __bfdev_always_inline bfdev_uintptr_t * bnode_get_key(bfdev_btree_root_t *root, bfdev_btree_node_t *node, unsigned int index) { @@ -48,25 +48,25 @@ bnode_get_key(bfdev_btree_root_t *root, bfdev_btree_node_t *node, static __bfdev_always_inline void bnode_set_key(bfdev_btree_root_t *root, bfdev_btree_node_t *node, - unsigned int index, uintptr_t *key) + unsigned int index, bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; - uintptr_t *slot; - size_t size; + bfdev_uintptr_t *slot; + bfdev_size_t size; layout = root->layout; - size = layout->keylen * sizeof(uintptr_t); + size = layout->keylen * sizeof(bfdev_uintptr_t); slot = bnode_get_key(root, node, index); - bfport_memcpy(slot, key, size); + bfdev_memcpy(slot, key, size); } static inline long bnode_cmp_key(bfdev_btree_root_t *root, bfdev_btree_node_t *node, - unsigned int index, uintptr_t *key) + unsigned int index, bfdev_uintptr_t *key) { const bfdev_btree_ops_t *ops; - uintptr_t *slot; + bfdev_uintptr_t *slot; ops = root->ops; slot = bnode_get_key(root, node, index); @@ -76,17 +76,17 @@ bnode_cmp_key(bfdev_btree_root_t *root, bfdev_btree_node_t *node, static inline void bnode_takeout_key(bfdev_btree_root_t *root, bfdev_btree_node_t *node, - unsigned int index, uintptr_t *key) + unsigned int index, bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; - uintptr_t *slot; - size_t size; + bfdev_uintptr_t *slot; + bfdev_size_t size; layout = root->layout; - size = layout->keylen * sizeof(uintptr_t); + size = layout->keylen * sizeof(bfdev_uintptr_t); slot = bnode_get_key(root, node, index); - bfport_memcpy(key, slot, size); + bfdev_memcpy(key, slot, size); } static inline void @@ -94,19 +94,19 @@ bnode_clear_index(bfdev_btree_root_t *root, bfdev_btree_node_t *node, unsigned int index) { bfdev_btree_layout_t *layout; - uintptr_t *slot; - size_t size; + bfdev_uintptr_t *slot; + bfdev_size_t size; layout = root->layout; - size = layout->keylen * sizeof(uintptr_t); + size = layout->keylen * sizeof(bfdev_uintptr_t); - bnode_set_value(root, node, index, NULL); + bnode_set_value(root, node, index, BFDEV_NULL); slot = bnode_get_key(root, node, index); - bfport_memset(slot, 0, size); + bfdev_memset(slot, 0, size); } -static inline bool -btree_empty_key(bfdev_btree_root_t *root, uintptr_t *key) +static inline bfdev_bool +btree_empty_key(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; unsigned int count; @@ -114,10 +114,10 @@ btree_empty_key(bfdev_btree_root_t *root, uintptr_t *key) layout = root->layout; for (count = 0; count < layout->keylen; ++count) { if (key[count]) - return false; + return bfdev_false; } - return true; + return bfdev_true; } static inline void @@ -146,7 +146,7 @@ bnode_alloc(bfdev_btree_root_t *root) node = ops->alloc(root); if (bfdev_likely(node)) - bfport_memset(node, 0, layout->nodesize); + bfdev_memset(node, 0, layout->nodesize); return node; } @@ -179,7 +179,7 @@ bnode_fill_index(bfdev_btree_root_t *root, bfdev_btree_node_t *node, static unsigned int bnode_key_index(bfdev_btree_root_t *root, bfdev_btree_node_t *node, - uintptr_t *key) + bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; unsigned int index; @@ -198,7 +198,7 @@ bnode_key_index(bfdev_btree_root_t *root, bfdev_btree_node_t *node, } static bfdev_btree_node_t * -bnode_find_parent(bfdev_btree_root_t *root, uintptr_t *key, unsigned int level) +bnode_find_parent(bfdev_btree_root_t *root, bfdev_uintptr_t *key, unsigned int level) { bfdev_btree_layout_t *layout; bfdev_btree_node_t *node; @@ -224,7 +224,7 @@ bnode_find_parent(bfdev_btree_root_t *root, uintptr_t *key, unsigned int level) static unsigned int bnode_find_index(bfdev_btree_root_t *root, bfdev_btree_node_t *node, - uintptr_t *key) + bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; unsigned int index; @@ -239,7 +239,7 @@ bnode_find_index(bfdev_btree_root_t *root, bfdev_btree_node_t *node, } static bfdev_btree_node_t * -bnode_lookup(bfdev_btree_root_t *root, uintptr_t *key) +bnode_lookup(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; bfdev_btree_node_t *node; @@ -247,7 +247,7 @@ bnode_lookup(bfdev_btree_root_t *root, uintptr_t *key) height = root->height; if (!height) - return NULL; + return BFDEV_NULL; layout = root->layout; node = root->node; @@ -259,18 +259,18 @@ bnode_lookup(bfdev_btree_root_t *root, uintptr_t *key) } if (index == layout->keynum) - return NULL; + return BFDEV_NULL; node = bnode_get_value(root, node, index); if (!node) - return NULL; + return BFDEV_NULL; } return node; } export void * -bfdev_btree_lookup(bfdev_btree_root_t *root, uintptr_t *key) +bfdev_btree_lookup(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { bfdev_btree_layout_t *layout; bfdev_btree_node_t *node; @@ -278,19 +278,19 @@ bfdev_btree_lookup(bfdev_btree_root_t *root, uintptr_t *key) node = bnode_lookup(root, key); if (!node) - return NULL; + return BFDEV_NULL; layout = root->layout; index = bnode_key_index(root, node, key); if (index == layout->keynum) - return NULL; + return BFDEV_NULL; return bnode_get_value(root, node, index); } export int -bfdev_btree_update(bfdev_btree_root_t *root, uintptr_t *key, void *value) +bfdev_btree_update(bfdev_btree_root_t *root, bfdev_uintptr_t *key, void *value) { bfdev_btree_layout_t *layout; bfdev_btree_node_t *node; @@ -315,7 +315,7 @@ btree_extend(bfdev_btree_root_t *root) { bfdev_btree_node_t *node; unsigned int index; - uintptr_t *slot; + bfdev_uintptr_t *slot; node = bnode_alloc(root); if (bfdev_unlikely(!node)) @@ -351,13 +351,13 @@ btree_shrink(bfdev_btree_root_t *root) static int insert_level(bfdev_btree_root_t *root, unsigned int level, - uintptr_t *key, void *value) + bfdev_uintptr_t *key, void *value) { const bfdev_btree_ops_t *ops; bfdev_btree_layout_t *layout; bfdev_btree_node_t *node, *newn; unsigned int index, fill, count; - uintptr_t *halfkey; + bfdev_uintptr_t *halfkey; int retval; if (root->height < level) { @@ -421,7 +421,7 @@ insert_level(bfdev_btree_root_t *root, unsigned int level, } static void * -remove_level(bfdev_btree_root_t *root, unsigned int level, uintptr_t *key); +remove_level(bfdev_btree_root_t *root, unsigned int level, bfdev_uintptr_t *key); static void rebalance_merge(bfdev_btree_root_t *root, unsigned int level, @@ -442,7 +442,7 @@ rebalance_merge(bfdev_btree_root_t *root, unsigned int level, } static void -remove_rebalance(bfdev_btree_root_t *root, unsigned int level, uintptr_t *key, +remove_rebalance(bfdev_btree_root_t *root, unsigned int level, bfdev_uintptr_t *key, bfdev_btree_node_t *child, unsigned int fill) { bfdev_btree_layout_t *layout; @@ -485,7 +485,7 @@ remove_rebalance(bfdev_btree_root_t *root, unsigned int level, uintptr_t *key, } static void * -remove_level(bfdev_btree_root_t *root, unsigned int level, uintptr_t *key) +remove_level(bfdev_btree_root_t *root, unsigned int level, bfdev_uintptr_t *key) { const bfdev_btree_ops_t *ops; bfdev_btree_layout_t *layout; @@ -495,8 +495,8 @@ remove_level(bfdev_btree_root_t *root, unsigned int level, uintptr_t *key) if (level > root->height) { root->height = 0; - root->node = NULL; - return NULL; + root->node = BFDEV_NULL; + return BFDEV_NULL; } layout = root->layout; @@ -506,10 +506,10 @@ remove_level(bfdev_btree_root_t *root, unsigned int level, uintptr_t *key) index = bnode_find_index(root, node, key); last = bnode_fill_index(root, node, index) - 1; - value = NULL; + value = BFDEV_NULL; if (level == 1) { if (bnode_cmp_key(root, node, index, key)) - return NULL; + return BFDEV_NULL; value = bnode_get_value(root, node, index); if (ops->remove) { @@ -536,7 +536,7 @@ remove_level(bfdev_btree_root_t *root, unsigned int level, uintptr_t *key) } export int -bfdev_btree_insert(bfdev_btree_root_t *root, uintptr_t *key, void *value) +bfdev_btree_insert(bfdev_btree_root_t *root, bfdev_uintptr_t *key, void *value) { if (bfdev_unlikely(!value)) return -BFDEV_EINVAL; @@ -545,10 +545,10 @@ bfdev_btree_insert(bfdev_btree_root_t *root, uintptr_t *key, void *value) } export void * -bfdev_btree_remove(bfdev_btree_root_t *root, uintptr_t *key) +bfdev_btree_remove(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { if (bfdev_unlikely(!root->height)) - return NULL; + return BFDEV_NULL; return remove_level(root, 1, key); } @@ -558,12 +558,12 @@ bfdev_btree_release(bfdev_btree_root_t *root, bfdev_release_t release, void *pdata) { bfdev_btree_layout_t *layout; - uintptr_t *key, *tkey; + bfdev_uintptr_t *key, *tkey; void *value, *tval; layout = root->layout; - key = bfdev_alloca(sizeof(uintptr_t) * layout->keylen); - tkey = bfdev_alloca(sizeof(uintptr_t) * layout->keylen); + key = bfdev_alloca(sizeof(bfdev_uintptr_t) * layout->keylen); + tkey = bfdev_alloca(sizeof(bfdev_uintptr_t) * layout->keylen); bfdev_btree_for_each_safe(root, key, value, tkey, tval) { if (release) @@ -572,28 +572,29 @@ bfdev_btree_release(bfdev_btree_root_t *root, bfdev_release_t release, } bnode_free(root, root->node); - root->node = NULL; + root->node = BFDEV_NULL; root->height = 0; } export void -bfdev_btree_key_copy(bfdev_btree_root_t *root, uintptr_t *dest, uintptr_t *src) +bfdev_btree_key_copy(bfdev_btree_root_t *root, bfdev_uintptr_t *dest, + bfdev_uintptr_t *src) { bfdev_btree_layout_t *layout; layout = root->layout; - bfport_memcpy(dest, src, layout->keylen * sizeof(uintptr_t)); + bfdev_memcpy(dest, src, layout->keylen * sizeof(bfdev_uintptr_t)); } export void * -bfdev_btree_first(bfdev_btree_root_t *root, uintptr_t *key) +bfdev_btree_first(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { bfdev_btree_node_t *node; unsigned int height; height = root->height; if (!height) - return NULL; + return BFDEV_NULL; node = root->node; while (--height) @@ -604,14 +605,14 @@ bfdev_btree_first(bfdev_btree_root_t *root, uintptr_t *key) } export void * -bfdev_btree_last(bfdev_btree_root_t *root, uintptr_t *key) +bfdev_btree_last(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { bfdev_btree_node_t *node; unsigned int last, height; height = root->height; if (!height) - return NULL; + return BFDEV_NULL; node = root->node; while (--height) { @@ -625,7 +626,7 @@ bfdev_btree_last(bfdev_btree_root_t *root, uintptr_t *key) } export void * -bfdev_btree_next(bfdev_btree_root_t *root, uintptr_t *key) +bfdev_btree_next(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { bfdev_btree_node_t *node; unsigned int depth, index, fill; @@ -633,10 +634,10 @@ bfdev_btree_next(bfdev_btree_root_t *root, uintptr_t *key) height = root->height; if (bfdev_unlikely(!height)) - return NULL; + return BFDEV_NULL; if (btree_empty_key(root, key)) - return NULL; + return BFDEV_NULL; for (depth = 1; depth <= height; ++depth) { node = bnode_find_parent(root, key, depth); @@ -647,7 +648,7 @@ bfdev_btree_next(bfdev_btree_root_t *root, uintptr_t *key) } if (depth > height) - return NULL; + return BFDEV_NULL; while (--depth) { node = bnode_get_value(root, node, index); @@ -659,7 +660,7 @@ bfdev_btree_next(bfdev_btree_root_t *root, uintptr_t *key) } export void * -bfdev_btree_prev(bfdev_btree_root_t *root, uintptr_t *key) +bfdev_btree_prev(bfdev_btree_root_t *root, bfdev_uintptr_t *key) { bfdev_btree_node_t *node; unsigned int depth, index; @@ -667,10 +668,10 @@ bfdev_btree_prev(bfdev_btree_root_t *root, uintptr_t *key) height = root->height; if (bfdev_unlikely(!height)) - return NULL; + return BFDEV_NULL; if (btree_empty_key(root, key)) - return NULL; + return BFDEV_NULL; for (depth = 1; depth <= height; ++depth) { node = bnode_find_parent(root, key, depth); @@ -680,7 +681,7 @@ bfdev_btree_prev(bfdev_btree_root_t *root, uintptr_t *key) } if (depth > height) - return NULL; + return BFDEV_NULL; while (--depth) { node = bnode_get_value(root, node, index); diff --git a/src/build.cmake b/src/build.cmake index e0f357ae..2051c601 100644 --- a/src/build.cmake +++ b/src/build.cmake @@ -95,4 +95,5 @@ include(${CMAKE_CURRENT_LIST_DIR}/cache/build.cmake) include(${CMAKE_CURRENT_LIST_DIR}/crypto/build.cmake) include(${CMAKE_CURRENT_LIST_DIR}/libc/build.cmake) include(${CMAKE_CURRENT_LIST_DIR}/log/build.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/port/build.cmake) include(${CMAKE_CURRENT_LIST_DIR}/textsearch/build.cmake) diff --git a/src/cache/cache.c b/src/cache/cache.c index 71ab16a6..8f5c10c8 100644 --- a/src/cache/cache.c +++ b/src/cache/cache.c @@ -18,27 +18,27 @@ cache_algorithm_find(const char *name) bfdev_cache_algo_t *walk; bfdev_list_for_each_entry(walk, &cache_algorithms, list) { - if (!bfport_strcmp(walk->name, name)) + if (!bfdev_strcmp(walk->name, name)) return walk; } - return NULL; + return BFDEV_NULL; } -static bool +static bfdev_bool cache_algorithm_exist(bfdev_cache_algo_t *algo) { bfdev_cache_algo_t *walk; bfdev_list_for_each_entry(walk, &cache_algorithms, list) { if (walk == algo) - return true; + return bfdev_true; } - return false; + return bfdev_false; } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool cache_starving(bfdev_cache_head_t *head) { return bfdev_list_check_empty(&head->freed) && head->algo->starving(head); @@ -56,7 +56,7 @@ cache_hash(bfdev_cache_head_t *head, const void *tag) return hash; } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool cache_find(bfdev_cache_head_t *head, bfdev_cache_node_t *node, const char *tag) { const bfdev_cache_ops_t *ops; @@ -70,7 +70,7 @@ cache_find(bfdev_cache_head_t *head, bfdev_cache_node_t *node, const char *tag) /* Find in changing, using or algos */ static bfdev_cache_node_t * -cache_lookup(bfdev_cache_head_t *head, const char *tag, bool change) +cache_lookup(bfdev_cache_head_t *head, const char *tag, bfdev_bool change) { bfdev_cache_node_t *walk; unsigned long hash, index; @@ -88,7 +88,7 @@ cache_lookup(bfdev_cache_head_t *head, const char *tag, bool change) break; } - return NULL; + return BFDEV_NULL; } /* Insert to from */ @@ -135,7 +135,7 @@ cache_obtain(bfdev_cache_head_t *head, const char *tag) export bfdev_cache_node_t * bfdev_cache_find(bfdev_cache_head_t *head, const void *tag) { - return cache_lookup(head, tag, false); + return cache_lookup(head, tag, bfdev_false); } export bfdev_cache_node_t * @@ -146,16 +146,16 @@ bfdev_cache_obtain(bfdev_cache_head_t *head, const void *tag, unsigned long flag if (bfdev_unlikely(bfdev_cache_starving_test(head))) { head->starve++; - return NULL; + return BFDEV_NULL; } - node = cache_lookup(head, tag, true); + node = cache_lookup(head, tag, bfdev_true); if (bfdev_likely(node)) { head->hits++; if (node->status == BFDEV_CACHE_PENDING) { if (!bfdev_cache_uncommitted_test(&flags)) - return NULL; + return BFDEV_NULL; node->refcnt++; return node; @@ -179,16 +179,16 @@ bfdev_cache_obtain(bfdev_cache_head_t *head, const void *tag, unsigned long flag head->misses++; if (!bfdev_cache_change_test(&flags)) - return NULL; + return BFDEV_NULL; bfdev_cache_dirty_set(head); if (bfdev_unlikely(cache_starving(head))) { bfdev_cache_starving_set(head); - return NULL; + return BFDEV_NULL; } if (bfdev_unlikely(head->pending >= head->maxpend)) - return NULL; + return BFDEV_NULL; node = cache_obtain(head, tag); BFDEV_BUG_ON(!node); @@ -292,7 +292,7 @@ bfdev_cache_reset(bfdev_cache_head_t *head) bfdev_list_head_init(&head->changing); head->algo->reset(head); - bfport_memset(head->taghash, 0, sizeof(*head->taghash) * head->size); + bfdev_memset(head->taghash, 0, sizeof(*head->taghash) * head->size); for (count = 0; count < head->size; ++count) { node = head->nodes[count]; @@ -310,19 +310,19 @@ bfdev_cache_create(const char *name, const bfdev_alloc_t *alloc, unsigned long count; if (!ops->hash || !ops->find) - return NULL; + return BFDEV_NULL; size = bfdev_pow2_roundup(size); if (bfdev_unlikely(size < 2)) - return NULL; + return BFDEV_NULL; algo = cache_algorithm_find(name); if (bfdev_unlikely(!algo)) - return NULL; + return BFDEV_NULL; head = algo->create(alloc, size); if (bfdev_unlikely(!head)) - return NULL; + return BFDEV_NULL; head->algo = algo; head->alloc = alloc; @@ -335,7 +335,7 @@ bfdev_cache_create(const char *name, const bfdev_alloc_t *alloc, head->taghash = bfdev_zalloc_array(alloc, size, sizeof(*head->taghash)); if (bfdev_unlikely(!head->taghash)) { algo->destroy(head); - return NULL; + return BFDEV_NULL; } bfdev_list_head_init(&head->using); diff --git a/src/cache/lfu.c b/src/cache/lfu.c index cb03e173..1c795934 100644 --- a/src/cache/lfu.c +++ b/src/cache/lfu.c @@ -42,7 +42,7 @@ lfu_compare(const bfdev_heap_node_t *node1, return bfdev_cmp(lfu1->count > lfu2->count); } -static bool +static bfdev_bool lfu_starving(bfdev_cache_head_t *head) { struct lfu_head *lfu_head; @@ -59,8 +59,9 @@ lfu_obtain(bfdev_cache_head_t *head) struct lfu_node *lfu_node; lfu_head = cache_to_lfu_head(head); - lfu_node = bfdev_heap_entry(BFDEV_HEAP_ROOT_NODE(&lfu_head->lfu), struct lfu_node, node); - bfdev_heap_delete(&lfu_head->lfu, &lfu_node->node, lfu_compare, NULL); + lfu_node = bfdev_heap_entry(BFDEV_HEAP_ROOT_NODE(&lfu_head->lfu), + struct lfu_node, node); + bfdev_heap_delete(&lfu_head->lfu, &lfu_node->node, lfu_compare, BFDEV_NULL); return &lfu_node->cache; } @@ -74,7 +75,8 @@ lfu_get(bfdev_cache_head_t *head, bfdev_cache_node_t *node) lfu_head = cache_to_lfu_head(head); lfu_node = cache_to_lfu_node(node); - bfdev_heap_delete(&lfu_head->lfu, &lfu_node->node, lfu_compare, NULL); + bfdev_heap_delete(&lfu_head->lfu, &lfu_node->node, + lfu_compare, BFDEV_NULL); } static void @@ -86,7 +88,8 @@ lfu_put(bfdev_cache_head_t *head, bfdev_cache_node_t *node) lfu_head = cache_to_lfu_head(head); lfu_node = cache_to_lfu_node(node); - bfdev_heap_insert(&lfu_head->lfu, &lfu_node->node, lfu_compare, NULL); + bfdev_heap_insert(&lfu_head->lfu, &lfu_node->node, + lfu_compare, BFDEV_NULL); } static void @@ -134,7 +137,7 @@ lfu_create(const bfdev_alloc_t *alloc, unsigned long size) lfu_head = bfdev_zalloc(alloc, sizeof(*lfu_head)); if (bfdev_unlikely(!lfu_head)) - return NULL; + return BFDEV_NULL; head = &lfu_head->cache; bfdev_heap_init(&lfu_head->lfu); @@ -162,7 +165,7 @@ lfu_create(const bfdev_alloc_t *alloc, unsigned long size) free_head: bfdev_free(alloc, head); - return NULL; + return BFDEV_NULL; } static void diff --git a/src/cache/lru.c b/src/cache/lru.c index b1b77aa9..2e42c42a 100644 --- a/src/cache/lru.c +++ b/src/cache/lru.c @@ -22,7 +22,7 @@ struct lru_node { #define cache_to_lru_node(ptr) \ bfdev_container_of(ptr, struct lru_node, cache) -static bool +static bfdev_bool lru_starving(bfdev_cache_head_t *head) { struct lru_head *lru_head; @@ -87,7 +87,7 @@ lru_create(const bfdev_alloc_t *alloc, unsigned long size) lru_head = bfdev_zalloc(alloc, sizeof(*lru_head)); if (bfdev_unlikely(!lru_head)) - return NULL; + return BFDEV_NULL; head = &lru_head->cache; bfdev_list_head_init(&lru_head->lru); @@ -115,7 +115,7 @@ lru_create(const bfdev_alloc_t *alloc, unsigned long size) free_head: bfdev_free(alloc, head); - return NULL; + return BFDEV_NULL; } static void diff --git a/src/crypto/arc4.c b/src/crypto/arc4.c index f6c88c93..1f5de101 100644 --- a/src/crypto/arc4.c +++ b/src/crypto/arc4.c @@ -8,12 +8,12 @@ #include static __bfdev_always_inline void -arc4_transform(bfdev_arc4_ctx_t *ctx, uint8_t *buff, - const uint8_t *data, size_t size) +arc4_transform(bfdev_arc4_ctx_t *ctx, bfdev_u8 *buff, + const bfdev_u8 *data, bfdev_size_t size) { - uint8_t proa, prob; - uint8_t tx, ty, tb; - uint8_t vx, vy; + bfdev_u8 proa, prob; + bfdev_u8 tx, ty, tb; + bfdev_u8 vx, vy; proa = ctx->proa; prob = ctx->prob; @@ -47,7 +47,7 @@ arc4_transform(bfdev_arc4_ctx_t *ctx, uint8_t *buff, export void bfdev_arc4_trans(bfdev_arc4_ctx_t *ctx, void *buff, - const void *data, size_t size) + const void *data, bfdev_size_t size) { if (bfdev_unlikely(!size)) return; @@ -57,9 +57,9 @@ bfdev_arc4_trans(bfdev_arc4_ctx_t *ctx, void *buff, export void bfdev_arc4_setkey(bfdev_arc4_ctx_t *ctx, - const uint8_t *key, unsigned int klen) + const bfdev_u8 *key, unsigned int klen) { - uint8_t value, loop; + bfdev_u8 value, loop; unsigned int count; if (bfdev_unlikely(!klen)) diff --git a/src/crypto/ascii85.c b/src/crypto/ascii85.c index 965e4a1a..a6a6d603 100644 --- a/src/crypto/ascii85.c +++ b/src/crypto/ascii85.c @@ -11,10 +11,11 @@ #include static __bfdev_always_inline void -ascii85_encode(uint8_t *buff, const void *data, size_t *plen, size_t size) +ascii85_encode(bfdev_u8 *buff, const void *data, bfdev_size_t *plen, + bfdev_size_t size) { - uint32_t value; - size_t index; + bfdev_u32 value; + bfdev_size_t index; for (index = 0; size >= 4; size -= 4) { value = bfdev_unaligned_get_be32(data); @@ -36,7 +37,8 @@ ascii85_encode(uint8_t *buff, const void *data, size_t *plen, size_t size) if (size) { value = bfdev_unaligned_get_be32(data); - value &= BFDEV_BIT_HIGH_MASK((BFDEV_BYTES_PER_U32 - size) * BFDEV_BITS_PER_BYTE); + value &= BFDEV_BIT_HIGH_MASK((BFDEV_BYTES_PER_U32 - size) * + BFDEV_BITS_PER_BYTE); if (!value) buff[index] = 'z'; @@ -56,15 +58,16 @@ ascii85_encode(uint8_t *buff, const void *data, size_t *plen, size_t size) } static __bfdev_always_inline int -ascii85_decode(void *buff, const uint8_t *data, size_t *plen, size_t size) +ascii85_decode(void *buff, const bfdev_u8 *data, bfdev_size_t *plen, + bfdev_size_t size) { unsigned int count; - uint32_t value; - size_t index; + bfdev_u32 value; + bfdev_size_t index; for (index = 0; size; index += 4) { if (*data == 'z') { - bfport_memset(buff + index, 0, 4); + bfdev_memset(buff + index, 0, 4); data++; size--; } @@ -96,13 +99,15 @@ ascii85_decode(void *buff, const uint8_t *data, size_t *plen, size_t size) } export void -bfdev_ascii85_encode(void *buff, const void *data, size_t *plen, size_t size) +bfdev_ascii85_encode(void *buff, const void *data, + bfdev_size_t *plen, bfdev_size_t size) { ascii85_encode(buff, data, plen, size); } export int -bfdev_ascii85_decode(void *buff, const void *data, size_t *plen, size_t size) +bfdev_ascii85_decode(void *buff, const void *data, + bfdev_size_t *plen, bfdev_size_t size) { return ascii85_decode(buff, data, plen, size); } diff --git a/src/crypto/base32.c b/src/crypto/base32.c index c0f90dbe..59dc56a8 100644 --- a/src/crypto/base32.c +++ b/src/crypto/base32.c @@ -7,7 +7,7 @@ #include #include -static const uint8_t +static const bfdev_u8 base32_encode_table[32] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', @@ -15,7 +15,7 @@ base32_encode_table[32] = { 'Y', 'Z', '2', '3', '4', '5', '6', '7', }; -static const uint8_t +static const bfdev_u8 base32_decode_table[256] = { [0 ... 255] = 0xff, ['A'] = 0x00, ['B'] = 0x01, ['C'] = 0x02, ['D'] = 0x03, @@ -29,9 +29,9 @@ base32_decode_table[256] = { }; static __bfdev_always_inline void -base32_encode(uint8_t *buff, const uint8_t *data, size_t size) +base32_encode(bfdev_u8 *buff, const bfdev_u8 *data, bfdev_size_t size) { - const uint8_t *prev; + const bfdev_u8 *prev; unsigned int bstate; prev = data; @@ -114,10 +114,10 @@ base32_encode(uint8_t *buff, const uint8_t *data, size_t size) } static __bfdev_always_inline int -base32_decode(uint8_t *buff, const uint8_t *data, size_t size) +base32_decode(bfdev_u8 *buff, const bfdev_u8 *data, bfdev_size_t size) { unsigned int bstate; - uint8_t decode; + bfdev_u8 decode; bstate = 0; while (size--) { @@ -172,13 +172,13 @@ base32_decode(uint8_t *buff, const uint8_t *data, size_t size) } export void -bfdev_base32_encode(void *buff, const void *data, size_t size) +bfdev_base32_encode(void *buff, const void *data, bfdev_size_t size) { base32_encode(buff, data, size); } export int -bfdev_base32_decode(void *buff, const void *data, size_t size) +bfdev_base32_decode(void *buff, const void *data, bfdev_size_t size) { return base32_decode(buff, data, size); } diff --git a/src/crypto/base64.c b/src/crypto/base64.c index ca18446b..9756b7c9 100644 --- a/src/crypto/base64.c +++ b/src/crypto/base64.c @@ -7,7 +7,7 @@ #include #include -static const uint8_t +static const bfdev_u8 base64_encode_table[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', @@ -19,7 +19,7 @@ base64_encode_table[64] = { '4', '5', '6', '7', '8', '9', '+', '/', }; -static const uint8_t +static const bfdev_u8 base64_decode_table[256] = { [0 ... 255] = 0xff, ['A'] = 0x00, ['B'] = 0x01, ['C'] = 0x02, ['D'] = 0x03, @@ -41,9 +41,9 @@ base64_decode_table[256] = { }; static __bfdev_always_inline void -base64_encode(uint8_t *buff, const uint8_t *data, size_t size) +base64_encode(bfdev_u8 *buff, const bfdev_u8 *data, bfdev_size_t size) { - const uint8_t *prev; + const bfdev_u8 *prev; unsigned int bstate; prev = data; @@ -91,10 +91,10 @@ base64_encode(uint8_t *buff, const uint8_t *data, size_t size) } static __bfdev_always_inline int -base64_decode(uint8_t *buff, const uint8_t *data, size_t size) +base64_decode(bfdev_u8 *buff, const bfdev_u8 *data, bfdev_size_t size) { unsigned int bstate; - uint8_t decode; + bfdev_u8 decode; bstate = 0; while (size--) { @@ -131,13 +131,13 @@ base64_decode(uint8_t *buff, const uint8_t *data, size_t size) } export void -bfdev_base64_encode(void *buff, const void *data, size_t size) +bfdev_base64_encode(void *buff, const void *data, bfdev_size_t size) { base64_encode(buff, data, size); } export int -bfdev_base64_decode(void *buff, const void *data, size_t size) +bfdev_base64_decode(void *buff, const void *data, bfdev_size_t size) { return base64_decode(buff, data, size); } diff --git a/src/crypto/crc-ccitt.c b/src/crypto/crc-ccitt.c index b6922b94..cd590938 100644 --- a/src/crypto/crc-ccitt.c +++ b/src/crypto/crc-ccitt.c @@ -7,8 +7,8 @@ #include #include -export uint16_t -bfdev_crc_ccitt(const void *data, size_t len, uint16_t crc) +export bfdev_u16 +bfdev_crc_ccitt(const void *data, bfdev_size_t len, bfdev_u16 crc) { return bfdev_crc_ccitt_inline(data, len, crc); } diff --git a/src/crypto/crc-itut.c b/src/crypto/crc-itut.c index 99449d60..78223b9e 100644 --- a/src/crypto/crc-itut.c +++ b/src/crypto/crc-itut.c @@ -7,8 +7,8 @@ #include #include -export uint16_t -bfdev_crc_itut(const void *data, size_t len, uint16_t crc) +export bfdev_u16 +bfdev_crc_itut(const void *data, bfdev_size_t len, bfdev_u16 crc) { return bfdev_crc_itut_inline(data, len, crc); } diff --git a/src/crypto/crc-rocksoft.c b/src/crypto/crc-rocksoft.c index b2adec2f..b8aa47cc 100644 --- a/src/crypto/crc-rocksoft.c +++ b/src/crypto/crc-rocksoft.c @@ -7,8 +7,8 @@ #include #include -export uint64_t -bfdev_crc_rocksoft(const void *data, size_t len, uint64_t crc) +export bfdev_u64 +bfdev_crc_rocksoft(const void *data, bfdev_size_t len, bfdev_u64 crc) { return bfdev_crc_rocksoft_inline(data, len, crc); } diff --git a/src/crypto/crc-t10dif.c b/src/crypto/crc-t10dif.c index fab0dad7..58d29167 100644 --- a/src/crypto/crc-t10dif.c +++ b/src/crypto/crc-t10dif.c @@ -7,8 +7,8 @@ #include #include -export uint16_t -bfdev_crc_t10dif(const void *data, size_t len, uint16_t crc) +export bfdev_u16 +bfdev_crc_t10dif(const void *data, bfdev_size_t len, bfdev_u16 crc) { return bfdev_crc_t10dif_inline(data, len, crc); } diff --git a/src/crypto/crc16.c b/src/crypto/crc16.c index 4f01ae0a..29150d6a 100644 --- a/src/crypto/crc16.c +++ b/src/crypto/crc16.c @@ -7,8 +7,8 @@ #include #include -export uint16_t -bfdev_crc16(const void *data, size_t len, uint16_t crc) +export bfdev_u16 +bfdev_crc16(const void *data, bfdev_size_t len, bfdev_u16 crc) { return bfdev_crc16_inline(data, len, crc); } diff --git a/src/crypto/crc32.c b/src/crypto/crc32.c index ca50f3c9..a2f947e9 100644 --- a/src/crypto/crc32.c +++ b/src/crypto/crc32.c @@ -7,8 +7,8 @@ #include #include -export uint32_t -bfdev_crc32(const void *data, size_t len, uint32_t crc) +export bfdev_u32 +bfdev_crc32(const void *data, bfdev_size_t len, bfdev_u32 crc) { return bfdev_crc32_inline(data, len, crc); } diff --git a/src/crypto/crc4.c b/src/crypto/crc4.c index f32568db..f02e874f 100644 --- a/src/crypto/crc4.c +++ b/src/crypto/crc4.c @@ -7,8 +7,8 @@ #include #include -export uint8_t -bfdev_crc4(const void *data, size_t len, uint8_t crc) +export bfdev_u8 +bfdev_crc4(const void *data, bfdev_size_t len, bfdev_u8 crc) { return bfdev_crc4_inline(data, len, crc); } diff --git a/src/crypto/crc64.c b/src/crypto/crc64.c index f2aadf52..11f3f209 100644 --- a/src/crypto/crc64.c +++ b/src/crypto/crc64.c @@ -7,8 +7,8 @@ #include #include -export uint64_t -bfdev_crc64(const void *data, size_t len, uint64_t crc) +export bfdev_u64 +bfdev_crc64(const void *data, bfdev_size_t len, bfdev_u64 crc) { return bfdev_crc64_inline(data, len, crc); } diff --git a/src/crypto/crc7.c b/src/crypto/crc7.c index 69f376a0..32d07abb 100644 --- a/src/crypto/crc7.c +++ b/src/crypto/crc7.c @@ -7,8 +7,8 @@ #include #include -export uint8_t -bfdev_crc7(const void *data, size_t len, uint8_t crc) +export bfdev_u8 +bfdev_crc7(const void *data, bfdev_size_t len, bfdev_u8 crc) { return bfdev_crc7_inline(data, len, crc); } diff --git a/src/crypto/crc8.c b/src/crypto/crc8.c index f576de79..88142496 100644 --- a/src/crypto/crc8.c +++ b/src/crypto/crc8.c @@ -7,8 +7,8 @@ #include #include -export uint8_t -bfdev_crc8(const void *data, size_t len, uint8_t crc) +export bfdev_u8 +bfdev_crc8(const void *data, bfdev_size_t len, bfdev_u8 crc) { return bfdev_crc8_inline(data, len, crc); } diff --git a/src/crypto/md5.c b/src/crypto/md5.c index 87096ba2..d6f4f2cb 100644 --- a/src/crypto/md5.c +++ b/src/crypto/md5.c @@ -12,13 +12,13 @@ static inline void md5_transform_block(bfdev_md5_ctx_t *ctx) { - bfdev_le32_to_cpu_array(ctx->block, (bfdev_le32 *)ctx->block, + bfdev_le32_to_cpu_array(ctx->block, (bfdev_le32 *)ctx->block, sizeof(ctx->block) / BFDEV_BYTES_PER_U32); - bfdev_md5_transform(ctx->digest, ctx->block); + bfdev_md5_transform(ctx->digest, ctx->block); } export void -bfdev_md5_update(bfdev_md5_ctx_t *ctx, const char *data, size_t size) +bfdev_md5_update(bfdev_md5_ctx_t *ctx, const char *data, bfdev_size_t size) { bfdev_md5_base_update(ctx, data, size, md5_transform_block); } diff --git a/src/crypto/sha1.c b/src/crypto/sha1.c index 30d4ecac..142a4071 100644 --- a/src/crypto/sha1.c +++ b/src/crypto/sha1.c @@ -10,9 +10,9 @@ #include static void -sha1_transform_block(bfdev_sha1_ctx_t *ctx, const void *src, size_t blocks) +sha1_transform_block(bfdev_sha1_ctx_t *ctx, const void *src, bfdev_size_t blocks) { - uint32_t buffer[BFDEV_SHA1_WORKSPACE_WORDS]; + bfdev_u32 buffer[BFDEV_SHA1_WORKSPACE_WORDS]; while (blocks--) { bfdev_sha1_transform(ctx->state, buffer, src); @@ -21,7 +21,7 @@ sha1_transform_block(bfdev_sha1_ctx_t *ctx, const void *src, size_t blocks) } export void -bfdev_sha1_update(bfdev_sha1_ctx_t *ctx, const void *data, size_t size) +bfdev_sha1_update(bfdev_sha1_ctx_t *ctx, const void *data, bfdev_size_t size) { bfdev_sha1_base_update(ctx, data, size, sha1_transform_block); } diff --git a/src/crypto/sha2.c b/src/crypto/sha2.c index 95165a16..710330c8 100644 --- a/src/crypto/sha2.c +++ b/src/crypto/sha2.c @@ -10,9 +10,9 @@ #include static void -sha2_transform_block(bfdev_sha2_ctx_t *ctx, const void *src, size_t blocks) +sha2_transform_block(bfdev_sha2_ctx_t *ctx, const void *src, bfdev_size_t blocks) { - uint32_t buffer[BFDEV_SHA2_WORKSPACE_WORDS]; + bfdev_u32 buffer[BFDEV_SHA2_WORKSPACE_WORDS]; while (blocks--) { bfdev_sha2_transform(ctx->state, buffer, src); @@ -21,7 +21,7 @@ sha2_transform_block(bfdev_sha2_ctx_t *ctx, const void *src, size_t blocks) } export void -bfdev_sha2_update(bfdev_sha2_ctx_t *ctx, const void *data, size_t size) +bfdev_sha2_update(bfdev_sha2_ctx_t *ctx, const void *data, bfdev_size_t size) { bfdev_sha2_base_update(ctx, data, size, sha2_transform_block); } diff --git a/src/errname.c b/src/errname.c index 79a8bced..ba818572 100644 --- a/src/errname.c +++ b/src/errname.c @@ -136,7 +136,7 @@ errname_search(const void *key, void *pdata) int value; entry = key; - value = (intptr_t)pdata; + value = (bfdev_intptr_t)pdata; if (entry->errnum == value) return BFDEV_EQ; @@ -154,7 +154,7 @@ bfdev_errname_find(int error) entry = bfdev_bsearch( bfdev_errname_table, BFDEV_ARRAY_SIZE(bfdev_errname_table) - 1, - sizeof(*entry), errname_search, (void *)(intptr_t)(error) + sizeof(*entry), errname_search, (void *)(bfdev_intptr_t)(error) ); return entry; @@ -168,7 +168,7 @@ bfdev_errname(int error, const char **infop) entry = bfdev_errname_find(error); if (bfdev_unlikely(!entry)) - return NULL; + return BFDEV_NULL; if (infop) *infop = entry->info; diff --git a/src/fifo.c b/src/fifo.c index ec1adc4d..d53d1a6e 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -23,8 +23,8 @@ } \ \ llen = bfdev_min(len, size - offset); \ - bfport_memcpy(copy1, copy2, llen); \ - bfport_memcpy(fold1, fold2, len - llen); \ + bfdev_memcpy(copy1, copy2, llen); \ + bfdev_memcpy(fold1, fold2, len - llen); \ } while (0) static __bfdev_always_inline void @@ -51,7 +51,7 @@ static __bfdev_always_inline unsigned long fifo_record_peek(bfdev_fifo_t *fifo, unsigned long recsize) { unsigned long mask, offset, length; - uint8_t *data; + bfdev_u8 *data; mask = fifo->mask; offset = fifo->out; @@ -77,7 +77,7 @@ static __bfdev_always_inline void fifo_record_poke(bfdev_fifo_t *fifo, unsigned long len, unsigned long recsize) { unsigned long mask, offset; - uint8_t *data; + bfdev_u8 *data; mask = fifo->mask; offset = fifo->out; @@ -90,13 +90,13 @@ fifo_record_poke(bfdev_fifo_t *fifo, unsigned long len, unsigned long recsize) } while (recsize--) { - data[offset & mask] = (uint8_t)len; + data[offset & mask] = (bfdev_u8)len; offset += fifo->esize; len >>= BFDEV_BITS_PER_U8; } } -static inline bool +static inline bfdev_bool fifo_empty(bfdev_fifo_t *fifo) { return fifo->in == fifo->out; @@ -199,7 +199,7 @@ bfdev_fifo_in_record(bfdev_fifo_t *fifo, const void *buff, unsigned long len, export int bfdev_fifo_dynamic_alloc(bfdev_fifo_t *fifo, const bfdev_alloc_t *alloc, - size_t esize, size_t size) + bfdev_size_t esize, bfdev_size_t size) { size = bfdev_pow2_roundup(size); if (size < 2) @@ -230,5 +230,5 @@ bfdev_fifo_dynamic_free(bfdev_fifo_t *fifo) alloc = fifo->alloc; bfdev_free(alloc, fifo->data); - fifo->data = NULL; + fifo->data = BFDEV_NULL; } diff --git a/src/fsm.c b/src/fsm.c index 2ed65319..84ebf6af 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -34,7 +34,7 @@ fsm_find_transition(const bfdev_fsm_state_t *state, bfdev_fsm_event_t *event) if (state->exception) return state->exception(event, state->data); - return NULL; + return BFDEV_NULL; } export int diff --git a/src/glob.c b/src/glob.c index 8d763d4c..dca621f5 100644 --- a/src/glob.c +++ b/src/glob.c @@ -7,15 +7,15 @@ #include #include -export bool +export bfdev_bool bfdev_glob(const char *patten, const char *string) { const char *class, *bpatten, *bstring; char ptch, stch, tcha, tchb; - bool match, inverted; + bfdev_bool match, inverted; - bpatten = NULL; - bstring = NULL; + bpatten = BFDEV_NULL; + bstring = BFDEV_NULL; for (;;) { ptch = *patten++; @@ -24,18 +24,18 @@ bfdev_glob(const char *patten, const char *string) switch (ptch) { case '?': if (stch == '\0') - return false; + return bfdev_false; break; case '*': if (*patten == '\0') - return true; + return bfdev_true; bpatten = patten; bstring = --string; break; case '[': - match = false; + match = bfdev_false; inverted = *patten == '!'; class = patten + inverted; tcha = *class++; @@ -67,13 +67,13 @@ bfdev_glob(const char *patten, const char *string) default: literal: if (ptch == stch) { if (ptch == '\0') - return true; + return bfdev_true; break; } backtrack: if (stch == '\0' || !bpatten) - return false; + return bfdev_false; patten = bpatten; string = ++bstring; diff --git a/src/hashmap.c b/src/hashmap.c index 748147a2..9e700a13 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -59,13 +59,13 @@ hashmap_find(bfdev_hashmap_t *hashmap, const void *key, return retval; } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool hashmap_need_extend(bfdev_hashmap_t *hashmap) { const bfdev_hashmap_ops_t *ops; if (!hashmap->capacity) - return true; + return bfdev_true; ops = hashmap->ops; if (ops->extend) @@ -75,7 +75,7 @@ hashmap_need_extend(bfdev_hashmap_t *hashmap) return hashmap->used * 4 / 3 > hashmap->capacity; } -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool hashmap_need_shrink(bfdev_hashmap_t *hashmap) { const bfdev_hashmap_ops_t *ops; @@ -96,7 +96,7 @@ hashmap_find_node(bfdev_hashmap_t *hashmap, const bfdev_hlist_node_t *node, unsigned long index; if (!hashmap->buckets) - return NULL; + return BFDEV_NULL; index = bfdev_hashtbl_index(hashmap->capacity, hash); bfdev_hashtbl_for_each_idx(walk, hashmap->buckets, hashmap->capacity, index) { @@ -104,7 +104,7 @@ hashmap_find_node(bfdev_hashmap_t *hashmap, const bfdev_hlist_node_t *node, return walk; } - return NULL; + return BFDEV_NULL; } static inline bfdev_hlist_node_t * @@ -115,7 +115,7 @@ hashmap_find_key(bfdev_hashmap_t *hashmap, const void *key, unsigned long index; if (!hashmap->buckets) - return NULL; + return BFDEV_NULL; index = bfdev_hashtbl_index(hashmap->capacity, hash); bfdev_hashtbl_for_each_idx(walk, hashmap->buckets, hashmap->capacity, index) { @@ -123,7 +123,7 @@ hashmap_find_key(bfdev_hashmap_t *hashmap, const void *key, return walk; } - return NULL; + return BFDEV_NULL; } static inline int @@ -260,7 +260,7 @@ bfdev_hashmap_release(bfdev_hashmap_t *hashmap) alloc = hashmap->alloc; bfdev_free(alloc, hashmap->buckets); - hashmap->buckets = NULL; + hashmap->buckets = BFDEV_NULL; hashmap->used = 0; hashmap->capacity = 0; diff --git a/src/heap-debug.c b/src/heap-debug.c index 316f36cb..9352eace 100644 --- a/src/heap-debug.c +++ b/src/heap-debug.c @@ -11,7 +11,7 @@ #include #include -export bool +export bfdev_bool bfdev_heap_check_link(bfdev_heap_node_t *parent, bfdev_heap_node_t **link, bfdev_heap_node_t *node) { @@ -21,13 +21,13 @@ bfdev_heap_check_link(bfdev_heap_node_t *parent, bfdev_heap_node_t **link, " should not be node (%p)\n", link, node ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_heap_check_delete(bfdev_heap_node_t *node) { if (bfdev_unlikely(node->left == BFDEV_POISON_HPNODE1)) { @@ -36,7 +36,7 @@ bfdev_heap_check_delete(bfdev_heap_node_t *node) " should not be BFDEV_POISON_HPNODE1 (%p)\n", node, BFDEV_POISON_HPNODE1 ); - return false; + return bfdev_false; } if (bfdev_unlikely(node->right == BFDEV_POISON_HPNODE2)) { @@ -45,7 +45,7 @@ bfdev_heap_check_delete(bfdev_heap_node_t *node) " should not be BFDEV_POISON_HPNODE2 (%p)\n", node, BFDEV_POISON_HPNODE2 ); - return false; + return bfdev_false; } if (bfdev_unlikely(node->parent == BFDEV_POISON_HPNODE3)) { @@ -54,8 +54,8 @@ bfdev_heap_check_delete(bfdev_heap_node_t *node) " should not be BFDEV_POISON_HPNODE3 (%p)\n", node, BFDEV_POISON_HPNODE3 ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } diff --git a/src/heap.c b/src/heap.c index 4470b9c1..3f375632 100644 --- a/src/heap.c +++ b/src/heap.c @@ -110,16 +110,16 @@ bfdev_heap_remove(bfdev_heap_root_t *root, bfdev_heap_node_t *node) * */ - root->node = NULL; - successor = NULL; + root->node = BFDEV_NULL; + successor = BFDEV_NULL; } else { bfdev_heap_node_t *parent; parent = successor->parent; if (parent->left == successor) - parent->left = NULL; + parent->left = BFDEV_NULL; else /* parent->right == successor */ - parent->right = NULL; + parent->right = BFDEV_NULL; /* * Case 2: node to delete is successor. @@ -131,7 +131,7 @@ bfdev_heap_remove(bfdev_heap_root_t *root, bfdev_heap_node_t *node) */ if (node == successor) { - successor = NULL; + successor = BFDEV_NULL; goto finish; } @@ -180,7 +180,7 @@ bfdev_heap_parent(bfdev_heap_root_t *root, bfdev_heap_node_t **parentp, link = &root->node; if (bfdev_unlikely(!*link)) { - *parentp = NULL; + *parentp = BFDEV_NULL; return link; } diff --git a/src/hlist-debug.c b/src/hlist-debug.c index 5db1855c..aaadf821 100644 --- a/src/hlist-debug.c +++ b/src/hlist-debug.c @@ -11,7 +11,7 @@ #include #include -export bool +export bfdev_bool bfdev_hlist_check_head_add(bfdev_hlist_head_t *head, bfdev_hlist_node_t *newn) { @@ -20,13 +20,13 @@ bfdev_hlist_check_head_add(bfdev_hlist_head_t *head, "head add corruption (%p) head->node" " should not be new (%p)\n", head, newn ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_hlist_check_next_add(bfdev_hlist_node_t *next, bfdev_hlist_node_t *newn) { @@ -36,13 +36,13 @@ bfdev_hlist_check_next_add(bfdev_hlist_node_t *next, " should not be new (%p)\n", next, newn ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_hlist_check_prev_add(bfdev_hlist_node_t *prev, bfdev_hlist_node_t *newn) { @@ -52,13 +52,13 @@ bfdev_hlist_check_prev_add(bfdev_hlist_node_t *prev, " should not be new (%p)\n", prev, newn ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_hlist_check_del(bfdev_hlist_node_t *node) { if (bfdev_unlikely(node->next == BFDEV_POISON_HLIST1)) { @@ -67,7 +67,7 @@ bfdev_hlist_check_del(bfdev_hlist_node_t *node) " should not be BFDEV_POISON_HLIST1 (%p)\n", node, BFDEV_POISON_HLIST1 ); - return false; + return bfdev_false; } if (bfdev_unlikely(node->pprev == BFDEV_POISON_HLIST2)) { @@ -76,8 +76,8 @@ bfdev_hlist_check_del(bfdev_hlist_node_t *node) " should not be BFDEV_POISON_HLIST2 (%p)\n", node, BFDEV_POISON_HLIST2 ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } diff --git a/src/ilist.c b/src/ilist.c index 815d096e..3daf5c1b 100644 --- a/src/ilist.c +++ b/src/ilist.c @@ -12,7 +12,7 @@ #include #ifdef BFDEV_DEBUG_ILIST -static inline bool +static inline bfdev_bool ilist_integrity_check(bfdev_list_head_t *head, bfdev_list_head_t *prev, bfdev_list_head_t *next) { @@ -22,7 +22,7 @@ ilist_integrity_check(bfdev_list_head_t *head, bfdev_list_head_t *prev, " should be next (%p), but was (%p)\n", head, prev, next, prev->next ); - return false; + return bfdev_false; } if (bfdev_unlikely(next->prev != prev)) { @@ -31,17 +31,17 @@ ilist_integrity_check(bfdev_list_head_t *head, bfdev_list_head_t *prev, " should be prev (%p), but was (%p)\n", head, next, prev, next->prev ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -static inline bool +static inline bfdev_bool ilist_list_check(bfdev_list_head_t *head) { bfdev_list_head_t *prev = head, *next = head->next; - bool success; + bfdev_bool success; success = ilist_integrity_check(head, prev, next); while (success && next != head) { @@ -53,10 +53,10 @@ ilist_list_check(bfdev_list_head_t *head) return success; } -static inline bool +static inline bfdev_bool ilist_head_check(bfdev_ilist_head_t *ihead) { - bool success; + bfdev_bool success; success = ilist_list_check(&ihead->node_list); if (success && !bfdev_ilist_head_empty(ihead)) @@ -90,7 +90,7 @@ bfdev_ilist_add(bfdev_ilist_head_t *ihead, bfdev_ilist_node_t *inode, /* Traverse to find a suitable insertion point */ first = walk = bfdev_ilist_first(ihead); - prev = NULL; + prev = BFDEV_NULL; do { if (cmp(inode, walk, pdata) < 0) { diff --git a/src/jhash.c b/src/jhash.c index 5c9c2f01..99f202fb 100644 --- a/src/jhash.c +++ b/src/jhash.c @@ -8,10 +8,10 @@ #include #include -static __bfdev_always_inline uint32_t -jhash(const uint8_t *data, size_t length, uint32_t initval) +static __bfdev_always_inline bfdev_u32 +jhash(const bfdev_u8 *data, bfdev_size_t length, bfdev_u32 initval) { - uint32_t a, b, c; + bfdev_u32 a, b, c; /* Set up the internal state */ a = BFDEV_JHASH_INITVAL + length + initval; @@ -26,18 +26,18 @@ jhash(const uint8_t *data, size_t length, uint32_t initval) /* Last block: affect all 32 bits of (c) */ switch (length) { - case 12: c += (uint32_t)data[11] << 24; bfdev_fallthrough; - case 11: c += (uint32_t)data[10] << 16; bfdev_fallthrough; - case 10: c += (uint32_t)data[ 9] << 8; bfdev_fallthrough; - case 9: c += (uint32_t)data[ 8] << 0; bfdev_fallthrough; - case 8: b += (uint32_t)data[ 7] << 24; bfdev_fallthrough; - case 7: b += (uint32_t)data[ 6] << 16; bfdev_fallthrough; - case 6: b += (uint32_t)data[ 5] << 8; bfdev_fallthrough; - case 5: b += (uint32_t)data[ 4] << 0; bfdev_fallthrough; - case 4: a += (uint32_t)data[ 3] << 24; bfdev_fallthrough; - case 3: a += (uint32_t)data[ 2] << 16; bfdev_fallthrough; - case 2: a += (uint32_t)data[ 1] << 8; bfdev_fallthrough; - case 1: a += (uint32_t)data[ 0] << 0; + case 12: c += (bfdev_u32)data[11] << 24; bfdev_fallthrough; + case 11: c += (bfdev_u32)data[10] << 16; bfdev_fallthrough; + case 10: c += (bfdev_u32)data[ 9] << 8; bfdev_fallthrough; + case 9: c += (bfdev_u32)data[ 8] << 0; bfdev_fallthrough; + case 8: b += (bfdev_u32)data[ 7] << 24; bfdev_fallthrough; + case 7: b += (bfdev_u32)data[ 6] << 16; bfdev_fallthrough; + case 6: b += (bfdev_u32)data[ 5] << 8; bfdev_fallthrough; + case 5: b += (bfdev_u32)data[ 4] << 0; bfdev_fallthrough; + case 4: a += (bfdev_u32)data[ 3] << 24; bfdev_fallthrough; + case 3: a += (bfdev_u32)data[ 2] << 16; bfdev_fallthrough; + case 2: a += (bfdev_u32)data[ 1] << 8; bfdev_fallthrough; + case 1: a += (bfdev_u32)data[ 0] << 0; bfdev_jhash_final(a, b, c); break; @@ -49,8 +49,8 @@ jhash(const uint8_t *data, size_t length, uint32_t initval) return c; } -export uint32_t -bfdev_jhash(const void *data, size_t length, uint32_t initval) +export bfdev_u32 +bfdev_jhash(const void *data, bfdev_size_t length, bfdev_u32 initval) { return jhash(data, length, initval); } diff --git a/src/levenshtein.c b/src/levenshtein.c index 324e0337..208cf828 100644 --- a/src/levenshtein.c +++ b/src/levenshtein.c @@ -9,12 +9,12 @@ export unsigned int bfdev_levenshtein_len(const bfdev_alloc_t *alloc, - const char *str1, const char *str2, size_t len1, size_t len2, + const char *str1, const char *str2, bfdev_size_t len1, bfdev_size_t len2, unsigned int s, unsigned int w, unsigned int a, unsigned int d) { unsigned int *row1, *row2, *row3; unsigned int distance, *cache; - size_t index1, index2; + bfdev_size_t index1, index2; if (bfdev_unlikely(!len1)) return len2 * a; @@ -24,7 +24,7 @@ bfdev_levenshtein_len(const bfdev_alloc_t *alloc, cache = bfdev_malloc(alloc, BFDEV_BYTES_PER_INT * (len1 + 1) * 3); if (bfdev_unlikely(!cache)) - return UINT_MAX; + return BFDEV_UINT_MAX; row1 = cache; row2 = row1 + (len1 + 1); @@ -69,10 +69,10 @@ bfdev_levenshtein(const bfdev_alloc_t *alloc, const char *str1, const char *str2, unsigned int s, unsigned int w, unsigned int a, unsigned int d) { - size_t len1, len2; + bfdev_size_t len1, len2; - len1 = bfport_strlen(str1); - len2 = bfport_strlen(str2); + len1 = bfdev_strlen(str1); + len2 = bfdev_strlen(str2); return bfdev_levenshtein_len(alloc, str1, str2, len1, len2, s, w, a, d); } diff --git a/src/libc/strdup.c b/src/libc/strdup.c index 93859dd6..51afdad7 100644 --- a/src/libc/strdup.c +++ b/src/libc/strdup.c @@ -8,39 +8,37 @@ #include export char * -bfdev_strdup(const bfdev_alloc_t *alloc, - const char *string) +bfdev_strdup(const bfdev_alloc_t *alloc, const char *string) { - size_t length; + bfdev_size_t length; char *dump; if (bfdev_unlikely(!string)) - return NULL; + return BFDEV_NULL; - length = bfport_strlen(string); + length = bfdev_strlen(string); dump = bfdev_malloc(alloc, length + 1); if (bfdev_likely(dump)) - bfport_strcpy(dump, string); + bfdev_strcpy(dump, string); return dump; } export char * -bfdev_strndup(const bfdev_alloc_t *alloc, - const char *string, size_t len) +bfdev_strndup(const bfdev_alloc_t *alloc, const char *string, bfdev_size_t len) { - size_t length; + bfdev_size_t length; char *dump; if (bfdev_unlikely(!string)) - return NULL; + return BFDEV_NULL; - length = bfport_strnlen(string, len); + length = bfdev_strnlen(string, len); dump = bfdev_malloc(alloc, length + 1); if (bfdev_likely(dump)) - bfport_strncpy(dump, string, len); + bfdev_strncpy(dump, string, len); return dump; } diff --git a/src/libc/string.c b/src/libc/string.c index 6e147ae4..17c50f75 100644 --- a/src/libc/string.c +++ b/src/libc/string.c @@ -17,11 +17,11 @@ bfdev_strdiff(const char *addr, int c) addr++; } - return NULL; + return BFDEV_NULL; } export __bfdev_weak void * -bfdev_memdiff(const void *addr, int c, size_t size) +bfdev_memdiff(const void *addr, int c, bfdev_size_t size) { const char *p = addr; @@ -32,5 +32,5 @@ bfdev_memdiff(const void *addr, int c, size_t size) size--; } - return NULL; + return BFDEV_NULL; } diff --git a/src/list-debug.c b/src/list-debug.c index 3a4ba172..bc46b404 100644 --- a/src/list-debug.c +++ b/src/list-debug.c @@ -11,7 +11,7 @@ #include #include -export bool +export bfdev_bool bfdev_list_check_add(bfdev_list_head_t *prev, bfdev_list_head_t *next, bfdev_list_head_t *newn) { @@ -21,7 +21,7 @@ bfdev_list_check_add(bfdev_list_head_t *prev, bfdev_list_head_t *next, " should be next (%p), but was (%p)\n", prev, next, prev->next ); - return false; + return bfdev_false; } if (bfdev_unlikely(next->prev != prev)) { @@ -30,7 +30,7 @@ bfdev_list_check_add(bfdev_list_head_t *prev, bfdev_list_head_t *next, " should be prev (%p), but was (%p)\n", next, prev, next->prev ); - return false; + return bfdev_false; } if (bfdev_unlikely(newn == prev || newn == next)) { @@ -39,13 +39,13 @@ bfdev_list_check_add(bfdev_list_head_t *prev, bfdev_list_head_t *next, " newn=(%p), prev=(%p), next=(%p)\n", newn, prev, next ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_list_check_del(bfdev_list_head_t *node) { if (bfdev_unlikely(node->next == BFDEV_POISON_LIST1)) { @@ -54,7 +54,7 @@ bfdev_list_check_del(bfdev_list_head_t *node) " should not be BFDEV_POISON_LIST1 (%p)\n", node, BFDEV_POISON_LIST1 ); - return false; + return bfdev_false; } if (bfdev_unlikely(node->prev == BFDEV_POISON_LIST2)) { @@ -63,8 +63,8 @@ bfdev_list_check_del(bfdev_list_head_t *node) " should not be BFDEV_POISON_LIST2 (%p)\n", node, BFDEV_POISON_LIST2 ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } diff --git a/src/list-sort.c b/src/list-sort.c index 68873beb..3e3a0e1a 100644 --- a/src/list-sort.c +++ b/src/list-sort.c @@ -84,12 +84,12 @@ bfdev_list_sort(bfdev_list_head_t *head, bfdev_list_cmp_t cmp, void *pdata) if (bfdev_unlikely(node == head->prev)) return; - head->prev->next = NULL; - pending = NULL; + head->prev->next = BFDEV_NULL; + pending = BFDEV_NULL; for (count = 0; node; ++count) { bfdev_list_head_t **tail; - size_t bits; + bfdev_size_t bits; tail = &pending; for (bits = count; bits & 1; bits >>= 1) @@ -110,7 +110,7 @@ bfdev_list_sort(bfdev_list_head_t *head, bfdev_list_cmp_t cmp, void *pdata) pending = node; node = node->next; - pending->next = NULL; + pending->next = BFDEV_NULL; } node = pending; diff --git a/src/llist.c b/src/llist.c index c1842f9c..b93b7738 100644 --- a/src/llist.c +++ b/src/llist.c @@ -7,7 +7,7 @@ #include #include -export bool +export bfdev_bool bfdev_llist_split(bfdev_slist_head_t *head, bfdev_slist_head_t *node, bfdev_slist_head_t *end) { @@ -32,7 +32,7 @@ bfdev_llist_del(bfdev_slist_head_t *head) entry = BFDEV_READ_ONCE(head->next); do { if (!entry) - return NULL; + return BFDEV_NULL; next = BFDEV_READ_ONCE(entry->next); } while (!bfdev_try_cmpxchg( (bfdev_atomic_t *)&head->next, (bfdev_atomic_t *)&entry, diff --git a/src/log/log.c b/src/log/log.c index efc692c9..2b487804 100644 --- a/src/log/log.c +++ b/src/log/log.c @@ -6,6 +6,7 @@ #include #include #include +#include #include export @@ -13,16 +14,13 @@ BFDEV_DEFINE_LOG( bfdev_log_default, BFDEV_LEVEL_DEFAULT, BFDEV_LEVEL_DEFAULT, BFDEV_LOG_COLOR | BFDEV_LOG_LEVEL, - NULL, NULL + BFDEV_NULL, BFDEV_NULL ); -#define __INSIDE_LOG__ -#include - -static size_t -log_vscnprintf(bfdev_log_message_t *msg, const char *fmt, va_list args) +static bfdev_size_t +log_vscnprintf(bfdev_log_message_t *msg, const char *fmt, bfdev_va_list args) { - size_t append; + bfdev_size_t append; append = bfdev_vscnprintf( msg->buff + msg->length, BFDEV_LOG_BUFF_SIZE - msg->length, @@ -33,15 +31,15 @@ log_vscnprintf(bfdev_log_message_t *msg, const char *fmt, va_list args) return append; } -static size_t +static bfdev_size_t log_scnprintf(bfdev_log_message_t *msg, const char *fmt, ...) { - size_t append; - va_list args; + bfdev_size_t append; + bfdev_va_list args; - va_start(args, fmt); + bfdev_va_start(args, fmt); append = log_vscnprintf(msg, fmt, args); - va_end(args); + bfdev_va_end(args); return append; } @@ -103,7 +101,7 @@ log_suffix(bfdev_log_t *log, bfdev_log_message_t *msg) } static int -log_emit(bfdev_log_t *log, unsigned int level, const char *fmt, va_list args) +log_emit(bfdev_log_t *log, unsigned int level, const char *fmt, bfdev_va_list args) { char buff[BFDEV_LOG_BUFF_SIZE]; bfdev_log_message_t msg; @@ -138,13 +136,13 @@ log_emit(bfdev_log_t *log, unsigned int level, const char *fmt, va_list args) if (log->write) retval = log->write(&msg, log->pdata); else - retval = generic_log_write(&msg); + retval = bfport_log_write(&msg); return retval; } export int -bfdev_vlog_core(bfdev_log_t *log, const char *fmt, va_list args) +bfdev_vlog_core(bfdev_log_t *log, const char *fmt, bfdev_va_list args) { unsigned int level; @@ -156,12 +154,12 @@ bfdev_vlog_core(bfdev_log_t *log, const char *fmt, va_list args) export int bfdev_log_core(bfdev_log_t *log, const char *fmt, ...) { - va_list para; + bfdev_va_list para; int length; - va_start(para, fmt); + bfdev_va_start(para, fmt); length = bfdev_vlog_core(log, fmt, para); - va_end(para); + bfdev_va_end(para); return length; } diff --git a/src/matrix.c b/src/matrix.c index 4db64903..ce736b1c 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -10,14 +10,14 @@ static inline void matrix_zero(BFDEV_MATRIX_TYPE *var, unsigned int size) { - bfport_memset(var, 0, size * BFDEV_MATRIX_SIZE); + bfdev_memset(var, 0, size * BFDEV_MATRIX_SIZE); } static inline void matrix_copy(BFDEV_MATRIX_TYPE *dest, const BFDEV_MATRIX_TYPE *src, unsigned int size) { - bfport_memcpy(dest, src, size * BFDEV_MATRIX_SIZE); + bfdev_memcpy(dest, src, size * BFDEV_MATRIX_SIZE); } #define GENERIC_MATRIX_ADDSUB(name, operate) \ @@ -75,7 +75,7 @@ bfdev_matrix_mul(bfdev_matrix_t *dest, if (va->col != vb->row) return -BFDEV_EINVAL; - rename = NULL; + rename = BFDEV_NULL; if (dest == va || dest == vb) { rename = dest; dest = &buffer; @@ -203,7 +203,7 @@ bfdev_matrix_data(const bfdev_matrix_t *var, unsigned int offset; if (var->col < row || var->col < col) - return NULL; + return BFDEV_NULL; offset = row * col; data = bfdev_array_data(&var->value, offset); diff --git a/src/memalloc.c b/src/memalloc.c index 31018d75..e75cc20e 100644 --- a/src/memalloc.c +++ b/src/memalloc.c @@ -12,34 +12,34 @@ #include #include -static __bfdev_always_inline bool +static __bfdev_always_inline bfdev_bool pnode_get_used(bfdev_memalloc_chunk_t *node) { return node->usize & BFDEV_BIT(0); } -static __bfdev_always_inline size_t +static __bfdev_always_inline bfdev_size_t pnode_get_size(bfdev_memalloc_chunk_t *node) { return node->usize & BFDEV_BIT_HIGH_MASK(1); } static __bfdev_always_inline void -pnode_set_used(bfdev_memalloc_chunk_t *node, bool used) +pnode_set_used(bfdev_memalloc_chunk_t *node, bfdev_bool used) { node->usize &= ~BFDEV_BIT(0); node->usize |= used; } static __bfdev_always_inline void -pnode_set_size(bfdev_memalloc_chunk_t *node, size_t size) +pnode_set_size(bfdev_memalloc_chunk_t *node, bfdev_size_t size) { node->usize &= ~BFDEV_BIT_HIGH_MASK(1); node->usize |= size & BFDEV_BIT_HIGH_MASK(1); } static __bfdev_always_inline void -pnode_set(bfdev_memalloc_chunk_t *node, size_t size, bool used) +pnode_set(bfdev_memalloc_chunk_t *node, bfdev_size_t size, bfdev_bool used) { node->usize = (size & BFDEV_BIT_HIGH_MASK(1)) | used; } @@ -55,7 +55,7 @@ memalloc_check(void *block) #ifdef BFDEV_DEBUG_MEMALLOC if (bfdev_unlikely(!bfdev_list_check_empty(&node->free))) { bfdev_log_crit("unlegal node at %p\n", block); - return NULL; + return BFDEV_NULL; } #endif @@ -63,7 +63,7 @@ memalloc_check(void *block) } export bfdev_memalloc_chunk_t * -bfdev_memalloc_first_fit(bfdev_memalloc_head_t *head, size_t size) +bfdev_memalloc_first_fit(bfdev_memalloc_head_t *head, bfdev_size_t size) { bfdev_memalloc_chunk_t *node; @@ -72,16 +72,16 @@ bfdev_memalloc_first_fit(bfdev_memalloc_head_t *head, size_t size) return node; } - return NULL; + return BFDEV_NULL; } export bfdev_memalloc_chunk_t * -bfdev_memalloc_best_fit(bfdev_memalloc_head_t *head, size_t size) +bfdev_memalloc_best_fit(bfdev_memalloc_head_t *head, bfdev_size_t size) { bfdev_memalloc_chunk_t *best, *node; - size_t walk, bsize; + bfdev_size_t walk, bsize; - best = NULL; + best = BFDEV_NULL; bsize = BFDEV_SIZE_MAX; bfdev_list_for_each_entry(node, &head->free_list, free) { @@ -100,12 +100,12 @@ bfdev_memalloc_best_fit(bfdev_memalloc_head_t *head, size_t size) } export bfdev_memalloc_chunk_t * -bfdev_memalloc_worst_fit(bfdev_memalloc_head_t *head, size_t size) +bfdev_memalloc_worst_fit(bfdev_memalloc_head_t *head, bfdev_size_t size) { bfdev_memalloc_chunk_t *worst, *node; - size_t walk, bsize; + bfdev_size_t walk, bsize; - worst = NULL; + worst = BFDEV_NULL; bsize = BFDEV_SIZE_MIN; bfdev_list_for_each_entry(node, &head->free_list, free) { @@ -124,19 +124,19 @@ bfdev_memalloc_worst_fit(bfdev_memalloc_head_t *head, size_t size) } export void * -bfdev_memalloc_alloc(bfdev_memalloc_head_t *head, size_t size) +bfdev_memalloc_alloc(bfdev_memalloc_head_t *head, bfdev_size_t size) { bfdev_memalloc_chunk_t *node, *free; - size_t nsize, bsize, fsize; + bfdev_size_t nsize, bsize, fsize; bfdev_align_high_adj(size, BFDEV_MEMALLOC_ALIGN); if (bfdev_unlikely(size > head->avail)) - return NULL; + return BFDEV_NULL; /* Get the free memory block */ node = head->find(head, size); if (bfdev_unlikely(!node)) - return NULL; + return BFDEV_NULL; /* Adjust available size */ nsize = pnode_get_size(node); @@ -150,7 +150,7 @@ bfdev_memalloc_alloc(bfdev_memalloc_head_t *head, size_t size) free = (void *)node->data + size; fsize = bsize - sizeof(*free); - pnode_set(free, fsize, false); + pnode_set(free, fsize, bfdev_false); head->avail += fsize; bfdev_list_add(&node->block, &free->block); @@ -159,24 +159,24 @@ bfdev_memalloc_alloc(bfdev_memalloc_head_t *head, size_t size) finish: /* Set node used */ - pnode_set_used(node, true); + pnode_set_used(node, bfdev_true); bfdev_list_del_init(&node->free); return node->data; } export void * -bfdev_memalloc_realloc(bfdev_memalloc_head_t *head, void *block, size_t resize) +bfdev_memalloc_realloc(bfdev_memalloc_head_t *head, void *block, bfdev_size_t resize) { bfdev_memalloc_chunk_t *node, *expand, *free; - size_t origin, exsize, nsize, bsize, fsize; + bfdev_size_t origin, exsize, nsize, bsize, fsize; node = memalloc_check(block); if (bfdev_unlikely(!node)) - return NULL; + return BFDEV_NULL; bfdev_align_high_adj(resize, BFDEV_MEMALLOC_ALIGN); if (bfdev_unlikely(resize > head->avail)) - return NULL; + return BFDEV_NULL; origin = pnode_get_size(node); if (origin >= resize) @@ -192,9 +192,9 @@ bfdev_memalloc_realloc(bfdev_memalloc_head_t *head, void *block, size_t resize) newblk = bfdev_memalloc_alloc(head, resize); if (bfdev_unlikely(!newblk)) - return NULL; + return BFDEV_NULL; - bfport_memcpy(newblk, block, origin); + bfdev_memcpy(newblk, block, origin); bfdev_memalloc_free(head, block); return newblk; @@ -219,7 +219,7 @@ bfdev_memalloc_realloc(bfdev_memalloc_head_t *head, void *block, size_t resize) free = (void *)expand + exsize; fsize = bsize - sizeof(*free); - pnode_set(free, fsize, false); + pnode_set(free, fsize, bfdev_false); head->avail += fsize; bfdev_list_add(&node->block, &free->block); @@ -234,14 +234,14 @@ export void bfdev_memalloc_free(bfdev_memalloc_head_t *head, void *block) { bfdev_memalloc_chunk_t *side, *node; - size_t nsize, fsize; + bfdev_size_t nsize, fsize; node = memalloc_check(block); if (bfdev_unlikely(!node)) return; /* Set node freed */ - pnode_set_used(node, false); + pnode_set_used(node, bfdev_false); bfdev_list_add(&head->free_list, &node->free); /* Adjust available size */ @@ -275,7 +275,7 @@ bfdev_memalloc_free(bfdev_memalloc_head_t *head, void *block) export void bfdev_memalloc_init(bfdev_memalloc_head_t *head, bfdev_memalloc_find_t find, - void *array, size_t size) + void *array, bfdev_size_t size) { bfdev_memalloc_chunk_t *node; @@ -284,7 +284,7 @@ bfdev_memalloc_init(bfdev_memalloc_head_t *head, bfdev_memalloc_find_t find, head->find = find; node = array; - pnode_set(node, size - sizeof(*node), false); + pnode_set(node, size - sizeof(*node), bfdev_false); head->avail = size - sizeof(*node); bfdev_list_add(&head->block_list, &node->block); diff --git a/src/mpi.c b/src/mpi.c index 4240f36c..600b53be 100644 --- a/src/mpi.c +++ b/src/mpi.c @@ -29,14 +29,14 @@ BFDEV_MPI_TYPE mpi_zero; static inline void mpa_zero(BFDEV_MPI_TYPE *dest, unsigned long length) { - bfport_memset(dest, 0, length * BFDEV_MPI_SIZE); + bfdev_memset(dest, 0, length * BFDEV_MPI_SIZE); } static inline void mpa_copy(BFDEV_MPI_TYPE *dest, const BFDEV_MPI_TYPE *src, unsigned long length) { - bfport_memcpy(dest, src, length * BFDEV_MPI_SIZE); + bfdev_memcpy(dest, src, length * BFDEV_MPI_SIZE); } static inline int @@ -77,10 +77,10 @@ mpa_cmp(const BFDEV_MPI_TYPE *ptra, const BFDEV_MPI_TYPE *ptrb, return BFDEV_EQ; } -static inline bool +static inline bfdev_bool mpa_addi(BFDEV_MPI_TYPE *ptrs, const BFDEV_MPI_TYPE *ptra, BFDEV_MPI_TYPE vi, - unsigned long length, bool carry) + unsigned long length, bfdev_bool carry) { BFDEV_MPI_TYPE value; @@ -96,10 +96,10 @@ mpa_addi(BFDEV_MPI_TYPE *ptrs, return carry; } -static inline bool +static inline bfdev_bool mpa_add(BFDEV_MPI_TYPE *ptrs, const BFDEV_MPI_TYPE *ptra, const BFDEV_MPI_TYPE *ptrb, - unsigned long cnta, unsigned long cntb, bool carry) + unsigned long cnta, unsigned long cntb, bfdev_bool carry) { BFDEV_MPI_TYPE value; @@ -126,10 +126,10 @@ mpa_add(BFDEV_MPI_TYPE *ptrs, return carry; } -static inline bool +static inline bfdev_bool mpa_subi(BFDEV_MPI_TYPE *ptrs, const BFDEV_MPI_TYPE *ptra, BFDEV_MPI_TYPE vi, - unsigned long length, bool borrow) + unsigned long length, bfdev_bool borrow) { BFDEV_MPI_TYPE value; @@ -146,10 +146,10 @@ mpa_subi(BFDEV_MPI_TYPE *ptrs, return borrow; } -static inline bool +static inline bfdev_bool mpa_sub(BFDEV_MPI_TYPE *ptrs, const BFDEV_MPI_TYPE *ptra, const BFDEV_MPI_TYPE *ptrb, - unsigned long cnta, unsigned long cntb, bool borrow) + unsigned long cnta, unsigned long cntb, bfdev_bool borrow) { BFDEV_MPI_TYPE value; @@ -323,27 +323,27 @@ mpa_modi(const BFDEV_MPI_TYPE *ptra, BFDEV_MPI_TYPE vi, while (length--) { dword[0] = *ptra--; - bfdev_dword_udiv(NULL, dword + 1, dword, vi); + bfdev_dword_udiv(BFDEV_NULL, dword + 1, dword, vi); } return dword[1]; } -static inline bool +static inline bfdev_bool mpa_divrem(BFDEV_MPI_TYPE *ptrs, BFDEV_MPI_TYPE *ptra, const BFDEV_MPI_TYPE *ptrb, unsigned long cnta, unsigned long cntb) { BFDEV_MPI_TYPE dhigh, dlow, value; unsigned long index; - bool limb, borrow; + bfdev_bool limb, borrow; /** * Argument constraints: * 0. @cnta >= @cntb. * 1. The most significant bit of the divisor must be set. * 2. @ptrs must either not overlap with the input operands at all, or - * @ptrs + @cntb >= @ptra must hold true. (This means that it's + * @ptrs + @cntb >= @ptra must hold bfdev_true. (This means that it's * possible to put the quotient in the high part of NUM, right after the * remainder in NUM. */ @@ -355,14 +355,14 @@ mpa_divrem(BFDEV_MPI_TYPE *ptrs, dhigh = ptrb[cntb - 1]; dlow = ptrb[cntb - 2]; - limb = false; + limb = bfdev_false; if (value >= dhigh) { if (value > dhigh || mpa_cmp(ptra, ptrb, cntb - 1, cntb - 1) >= 0) { - borrow = mpa_sub(ptra, ptra, ptrb, cntb, cntb, false); + borrow = mpa_sub(ptra, ptra, ptrb, cntb, cntb, bfdev_false); BFDEV_BUG_ON(borrow); value = ptra[cntb - 1]; - limb = true; + limb = bfdev_true; } } @@ -560,7 +560,7 @@ mpi_addi(bfdev_mpi_t *dest, { BFDEV_MPI_TYPE *ptrs, *ptra; unsigned long length; - bool carry; + bfdev_bool carry; int retval; /* parameter check */ @@ -575,7 +575,7 @@ mpi_addi(bfdev_mpi_t *dest, ptrs = mpi_val(dest); ptra = mpi_val(va); - carry = mpa_addi(ptrs, ptra, vi, length, false); + carry = mpa_addi(ptrs, ptra, vi, length, bfdev_false); *(ptrs + length) = carry; mpi_relocation(dest); @@ -588,7 +588,7 @@ mpi_add(bfdev_mpi_t *dest, { BFDEV_MPI_TYPE *ptrs, *ptra, *ptrb; unsigned long length, cnta, cntb; - bool carry; + bfdev_bool carry; int retval; /* parameter check */ @@ -613,7 +613,7 @@ mpi_add(bfdev_mpi_t *dest, ptra = mpi_val(va); ptrs = mpi_val(dest); - carry = mpa_add(ptrs, ptra, ptrb, cnta, cntb, false); + carry = mpa_add(ptrs, ptra, ptrb, cnta, cntb, bfdev_false); *(ptrs + length) = carry; mpi_relocation(dest); @@ -626,7 +626,7 @@ mpi_subi(bfdev_mpi_t *dest, { BFDEV_MPI_TYPE *ptrs, *ptra; unsigned long length; - bool borrow; + bfdev_bool borrow; int retval; /* parameter check */ @@ -640,7 +640,7 @@ mpi_subi(bfdev_mpi_t *dest, ptrs = mpi_val(dest); ptra = mpi_val(va); - borrow = mpa_subi(ptrs, ptra, vi, length, false); + borrow = mpa_subi(ptrs, ptra, vi, length, bfdev_false); BFDEV_BUG_ON(borrow); mpi_relocation(dest); @@ -653,7 +653,7 @@ mpi_sub(bfdev_mpi_t *dest, { BFDEV_MPI_TYPE *ptrs, *ptra, *ptrb; unsigned long cnta, cntb; - bool borrow; + bfdev_bool borrow; int retval; /* parameter check */ @@ -676,7 +676,7 @@ mpi_sub(bfdev_mpi_t *dest, ptrs = mpi_val(dest); ptra = mpi_val(va); - borrow = mpa_sub(ptrs, ptra, ptrb, cnta, cntb, false); + borrow = mpa_sub(ptrs, ptra, ptrb, cnta, cntb, bfdev_false); BFDEV_BUG_ON(borrow); mpi_relocation(dest); @@ -735,7 +735,7 @@ mpi_mul(bfdev_mpi_t *dest, if (cntb == 1) return mpi_muli(dest, va, *ptrb); - rename = NULL; + rename = BFDEV_NULL; if (dest == va && dest == vb) { rename = dest; dest = &buffer; @@ -835,7 +835,7 @@ mpi_div(bfdev_mpi_t *quot, bfdev_mpi_t *rem, BFDEV_MPI_TYPE *ptrs, *ptra, *ptrb; unsigned long cnta, cntb, length; bfdev_mpi_t *rename; - bool limb; + bfdev_bool limb; int retval; /* divide by zero */ @@ -868,7 +868,7 @@ mpi_div(bfdev_mpi_t *quot, bfdev_mpi_t *rem, return retval; } - rename = NULL; + rename = BFDEV_NULL; if (quot == va) { rename = quot; quot = &buffer; @@ -936,7 +936,7 @@ mpi_mod(bfdev_mpi_t *rem, cnta = mpi_len(va); ptra = mpi_val(rem); - mpa_divrem(NULL, ptra, ptrb, cnta, cntb); + mpa_divrem(BFDEV_NULL, ptra, ptrb, cnta, cntb); BFDEV_BUG_ON(mpi_resize(rem, cntb)); mpi_relocation(rem); @@ -1180,7 +1180,7 @@ bfdev_mpi_add(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; break; case BFDEV_BT: @@ -1215,7 +1215,7 @@ bfdev_mpi_addi(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; return -BFDEV_ENOERR; } @@ -1226,7 +1226,7 @@ bfdev_mpi_addi(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; break; case BFDEV_LT: @@ -1235,7 +1235,7 @@ bfdev_mpi_addi(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; break; case BFDEV_BT: @@ -1243,7 +1243,7 @@ bfdev_mpi_addi(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = false; + dest->plus = bfdev_false; break; } @@ -1272,7 +1272,7 @@ bfdev_mpi_sub(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; break; case BFDEV_BT: @@ -1307,7 +1307,7 @@ bfdev_mpi_subi(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = false; + dest->plus = bfdev_false; return -BFDEV_ENOERR; } @@ -1318,7 +1318,7 @@ bfdev_mpi_subi(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; break; case BFDEV_LT: @@ -1327,7 +1327,7 @@ bfdev_mpi_subi(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = false; + dest->plus = bfdev_false; break; case BFDEV_BT: @@ -1398,7 +1398,7 @@ bfdev_mpi_div(bfdev_mpi_t *quot, bfdev_mpi_t *rem, return retval; quot->plus = !(va->plus ^ vb->plus); - rem->plus = true; + rem->plus = bfdev_true; break; case BFDEV_LT: @@ -1415,7 +1415,7 @@ bfdev_mpi_div(bfdev_mpi_t *quot, bfdev_mpi_t *rem, if (bfdev_unlikely(retval)) return retval; - quot->plus = true; + quot->plus = bfdev_true; break; case BFDEV_BT: @@ -1449,7 +1449,7 @@ bfdev_mpi_divi(bfdev_mpi_t *quot, bfdev_mpi_t *rem, return retval; quot->plus = va->plus; - rem->plus = true; + rem->plus = bfdev_true; break; case BFDEV_LT: @@ -1466,7 +1466,7 @@ bfdev_mpi_divi(bfdev_mpi_t *quot, bfdev_mpi_t *rem, if (bfdev_unlikely(retval)) return retval; - quot->plus = true; + quot->plus = bfdev_true; break; case BFDEV_BT: @@ -1495,7 +1495,7 @@ bfdev_mpi_mod(bfdev_mpi_t *rem, if (bfdev_unlikely(retval)) return retval; - rem->plus = true; + rem->plus = bfdev_true; break; case BFDEV_LT: @@ -1533,7 +1533,7 @@ bfdev_mpi_modi(bfdev_mpi_t *rem, if (bfdev_unlikely(retval)) return retval; - rem->plus = true; + rem->plus = bfdev_true; break; case BFDEV_LT: @@ -1568,7 +1568,7 @@ bfdev_mpi_and(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; return -BFDEV_ENOERR; } @@ -1583,7 +1583,7 @@ bfdev_mpi_or(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; return -BFDEV_ENOERR; } @@ -1598,7 +1598,7 @@ bfdev_mpi_xor(bfdev_mpi_t *dest, if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; return -BFDEV_ENOERR; } @@ -1633,7 +1633,7 @@ bfdev_mpi_shri(bfdev_mpi_t *dest, return -BFDEV_ENOERR; } -export bool +export bfdev_bool bfdev_mpi_btesti(bfdev_mpi_t *dest, BFDEV_MPI_TYPE bit) { BFDEV_MPI_TYPE *base; @@ -1643,7 +1643,7 @@ bfdev_mpi_btesti(bfdev_mpi_t *dest, BFDEV_MPI_TYPE bit) length = mpi_len(dest); if (offset >= length) - return false; + return bfdev_false; base = mpi_val(dest); return bfdev_bit_test(base, bit); @@ -1695,7 +1695,7 @@ bfdev_mpi_seti(bfdev_mpi_t *dest, BFDEV_MPI_TYPE val) if (bfdev_unlikely(retval)) return retval; - dest->plus = true; + dest->plus = bfdev_true; return -BFDEV_ENOERR; } @@ -1716,7 +1716,7 @@ bfdev_mpi_set(bfdev_mpi_t *dest, const bfdev_mpi_t *src) export int bfdev_mpi_import(bfdev_mpi_t *var, const BFDEV_MPI_TYPE *buffer, - unsigned long length, bool sign) + unsigned long length, bfdev_bool sign) { int retval; @@ -1730,7 +1730,7 @@ bfdev_mpi_import(bfdev_mpi_t *var, const BFDEV_MPI_TYPE *buffer, } export const BFDEV_MPI_TYPE * -bfdev_mpi_data(const bfdev_mpi_t *var, bool *sign) +bfdev_mpi_data(const bfdev_mpi_t *var, bfdev_bool *sign) { const BFDEV_MPI_TYPE *retval; diff --git a/src/notifier.c b/src/notifier.c index 7888fa6c..9834911f 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -57,7 +57,7 @@ bfdev_notifier_register(bfdev_notifier_t *head, bfdev_notifier_node_t *node) return -BFDEV_EINVAL; bfdev_ilist_node_init(&node->list); - bfdev_ilist_add(&head->nodes, &node->list, notifier_chain_cmp, NULL); + bfdev_ilist_add(&head->nodes, &node->list, notifier_chain_cmp, BFDEV_NULL); return -BFDEV_ENOERR; } diff --git a/src/popcount.c b/src/popcount.c index de1b4da5..20bddee7 100644 --- a/src/popcount.c +++ b/src/popcount.c @@ -6,7 +6,7 @@ #include #include -export const uint8_t +export const bfdev_u8 bfdev_popcount_table[256] = { [0x00] = 0, [0x01] = 1, [0x02] = 1, [0x03] = 2, [0x04] = 1, [0x05] = 2, [0x06] = 2, [0x07] = 3, @@ -74,70 +74,70 @@ bfdev_popcount_table[256] = { [0xfc] = 6, [0xfd] = 7, [0xfe] = 7, [0xff] = 8, }; -export const bool +export const bfdev_bool bfdev_popparity_table[256] = { - [0x00] = false, [0x01] = true, [0x02] = true, [0x03] = false, - [0x04] = true, [0x05] = false, [0x06] = false, [0x07] = true, - [0x08] = true, [0x09] = false, [0x0a] = false, [0x0b] = true, - [0x0c] = false, [0x0d] = true, [0x0e] = true, [0x0f] = false, - [0x10] = true, [0x11] = false, [0x12] = false, [0x13] = true, - [0x14] = false, [0x15] = true, [0x16] = true, [0x17] = false, - [0x18] = false, [0x19] = true, [0x1a] = true, [0x1b] = false, - [0x1c] = true, [0x1d] = false, [0x1e] = false, [0x1f] = true, - [0x20] = true, [0x21] = false, [0x22] = false, [0x23] = true, - [0x24] = false, [0x25] = true, [0x26] = true, [0x27] = false, - [0x28] = false, [0x29] = true, [0x2a] = true, [0x2b] = false, - [0x2c] = true, [0x2d] = false, [0x2e] = false, [0x2f] = true, - [0x30] = false, [0x31] = true, [0x32] = true, [0x33] = false, - [0x34] = true, [0x35] = false, [0x36] = false, [0x37] = true, - [0x38] = true, [0x39] = false, [0x3a] = false, [0x3b] = true, - [0x3c] = false, [0x3d] = true, [0x3e] = true, [0x3f] = false, - [0x40] = true, [0x41] = false, [0x42] = false, [0x43] = true, - [0x44] = false, [0x45] = true, [0x46] = true, [0x47] = false, - [0x48] = false, [0x49] = true, [0x4a] = true, [0x4b] = false, - [0x4c] = true, [0x4d] = false, [0x4e] = false, [0x4f] = true, - [0x50] = false, [0x51] = true, [0x52] = true, [0x53] = false, - [0x54] = true, [0x55] = false, [0x56] = false, [0x57] = true, - [0x58] = true, [0x59] = false, [0x5a] = false, [0x5b] = true, - [0x5c] = false, [0x5d] = true, [0x5e] = true, [0x5f] = false, - [0x60] = false, [0x61] = true, [0x62] = true, [0x63] = false, - [0x64] = true, [0x65] = false, [0x66] = false, [0x67] = true, - [0x68] = true, [0x69] = false, [0x6a] = false, [0x6b] = true, - [0x6c] = false, [0x6d] = true, [0x6e] = true, [0x6f] = false, - [0x70] = true, [0x71] = false, [0x72] = false, [0x73] = true, - [0x74] = false, [0x75] = true, [0x76] = true, [0x77] = false, - [0x78] = false, [0x79] = true, [0x7a] = true, [0x7b] = false, - [0x7c] = true, [0x7d] = false, [0x7e] = false, [0x7f] = true, - [0x80] = true, [0x81] = false, [0x82] = false, [0x83] = true, - [0x84] = false, [0x85] = true, [0x86] = true, [0x87] = false, - [0x88] = false, [0x89] = true, [0x8a] = true, [0x8b] = false, - [0x8c] = true, [0x8d] = false, [0x8e] = false, [0x8f] = true, - [0x90] = false, [0x91] = true, [0x92] = true, [0x93] = false, - [0x94] = true, [0x95] = false, [0x96] = false, [0x97] = true, - [0x98] = true, [0x99] = false, [0x9a] = false, [0x9b] = true, - [0x9c] = false, [0x9d] = true, [0x9e] = true, [0x9f] = false, - [0xa0] = false, [0xa1] = true, [0xa2] = true, [0xa3] = false, - [0xa4] = true, [0xa5] = false, [0xa6] = false, [0xa7] = true, - [0xa8] = true, [0xa9] = false, [0xaa] = false, [0xab] = true, - [0xac] = false, [0xad] = true, [0xae] = true, [0xaf] = false, - [0xb0] = true, [0xb1] = false, [0xb2] = false, [0xb3] = true, - [0xb4] = false, [0xb5] = true, [0xb6] = true, [0xb7] = false, - [0xb8] = false, [0xb9] = true, [0xba] = true, [0xbb] = false, - [0xbc] = true, [0xbd] = false, [0xbe] = false, [0xbf] = true, - [0xc0] = false, [0xc1] = true, [0xc2] = true, [0xc3] = false, - [0xc4] = true, [0xc5] = false, [0xc6] = false, [0xc7] = true, - [0xc8] = true, [0xc9] = false, [0xca] = false, [0xcb] = true, - [0xcc] = false, [0xcd] = true, [0xce] = true, [0xcf] = false, - [0xd0] = true, [0xd1] = false, [0xd2] = false, [0xd3] = true, - [0xd4] = false, [0xd5] = true, [0xd6] = true, [0xd7] = false, - [0xd8] = false, [0xd9] = true, [0xda] = true, [0xdb] = false, - [0xdc] = true, [0xdd] = false, [0xde] = false, [0xdf] = true, - [0xe0] = true, [0xe1] = false, [0xe2] = false, [0xe3] = true, - [0xe4] = false, [0xe5] = true, [0xe6] = true, [0xe7] = false, - [0xe8] = false, [0xe9] = true, [0xea] = true, [0xeb] = false, - [0xec] = true, [0xed] = false, [0xee] = false, [0xef] = true, - [0xf0] = false, [0xf1] = true, [0xf2] = true, [0xf3] = false, - [0xf4] = true, [0xf5] = false, [0xf6] = false, [0xf7] = true, - [0xf8] = true, [0xf9] = false, [0xfa] = false, [0xfb] = true, - [0xfc] = false, [0xfd] = true, [0xfe] = true, [0xff] = false, + [0x00] = bfdev_false, [0x01] = bfdev_true, [0x02] = bfdev_true, [0x03] = bfdev_false, + [0x04] = bfdev_true, [0x05] = bfdev_false, [0x06] = bfdev_false, [0x07] = bfdev_true, + [0x08] = bfdev_true, [0x09] = bfdev_false, [0x0a] = bfdev_false, [0x0b] = bfdev_true, + [0x0c] = bfdev_false, [0x0d] = bfdev_true, [0x0e] = bfdev_true, [0x0f] = bfdev_false, + [0x10] = bfdev_true, [0x11] = bfdev_false, [0x12] = bfdev_false, [0x13] = bfdev_true, + [0x14] = bfdev_false, [0x15] = bfdev_true, [0x16] = bfdev_true, [0x17] = bfdev_false, + [0x18] = bfdev_false, [0x19] = bfdev_true, [0x1a] = bfdev_true, [0x1b] = bfdev_false, + [0x1c] = bfdev_true, [0x1d] = bfdev_false, [0x1e] = bfdev_false, [0x1f] = bfdev_true, + [0x20] = bfdev_true, [0x21] = bfdev_false, [0x22] = bfdev_false, [0x23] = bfdev_true, + [0x24] = bfdev_false, [0x25] = bfdev_true, [0x26] = bfdev_true, [0x27] = bfdev_false, + [0x28] = bfdev_false, [0x29] = bfdev_true, [0x2a] = bfdev_true, [0x2b] = bfdev_false, + [0x2c] = bfdev_true, [0x2d] = bfdev_false, [0x2e] = bfdev_false, [0x2f] = bfdev_true, + [0x30] = bfdev_false, [0x31] = bfdev_true, [0x32] = bfdev_true, [0x33] = bfdev_false, + [0x34] = bfdev_true, [0x35] = bfdev_false, [0x36] = bfdev_false, [0x37] = bfdev_true, + [0x38] = bfdev_true, [0x39] = bfdev_false, [0x3a] = bfdev_false, [0x3b] = bfdev_true, + [0x3c] = bfdev_false, [0x3d] = bfdev_true, [0x3e] = bfdev_true, [0x3f] = bfdev_false, + [0x40] = bfdev_true, [0x41] = bfdev_false, [0x42] = bfdev_false, [0x43] = bfdev_true, + [0x44] = bfdev_false, [0x45] = bfdev_true, [0x46] = bfdev_true, [0x47] = bfdev_false, + [0x48] = bfdev_false, [0x49] = bfdev_true, [0x4a] = bfdev_true, [0x4b] = bfdev_false, + [0x4c] = bfdev_true, [0x4d] = bfdev_false, [0x4e] = bfdev_false, [0x4f] = bfdev_true, + [0x50] = bfdev_false, [0x51] = bfdev_true, [0x52] = bfdev_true, [0x53] = bfdev_false, + [0x54] = bfdev_true, [0x55] = bfdev_false, [0x56] = bfdev_false, [0x57] = bfdev_true, + [0x58] = bfdev_true, [0x59] = bfdev_false, [0x5a] = bfdev_false, [0x5b] = bfdev_true, + [0x5c] = bfdev_false, [0x5d] = bfdev_true, [0x5e] = bfdev_true, [0x5f] = bfdev_false, + [0x60] = bfdev_false, [0x61] = bfdev_true, [0x62] = bfdev_true, [0x63] = bfdev_false, + [0x64] = bfdev_true, [0x65] = bfdev_false, [0x66] = bfdev_false, [0x67] = bfdev_true, + [0x68] = bfdev_true, [0x69] = bfdev_false, [0x6a] = bfdev_false, [0x6b] = bfdev_true, + [0x6c] = bfdev_false, [0x6d] = bfdev_true, [0x6e] = bfdev_true, [0x6f] = bfdev_false, + [0x70] = bfdev_true, [0x71] = bfdev_false, [0x72] = bfdev_false, [0x73] = bfdev_true, + [0x74] = bfdev_false, [0x75] = bfdev_true, [0x76] = bfdev_true, [0x77] = bfdev_false, + [0x78] = bfdev_false, [0x79] = bfdev_true, [0x7a] = bfdev_true, [0x7b] = bfdev_false, + [0x7c] = bfdev_true, [0x7d] = bfdev_false, [0x7e] = bfdev_false, [0x7f] = bfdev_true, + [0x80] = bfdev_true, [0x81] = bfdev_false, [0x82] = bfdev_false, [0x83] = bfdev_true, + [0x84] = bfdev_false, [0x85] = bfdev_true, [0x86] = bfdev_true, [0x87] = bfdev_false, + [0x88] = bfdev_false, [0x89] = bfdev_true, [0x8a] = bfdev_true, [0x8b] = bfdev_false, + [0x8c] = bfdev_true, [0x8d] = bfdev_false, [0x8e] = bfdev_false, [0x8f] = bfdev_true, + [0x90] = bfdev_false, [0x91] = bfdev_true, [0x92] = bfdev_true, [0x93] = bfdev_false, + [0x94] = bfdev_true, [0x95] = bfdev_false, [0x96] = bfdev_false, [0x97] = bfdev_true, + [0x98] = bfdev_true, [0x99] = bfdev_false, [0x9a] = bfdev_false, [0x9b] = bfdev_true, + [0x9c] = bfdev_false, [0x9d] = bfdev_true, [0x9e] = bfdev_true, [0x9f] = bfdev_false, + [0xa0] = bfdev_false, [0xa1] = bfdev_true, [0xa2] = bfdev_true, [0xa3] = bfdev_false, + [0xa4] = bfdev_true, [0xa5] = bfdev_false, [0xa6] = bfdev_false, [0xa7] = bfdev_true, + [0xa8] = bfdev_true, [0xa9] = bfdev_false, [0xaa] = bfdev_false, [0xab] = bfdev_true, + [0xac] = bfdev_false, [0xad] = bfdev_true, [0xae] = bfdev_true, [0xaf] = bfdev_false, + [0xb0] = bfdev_true, [0xb1] = bfdev_false, [0xb2] = bfdev_false, [0xb3] = bfdev_true, + [0xb4] = bfdev_false, [0xb5] = bfdev_true, [0xb6] = bfdev_true, [0xb7] = bfdev_false, + [0xb8] = bfdev_false, [0xb9] = bfdev_true, [0xba] = bfdev_true, [0xbb] = bfdev_false, + [0xbc] = bfdev_true, [0xbd] = bfdev_false, [0xbe] = bfdev_false, [0xbf] = bfdev_true, + [0xc0] = bfdev_false, [0xc1] = bfdev_true, [0xc2] = bfdev_true, [0xc3] = bfdev_false, + [0xc4] = bfdev_true, [0xc5] = bfdev_false, [0xc6] = bfdev_false, [0xc7] = bfdev_true, + [0xc8] = bfdev_true, [0xc9] = bfdev_false, [0xca] = bfdev_false, [0xcb] = bfdev_true, + [0xcc] = bfdev_false, [0xcd] = bfdev_true, [0xce] = bfdev_true, [0xcf] = bfdev_false, + [0xd0] = bfdev_true, [0xd1] = bfdev_false, [0xd2] = bfdev_false, [0xd3] = bfdev_true, + [0xd4] = bfdev_false, [0xd5] = bfdev_true, [0xd6] = bfdev_true, [0xd7] = bfdev_false, + [0xd8] = bfdev_false, [0xd9] = bfdev_true, [0xda] = bfdev_true, [0xdb] = bfdev_false, + [0xdc] = bfdev_true, [0xdd] = bfdev_false, [0xde] = bfdev_false, [0xdf] = bfdev_true, + [0xe0] = bfdev_true, [0xe1] = bfdev_false, [0xe2] = bfdev_false, [0xe3] = bfdev_true, + [0xe4] = bfdev_false, [0xe5] = bfdev_true, [0xe6] = bfdev_true, [0xe7] = bfdev_false, + [0xe8] = bfdev_false, [0xe9] = bfdev_true, [0xea] = bfdev_true, [0xeb] = bfdev_false, + [0xec] = bfdev_true, [0xed] = bfdev_false, [0xee] = bfdev_false, [0xef] = bfdev_true, + [0xf0] = bfdev_false, [0xf1] = bfdev_true, [0xf2] = bfdev_true, [0xf3] = bfdev_false, + [0xf4] = bfdev_true, [0xf5] = bfdev_false, [0xf6] = bfdev_false, [0xf7] = bfdev_true, + [0xf8] = bfdev_true, [0xf9] = bfdev_false, [0xfa] = bfdev_false, [0xfb] = bfdev_true, + [0xfc] = bfdev_false, [0xfd] = bfdev_true, [0xfe] = bfdev_true, [0xff] = bfdev_false, }; diff --git a/src/port/build.cmake b/src/port/build.cmake new file mode 100644 index 00000000..3ee5722d --- /dev/null +++ b/src/port/build.cmake @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# +# Copyright(c) 2023 John Sanpe +# + +set(BFDEV_SOURCE + ${BFDEV_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/stdlib.c + ${CMAKE_CURRENT_LIST_DIR}/string.c +) diff --git a/src/port/stdlib.c b/src/port/stdlib.c new file mode 100644 index 00000000..1fef5f4b --- /dev/null +++ b/src/port/stdlib.c @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include +#include + +extern __bfdev_noreturn void +bfdev_abort(void) +{ + bfport_abort(); +} diff --git a/src/port/string.c b/src/port/string.c new file mode 100644 index 00000000..51bd2676 --- /dev/null +++ b/src/port/string.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include +#include + +export void * +bfdev_memcpy(void *dest, const void *src, bfdev_size_t n) +{ + return bfport_memcpy(dest, src, n); +} + +export void * +bfdev_memset(void *s, int c, bfdev_size_t n) +{ + return bfport_memset(s, c, n); +} + +export int +bfdev_memcmp(const void *s1, const void *s2, bfdev_size_t n) +{ + return bfport_memcmp(s1, s2, n); +} + +export int +bfdev_strcmp(const char *s1, const char *s2) +{ + return bfport_strcmp(s1, s2); +} + +export char * +bfdev_strchr(const char *s, int c) +{ + return bfport_strchr(s, c); +} + +export bfdev_size_t +bfdev_strspn(const char *s, const char *accept) +{ + return bfport_strspn(s, accept); +} + +export bfdev_size_t +bfdev_strcspn(const char *s, const char *reject) +{ + return bfport_strcspn(s, reject); +} + +export char * +bfdev_strcpy(char *dest, const char *src) +{ + return bfport_strcpy(dest, src); +} + +export char * +bfdev_strncpy(char *dest, const char *src, bfdev_size_t n) +{ + return bfport_strncpy(dest, src, n); +} + +export bfdev_size_t +bfdev_strlen(const char *s) +{ + return bfport_strlen(s); +} + +export bfdev_size_t +bfdev_strnlen(const char *s, bfdev_size_t len) +{ + return bfport_strnlen(s, len); +} diff --git a/src/prandom.c b/src/prandom.c index 10dbb64c..bc945923 100644 --- a/src/prandom.c +++ b/src/prandom.c @@ -7,16 +7,16 @@ #include #include -static __bfdev_always_inline uint32_t -seed_minimum(uint32_t x, uint32_t m) +static __bfdev_always_inline bfdev_u32 +seed_minimum(bfdev_u32 x, bfdev_u32 m) { return (x < m) ? x + m : x; } static void -prandom_setup(bfdev_prandom_t *pstate, uint64_t seed) +prandom_setup(bfdev_prandom_t *pstate, bfdev_u64 seed) { - uint32_t s1, s2, s3, s4; + bfdev_u32 s1, s2, s3, s4; seed = bfdev_lower_32_bits((seed >> 32) ^ (seed << 10) ^ seed); s1 = seed_minimum(seed, 2U); @@ -31,7 +31,7 @@ prandom_setup(bfdev_prandom_t *pstate, uint64_t seed) } static __bfdev_always_inline void -prandom_value(bfdev_prandom_t *pstate, uint32_t buff[4]) +prandom_value(bfdev_prandom_t *pstate, bfdev_u32 buff[4]) { buff[0] = BFDEV_TAUSWORTHE(pstate->s1, 6U, 13U, 4294967294U, 18U); buff[1] = BFDEV_TAUSWORTHE(pstate->s2, 2U, 27U, 4294967288U, 2U); @@ -48,16 +48,16 @@ static __bfdev_always_inline void prandom_warmup(bfdev_prandom_t *pstate) { unsigned int count; - uint32_t buff[4]; + bfdev_u32 buff[4]; for (count = 0; count < BFDEV_PRANDOM_WARMUP; ++count) prandom_value(pstate, buff); } -export uint32_t +export bfdev_u32 bfdev_prandom_value(bfdev_prandom_t *pstate) { - uint32_t value, buff[4]; + bfdev_u32 value, buff[4]; prandom_value(pstate, buff); value = buff[0] ^ buff[1] ^ buff[2] ^ buff[3]; @@ -66,7 +66,7 @@ bfdev_prandom_value(bfdev_prandom_t *pstate) } export void -bfdev_prandom_seed(bfdev_prandom_t *pstate, uint64_t seed) +bfdev_prandom_seed(bfdev_prandom_t *pstate, bfdev_u64 seed) { prandom_setup(pstate, seed); prandom_warmup(pstate); diff --git a/src/radix.c b/src/radix.c index f473a77e..16163dad 100644 --- a/src/radix.c +++ b/src/radix.c @@ -26,13 +26,13 @@ radix_depth_shift(unsigned int level) } static __bfdev_always_inline unsigned int -radix_depth_index(unsigned int level, uintptr_t offset) +radix_depth_index(unsigned int level, bfdev_uintptr_t offset) { return (offset >> radix_depth_shift(level)) & RADIX_ARY_MASK; } -static bool -radix_parent(bfdev_radix_root_t *root, uintptr_t offset, +static bfdev_bool +radix_parent(bfdev_radix_root_t *root, bfdev_uintptr_t offset, struct radix_parent *parent) { bfdev_radix_node_t *node; @@ -43,13 +43,13 @@ radix_parent(bfdev_radix_root_t *root, uintptr_t offset, /* Directly check capacity overflow */ if (bfdev_ilog2(offset) > radix_depth_shift(level)) - return false; + return bfdev_false; node = root->node; parent[root->level].node = node; if (bfdev_unlikely(!node)) - return false; + return bfdev_false; while (level--) { index = radix_depth_index(level, offset); @@ -57,40 +57,40 @@ radix_parent(bfdev_radix_root_t *root, uintptr_t offset, offset &= BFDEV_BIT_LOW_MASK(radix_depth_shift(level)); if (bfdev_unlikely(!node)) - return false; + return bfdev_false; parent[level].node = node; parent[level + 1].index = index; } parent[0].index = offset; - return true; + return bfdev_true; } export void * -bfdev_radix_root_find(bfdev_radix_root_t *root, uintptr_t offset) +bfdev_radix_root_find(bfdev_radix_root_t *root, bfdev_uintptr_t offset) { struct radix_parent parents[RADIX_LEVEL_MAX]; bfdev_radix_node_t *node; unsigned int index; - bool contain; + bfdev_bool contain; contain = radix_parent(root, offset, parents); if (bfdev_unlikely(!contain)) - return NULL; + return BFDEV_NULL; node = parents[0].node; index = parents[0].index; contain = bfdev_bit_test(node->bitmap, index); if (bfdev_unlikely(!contain)) - return NULL; + return BFDEV_NULL; return &node->block[index]; } static inline bfdev_radix_node_t * -radix_extend(bfdev_radix_root_t *root, uintptr_t offset) +radix_extend(bfdev_radix_root_t *root, bfdev_uintptr_t offset) { const bfdev_alloc_t *alloc; bfdev_radix_node_t *node, *successor; @@ -106,7 +106,7 @@ radix_extend(bfdev_radix_root_t *root, uintptr_t offset) successor = bfdev_zalloc(alloc, sizeof(*successor)); if (bfdev_unlikely(!successor)) - return NULL; + return BFDEV_NULL; if (node) { successor->refcount++; @@ -142,7 +142,7 @@ radix_shrink(bfdev_radix_root_t *root) } export void * -bfdev_radix_root_alloc(bfdev_radix_root_t *root, uintptr_t offset) +bfdev_radix_root_alloc(bfdev_radix_root_t *root, bfdev_uintptr_t offset) { const bfdev_alloc_t *alloc; bfdev_radix_node_t *node; @@ -150,7 +150,7 @@ bfdev_radix_root_alloc(bfdev_radix_root_t *root, uintptr_t offset) node = radix_extend(root, offset); if (bfdev_unlikely(!node)) - return NULL; + return BFDEV_NULL; alloc = root->alloc; for (level = root->level; level--;) { @@ -162,7 +162,7 @@ bfdev_radix_root_alloc(bfdev_radix_root_t *root, uintptr_t offset) if (!*slot) { newn = bfdev_zalloc(alloc, sizeof(*newn)); if (bfdev_unlikely(!newn)) - return NULL; + return BFDEV_NULL; *slot = newn; node->refcount++; @@ -176,13 +176,13 @@ bfdev_radix_root_alloc(bfdev_radix_root_t *root, uintptr_t offset) } export int -bfdev_radix_root_free(bfdev_radix_root_t *root, uintptr_t offset) +bfdev_radix_root_free(bfdev_radix_root_t *root, bfdev_uintptr_t offset) { struct radix_parent parents[RADIX_LEVEL_MAX]; const bfdev_alloc_t *alloc; bfdev_radix_node_t *node; unsigned int level, index; - bool contain; + bfdev_bool contain; contain = radix_parent(root, offset, parents); if (bfdev_unlikely(!contain)) @@ -210,7 +210,7 @@ bfdev_radix_root_free(bfdev_radix_root_t *root, uintptr_t offset) parent = parents[level + 1].node; index = parents[level + 1].index; - parent->child[index] = NULL; + parent->child[index] = BFDEV_NULL; bfdev_free(alloc, node); node = parent; } @@ -224,10 +224,10 @@ bfdev_radix_root_free(bfdev_radix_root_t *root, uintptr_t offset) export int bfdev_radix_root_charge(bfdev_radix_root_t *root, - uintptr_t offset, size_t size) + bfdev_uintptr_t offset, bfdev_size_t size) { - uintptr_t end; - bool retval; + bfdev_uintptr_t end; + bfdev_bool retval; retval = bfdev_overflow_check_add(offset, size, &end); if (bfdev_unlikely(retval)) @@ -270,12 +270,12 @@ bfdev_radix_root_release(bfdev_radix_root_t *root) radix_destroy_recurse(alloc, root->node, root->level); root->level = 0; - root->node = NULL; + root->node = BFDEV_NULL; } static inline bfdev_radix_node_t * radix_left_most(bfdev_radix_node_t *node, unsigned int level, - uintptr_t *offset) + bfdev_uintptr_t *offset) { unsigned int walk; @@ -285,12 +285,12 @@ radix_left_most(bfdev_radix_node_t *node, unsigned int level, continue; node = node->child[walk]; - *offset |= (uintptr_t)walk << radix_depth_shift(level); + *offset |= (bfdev_uintptr_t)walk << radix_depth_shift(level); break; } if (walk == BFDEV_RADIX_ARY) - return NULL; + return BFDEV_NULL; } return node; @@ -298,7 +298,7 @@ radix_left_most(bfdev_radix_node_t *node, unsigned int level, static inline bfdev_radix_node_t * radix_right_most(bfdev_radix_node_t *node, unsigned int level, - uintptr_t *offset) + bfdev_uintptr_t *offset) { unsigned int walk; @@ -309,30 +309,30 @@ radix_right_most(bfdev_radix_node_t *node, unsigned int level, continue; node = node->child[walk]; - *offset |= (uintptr_t)walk << radix_depth_shift(level); + *offset |= (bfdev_uintptr_t)walk << radix_depth_shift(level); break; } if (walk > BFDEV_RADIX_ARY) - return NULL; + return BFDEV_NULL; } return node; } export void * -bfdev_radix_root_first(bfdev_radix_root_t *root, uintptr_t *offsetp) +bfdev_radix_root_first(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp) { unsigned int count, level; bfdev_radix_node_t *node; - uintptr_t offset; + bfdev_uintptr_t offset; *offsetp = 0; node = root->node; level = root->level; if (!node) - return NULL; + return BFDEV_NULL; offset = 0; node = radix_left_most(node, level, &offset); @@ -340,7 +340,7 @@ bfdev_radix_root_first(bfdev_radix_root_t *root, uintptr_t *offsetp) count = bfdev_find_first_bit(node->bitmap, BFDEV_RADIX_BLOCK); if (count == BFDEV_RADIX_BLOCK) - return NULL; + return BFDEV_NULL; offset |= count; *offsetp = offset; @@ -349,18 +349,18 @@ bfdev_radix_root_first(bfdev_radix_root_t *root, uintptr_t *offsetp) } export void * -bfdev_radix_root_last(bfdev_radix_root_t *root, uintptr_t *offsetp) +bfdev_radix_root_last(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp) { unsigned int count, level; bfdev_radix_node_t *node; - uintptr_t offset; + bfdev_uintptr_t offset; *offsetp = 0; node = root->node; level = root->level; if (!node) - return NULL; + return BFDEV_NULL; offset = 0; node = radix_right_most(node, level, &offset); @@ -368,7 +368,7 @@ bfdev_radix_root_last(bfdev_radix_root_t *root, uintptr_t *offsetp) count = bfdev_find_last_bit(node->bitmap, BFDEV_RADIX_BLOCK); if (count == BFDEV_RADIX_BLOCK) - return NULL; + return BFDEV_NULL; offset |= count; *offsetp = offset; @@ -377,16 +377,16 @@ bfdev_radix_root_last(bfdev_radix_root_t *root, uintptr_t *offsetp) } export void * -bfdev_radix_root_next(bfdev_radix_root_t *root, uintptr_t *offsetp) +bfdev_radix_root_next(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp) { struct radix_parent parents[RADIX_LEVEL_MAX]; bfdev_radix_node_t *node; unsigned int count, index, level; - bool contain; + bfdev_bool contain; contain = radix_parent(root, *offsetp, parents); if (bfdev_unlikely(!contain)) - return NULL; + return BFDEV_NULL; node = parents[0].node; index = parents[0].index; @@ -394,7 +394,7 @@ bfdev_radix_root_next(bfdev_radix_root_t *root, uintptr_t *offsetp) /* Check for safety */ contain = bfdev_bit_test(node->bitmap, index); if (bfdev_unlikely(!contain)) - return NULL; + return BFDEV_NULL; count = bfdev_find_next_bit(node->bitmap, BFDEV_RADIX_BLOCK, index + 1); if (count < BFDEV_RADIX_BLOCK) @@ -405,20 +405,20 @@ bfdev_radix_root_next(bfdev_radix_root_t *root, uintptr_t *offsetp) index = parents[level].index; count = radix_depth_shift(level - 1); - *offsetp &= ~((uintptr_t)RADIX_ARY_MASK << count); + *offsetp &= ~((bfdev_uintptr_t)RADIX_ARY_MASK << count); while (++index < BFDEV_RADIX_ARY) { if (!node->child[index]) continue; - *offsetp |= (uintptr_t)index << count; + *offsetp |= (bfdev_uintptr_t)index << count; node = node->child[index]; goto downward; } } - return NULL; + return BFDEV_NULL; downward: node = radix_left_most(node, level - 1, offsetp); @@ -426,23 +426,23 @@ bfdev_radix_root_next(bfdev_radix_root_t *root, uintptr_t *offsetp) count = bfdev_find_first_bit(node->bitmap, BFDEV_RADIX_BLOCK); finish: - *offsetp &= ~(uintptr_t)RADIX_BLOCK_MASK; + *offsetp &= ~(bfdev_uintptr_t)RADIX_BLOCK_MASK; *offsetp |= count; return &node->block[count]; } export void * -bfdev_radix_root_prev(bfdev_radix_root_t *root, uintptr_t *offsetp) +bfdev_radix_root_prev(bfdev_radix_root_t *root, bfdev_uintptr_t *offsetp) { struct radix_parent parents[RADIX_LEVEL_MAX]; bfdev_radix_node_t *node; unsigned int count, index, level; - bool contain; + bfdev_bool contain; contain = radix_parent(root, *offsetp, parents); if (bfdev_unlikely(!contain)) - return NULL; + return BFDEV_NULL; node = parents[0].node; index = parents[0].index; @@ -450,7 +450,7 @@ bfdev_radix_root_prev(bfdev_radix_root_t *root, uintptr_t *offsetp) /* Check for safety */ contain = bfdev_bit_test(node->bitmap, index); if (bfdev_unlikely(!contain)) - return NULL; + return BFDEV_NULL; count = bfdev_find_prev_bit(node->bitmap, BFDEV_RADIX_BLOCK, index - 1); if (count < BFDEV_RADIX_BLOCK) @@ -461,20 +461,20 @@ bfdev_radix_root_prev(bfdev_radix_root_t *root, uintptr_t *offsetp) index = parents[level].index; count = radix_depth_shift(level - 1); - *offsetp &= ~((uintptr_t)RADIX_ARY_MASK << count); + *offsetp &= ~((bfdev_uintptr_t)RADIX_ARY_MASK << count); while (index--) { if (!node->child[index]) continue; - *offsetp |= (uintptr_t)index << count; + *offsetp |= (bfdev_uintptr_t)index << count; node = node->child[index]; goto downward; } } - return NULL; + return BFDEV_NULL; downward: node = radix_right_most(node, level - 1, offsetp); @@ -482,7 +482,7 @@ bfdev_radix_root_prev(bfdev_radix_root_t *root, uintptr_t *offsetp) count = bfdev_find_last_bit(node->bitmap, BFDEV_RADIX_BLOCK); finish: - *offsetp &= ~(uintptr_t)RADIX_BLOCK_MASK; + *offsetp &= ~(bfdev_uintptr_t)RADIX_BLOCK_MASK; *offsetp |= count; return &node->block[count]; diff --git a/src/ratelimit.c b/src/ratelimit.c index 6908623a..bf360f3b 100644 --- a/src/ratelimit.c +++ b/src/ratelimit.c @@ -8,13 +8,13 @@ #include #include -export bool +export bfdev_bool bfdev_ratelimit(bfdev_ratelimit_t *limit, bfdev_time_t current) { - bool accept; + bfdev_bool accept; if (!limit->interval) - return true; + return bfdev_true; if (bfdev_unlikely(!limit->begin)) limit->begin = current; @@ -26,10 +26,10 @@ bfdev_ratelimit(bfdev_ratelimit_t *limit, bfdev_time_t current) if (bfdev_likely(limit->burst > limit->passed)) { limit->passed++; - accept = true; + accept = bfdev_true; } else { limit->missed++; - accept = false; + accept = bfdev_false; } return accept; diff --git a/src/rbtree-debug.c b/src/rbtree-debug.c index ff6ae75f..b64e6b87 100644 --- a/src/rbtree-debug.c +++ b/src/rbtree-debug.c @@ -11,7 +11,7 @@ #include #include -export bool +export bfdev_bool bfdev_rb_check_link(bfdev_rb_node_t *parent, bfdev_rb_node_t **link, bfdev_rb_node_t *node) { @@ -21,13 +21,13 @@ bfdev_rb_check_link(bfdev_rb_node_t *parent, bfdev_rb_node_t **link, " should not be node (%p)\n", link, node ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_rb_check_delete(bfdev_rb_node_t *node) { if (bfdev_unlikely(node->left == BFDEV_POISON_RBNODE1)) { @@ -36,7 +36,7 @@ bfdev_rb_check_delete(bfdev_rb_node_t *node) " should not be BFDEV_POISON_RBNODE1 (%p)\n", node, BFDEV_POISON_RBNODE1 ); - return false; + return bfdev_false; } if (bfdev_unlikely(node->right == BFDEV_POISON_RBNODE2)) { @@ -45,7 +45,7 @@ bfdev_rb_check_delete(bfdev_rb_node_t *node) " should not be BFDEV_POISON_RBNODE2 (%p)\n", node, BFDEV_POISON_RBNODE2 ); - return false; + return bfdev_false; } if (bfdev_unlikely(node->parent == BFDEV_POISON_RBNODE3)) { @@ -54,8 +54,8 @@ bfdev_rb_check_delete(bfdev_rb_node_t *node) " should not be BFDEV_POISON_RBNODE3 (%p)\n", node, BFDEV_POISON_RBNODE3 ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } diff --git a/src/rbtree.c b/src/rbtree.c index 1a5431d6..27febf68 100644 --- a/src/rbtree.c +++ b/src/rbtree.c @@ -229,9 +229,10 @@ export void bfdev_rb_erase_augmented(bfdev_rb_root_t *root, bfdev_rb_node_t *parent, const bfdev_rb_callbacks_t *callbacks) { - bfdev_rb_node_t *sibling, *node = NULL; + bfdev_rb_node_t *sibling, *node; bfdev_rb_node_t *tmp1, *tmp2; + node = BFDEV_NULL; while (root && parent) { /* * Loop invariants: @@ -379,12 +380,13 @@ export bfdev_rb_node_t * bfdev_rb_remove_augmented(bfdev_rb_root_t *root, bfdev_rb_node_t *node, const bfdev_rb_callbacks_t *callbacks) { - bfdev_rb_node_t *parent, *rebalance = NULL; + bfdev_rb_node_t *parent, *rebalance; bfdev_rb_node_t *child1, *child2; parent = node->parent; child1 = node->left; child2 = node->right; + rebalance = BFDEV_NULL; if (!child1 && !child2) { /* @@ -398,7 +400,7 @@ bfdev_rb_remove_augmented(bfdev_rb_root_t *root, bfdev_rb_node_t *node, if (node->color == BFDEV_RB_BLACK) rebalance = parent; - child_change(root, parent, node, NULL); + child_change(root, parent, node, BFDEV_NULL); } else if (!child2) { /* * Case 1: node to erase only has left child. @@ -495,7 +497,7 @@ bfdev_rb_remove_augmented(bfdev_rb_root_t *root, bfdev_rb_node_t *node, parent = successor; } - callbacks->propagate(parent, NULL); + callbacks->propagate(parent, BFDEV_NULL); return rebalance; } @@ -559,22 +561,22 @@ bfdev_rb_find(const bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find) node = node->right; } - return NULL; + return BFDEV_NULL; } export bfdev_rb_node_t * bfdev_rb_find_last(bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find, bfdev_rb_node_t **parentp, bfdev_rb_node_t ***linkp, - bool *leftmostp) + bfdev_bool *leftmostp) { - bool leftmost; + bfdev_bool leftmost; long retval; *linkp = &root->node; - leftmost = true; + leftmost = bfdev_true; if (bfdev_unlikely(!**linkp)) { - *parentp = NULL; + *parentp = BFDEV_NULL; goto finish; } @@ -588,7 +590,7 @@ bfdev_rb_find_last(bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find, *linkp = &(**linkp)->left; else /* retval < 0 */ { *linkp = &(**linkp)->right; - leftmost = false; + leftmost = bfdev_false; } } while (**linkp); @@ -596,37 +598,37 @@ bfdev_rb_find_last(bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find, if (leftmostp) *leftmostp = leftmost; - return NULL; + return BFDEV_NULL; } export bfdev_rb_node_t ** bfdev_rb_parent(bfdev_rb_root_t *root, bfdev_rb_node_t **parentp, bfdev_rb_node_t *node, bfdev_rb_cmp_t cmp, void *pdata, - bool *leftmostp) + bfdev_bool *leftmostp) { bfdev_rb_node_t **link; - bool leftmost; + bfdev_bool leftmost; long retval; link = &root->node; - leftmost = true; + leftmost = bfdev_true; if (bfdev_unlikely(!*link)) { - *parentp = NULL; + *parentp = BFDEV_NULL; goto finish; } do { retval = cmp(node, *link, pdata); if (bfdev_unlikely(!retval)) - return NULL; + return BFDEV_NULL; *parentp = *link; if (retval < 0) link = &(*link)->left; else /* retval > 0 */ { link = &(*link)->right; - leftmost = false; + leftmost = bfdev_false; } } while (*link); diff --git a/src/respool.c b/src/respool.c index 6ce5bca0..1b3075e2 100644 --- a/src/respool.c +++ b/src/respool.c @@ -18,7 +18,7 @@ bfdev_respool_find(bfdev_respool_t *pool, return walk; } - return NULL; + return BFDEV_NULL; } export void diff --git a/src/ringbuf.c b/src/ringbuf.c index b78a6fea..b6b4bc81 100644 --- a/src/ringbuf.c +++ b/src/ringbuf.c @@ -23,8 +23,8 @@ } \ \ llen = bfdev_min(len, size - offset); \ - bfport_memcpy(copy1, copy2, llen); \ - bfport_memcpy(fold1, fold2, len - llen); \ + bfdev_memcpy(copy1, copy2, llen); \ + bfdev_memcpy(fold1, fold2, len - llen); \ } while (0) static __bfdev_always_inline void @@ -51,7 +51,7 @@ static __bfdev_always_inline unsigned long ringbuf_record_peek(bfdev_ringbuf_t *ringbuf, unsigned long recsize) { unsigned long mask, offset, length; - uint8_t *data; + bfdev_u8 *data; mask = ringbuf->mask; offset = ringbuf->out; @@ -74,10 +74,11 @@ ringbuf_record_peek(bfdev_ringbuf_t *ringbuf, unsigned long recsize) } static __bfdev_always_inline void -ringbuf_record_poke(bfdev_ringbuf_t *ringbuf, unsigned long len, unsigned long recsize) +ringbuf_record_poke(bfdev_ringbuf_t *ringbuf, unsigned long len, + unsigned long recsize) { unsigned long mask, offset; - uint8_t *data; + bfdev_u8 *data; mask = ringbuf->mask; offset = ringbuf->out; @@ -90,13 +91,13 @@ ringbuf_record_poke(bfdev_ringbuf_t *ringbuf, unsigned long len, unsigned long r } while (recsize--) { - data[offset & mask] = (uint8_t)len; + data[offset & mask] = (bfdev_u8)len; offset += ringbuf->esize; len >>= BFDEV_BITS_PER_U8; } } -static inline bool +static inline bfdev_bool ringbuf_empty(bfdev_ringbuf_t *ringbuf) { return ringbuf->in == ringbuf->out; @@ -224,7 +225,7 @@ bfdev_ringbuf_in_record(bfdev_ringbuf_t *ringbuf, const void *buff, unsigned lon export int bfdev_ringbuf_dynamic_alloc(bfdev_ringbuf_t *ringbuf, const bfdev_alloc_t *alloc, - size_t esize, size_t size) + bfdev_size_t esize, bfdev_size_t size) { size = bfdev_pow2_roundup(size); if (size < 2) @@ -255,5 +256,5 @@ bfdev_ringbuf_dynamic_free(bfdev_ringbuf_t *ringbuf) alloc = ringbuf->alloc; bfdev_free(alloc, ringbuf->data); - ringbuf->data = NULL; + ringbuf->data = BFDEV_NULL; } diff --git a/src/scnprintf.c b/src/scnprintf.c index 13d08027..b6bc0bc9 100644 --- a/src/scnprintf.c +++ b/src/scnprintf.c @@ -5,10 +5,12 @@ #include #include +#include #include export int -bfdev_vscnprintf(char *buf, size_t size, const char *fmt, va_list args) +bfdev_vscnprintf(char *buf, bfdev_size_t size, + const char *fmt, bfdev_va_list args) { int len; @@ -23,14 +25,14 @@ bfdev_vscnprintf(char *buf, size_t size, const char *fmt, va_list args) } export int -bfdev_scnprintf(char *buf, size_t size, const char *fmt, ...) +bfdev_scnprintf(char *buf, bfdev_size_t size, const char *fmt, ...) { - va_list args; + bfdev_va_list args; int len; - va_start(args, fmt); + bfdev_va_start(args, fmt); len = bfdev_vscnprintf(buf, size, fmt, args); - va_end(args); + bfdev_va_end(args); return len; } diff --git a/src/skiplist.c b/src/skiplist.c index caaa16b4..5f04ca3e 100644 --- a/src/skiplist.c +++ b/src/skiplist.c @@ -5,6 +5,7 @@ #include #include +#include #include static unsigned int @@ -14,7 +15,7 @@ random_level(bfdev_skip_head_t *head) level = 1; while (level < head->levels) { - if (bfport_rand() > RAND_MAX >> 2) + if ((bfport_rand() & 0xffff) > 0xffff >> 2) break; level++; } @@ -33,7 +34,7 @@ skipnode_find(bfdev_skip_head_t *head, bfdev_find_t find, level = head->curr; if (bfdev_unlikely(!level)) - return NULL; + return BFDEV_NULL; list = &head->nodes[level - 1]; end = list; @@ -58,13 +59,13 @@ skipnode_find(bfdev_skip_head_t *head, bfdev_find_t find, list = end->prev; } - return NULL; + return BFDEV_NULL; } export bfdev_skip_node_t * bfdev_skiplist_find(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata) { - return skipnode_find(head, find, pdata, NULL); + return skipnode_find(head, find, pdata, BFDEV_NULL); } export int @@ -164,11 +165,11 @@ bfdev_skiplist_create(const bfdev_alloc_t *alloc, unsigned int levels) unsigned int count; if (bfdev_unlikely(!levels)) - return NULL; + return BFDEV_NULL; head = bfdev_malloc(alloc, sizeof(*head) + sizeof(*head->nodes) * levels); if (bfdev_unlikely(!head)) - return NULL; + return BFDEV_NULL; for (count = 0; count < levels; ++count) bfdev_list_head_init(&head->nodes[count]); diff --git a/src/slist-debug.c b/src/slist-debug.c index fb642d2e..b6563dd0 100644 --- a/src/slist-debug.c +++ b/src/slist-debug.c @@ -11,7 +11,7 @@ #include #include -export bool +export bfdev_bool bfdev_slist_check_add(bfdev_slist_head_t *node, bfdev_slist_head_t *newn) { if (bfdev_unlikely(node->next == newn)) { @@ -20,7 +20,7 @@ bfdev_slist_check_add(bfdev_slist_head_t *node, bfdev_slist_head_t *newn) " should not be newn (%p)\n", node, newn ); - return false; + return bfdev_false; } if (bfdev_unlikely(node == newn)) { @@ -29,13 +29,13 @@ bfdev_slist_check_add(bfdev_slist_head_t *node, bfdev_slist_head_t *newn) " newn=(%p), node=(%p)\n", newn, node ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } -export bool +export bfdev_bool bfdev_slist_check_del(bfdev_slist_head_t *node) { if (bfdev_unlikely(node->next == BFDEV_POISON_SLIST)) { @@ -44,8 +44,8 @@ bfdev_slist_check_del(bfdev_slist_head_t *node) " should not be BFDEV_POISON_SLIST (%p)\n", node, BFDEV_POISON_SLIST ); - return false; + return bfdev_false; } - return true; + return bfdev_true; } diff --git a/src/sort.c b/src/sort.c index 0cca137a..c187bc54 100644 --- a/src/sort.c +++ b/src/sort.c @@ -8,20 +8,20 @@ #include static __bfdev_noinline void -sort_swap(size_t cells, void *cel1, void *cel2) +sort_swap(bfdev_size_t cells, void *cel1, void *cel2) { void *buff; /* alloca hates inline */ buff = bfdev_alloca(cells); - bfport_memcpy(buff, cel1, cells); - bfport_memcpy(cel1, cel2, cells); - bfport_memcpy(cel2, buff, cells); + bfdev_memcpy(buff, cel1, cells); + bfdev_memcpy(cel1, cel2, cells); + bfdev_memcpy(cel2, buff, cells); } -static __bfdev_attribute_const __bfdev_always_inline size_t -parent(size_t cells, unsigned int lsbit, size_t index) +static __bfdev_attribute_const __bfdev_always_inline bfdev_size_t +parent(bfdev_size_t cells, unsigned int lsbit, bfdev_size_t index) { index -= cells; index -= cells & -(index & lsbit); @@ -29,10 +29,11 @@ parent(size_t cells, unsigned int lsbit, size_t index) } export int -bfdev_sort(void *base, size_t num, size_t cells, bfdev_cmp_t cmp, void *pdata) +bfdev_sort(void *base, bfdev_size_t num, bfdev_size_t cells, + bfdev_cmp_t cmp, void *pdata) { - size_t idx1, idx2, idx3, idx4; - size_t size, lsbit; + bfdev_size_t idx1, idx2, idx3, idx4; + bfdev_size_t size, lsbit; idx1 = (num >> 1) * cells; if (bfdev_unlikely(!base || !cmp || !idx1)) diff --git a/src/textsearch/bm.c b/src/textsearch/bm.c index 24cdeda3..09ef4f63 100644 --- a/src/textsearch/bm.c +++ b/src/textsearch/bm.c @@ -8,9 +8,9 @@ struct bm_context { bfdev_ts_context_t tsc; - uint8_t *pattern; + bfdev_u8 *pattern; unsigned int pattern_len; - unsigned int bad_shift[UINT8_MAX]; + unsigned int bad_shift[BFDEV_UINT8_MAX]; unsigned int good_shift[0]; }; @@ -40,12 +40,12 @@ bm_pattern_len(bfdev_ts_context_t *tsc) static unsigned int bm_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) { - #define find_pattern() (icase ? toupper(text[shift - index]) : text[shift - index]) + #define find_pattern() (icase ? bfdev_toupper(text[shift - index]) : text[shift - index]) struct bm_context *bctx; unsigned int bad_shift, good_shift, consumed; unsigned int length, index, shift; - const uint8_t *text; - bool icase; + const bfdev_u8 *text; + bfdev_bool icase; bctx = ts_to_bm(tsc); icase = bfdev_ts_igcase_test(tsc); @@ -55,7 +55,7 @@ bm_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) for (;;) { length = tsc->next_block(tsc, tss, consumed, (const void **)&text); if (bfdev_unlikely(!length)) - return UINT_MAX; + return BFDEV_UINT_MAX; while (shift < length) { for (index = 0; index < bctx->pattern_len; ++index) { @@ -77,8 +77,8 @@ bm_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) #undef find_pattern } -static inline bool -subpattern(const uint8_t *pattern, int index, int j, int g) +static inline bfdev_bool +subpattern(const bfdev_u8 *pattern, int index, int j, int g) { int x, y; @@ -87,12 +87,12 @@ subpattern(const uint8_t *pattern, int index, int j, int g) while (y && pattern[x--] == pattern[y--]) { if (y < 0) - return true; + return bfdev_true; if (!--g) return pattern[index - 1] != pattern[j - 1]; } - return false; + return bfdev_false; } static inline void @@ -100,13 +100,13 @@ bm_compute_prefix(struct bm_context *bctx) { int index, start, count; - for (index = 0; index < UINT8_MAX; ++index) + for (index = 0; index < BFDEV_UINT8_MAX; ++index) bctx->bad_shift[index] = bctx->pattern_len; for (index = 0; index < bctx->pattern_len - 1; ++index) { bctx->bad_shift[bctx->pattern[index]] = bctx->pattern_len - index - 1; if (bfdev_ts_igcase_test(&bctx->tsc)) { - bctx->bad_shift[tolower(bctx->pattern[index])] = + bctx->bad_shift[bfdev_tolower(bctx->pattern[index])] = bctx->pattern_len - index - 1; } } @@ -127,7 +127,7 @@ bm_compute_prefix(struct bm_context *bctx) static bfdev_ts_context_t * bm_prepare(const bfdev_alloc_t *alloc, const void *pattern, - size_t len, unsigned long flags) + bfdev_size_t len, unsigned long flags) { struct bm_context *bctx; unsigned int gsize, index; @@ -135,16 +135,16 @@ bm_prepare(const bfdev_alloc_t *alloc, const void *pattern, gsize = sizeof(unsigned int) * len; bctx = bfdev_malloc(alloc, sizeof(*bctx) + gsize + len); if (bfdev_unlikely(!bctx)) - return NULL; + return BFDEV_NULL; bctx->tsc.flags = flags; bctx->pattern_len = len; bctx->pattern = (void *)bctx + sizeof(*bctx) + gsize; if (!bfdev_ts_igcase_test(&bctx->tsc)) - bfport_memcpy(bctx->pattern, pattern, len); + bfdev_memcpy(bctx->pattern, pattern, len); else for (index = 0; index < len; ++index) - bctx->pattern[index] = toupper(((char *)pattern)[index]); + bctx->pattern[index] = bfdev_toupper(((char *)pattern)[index]); bm_compute_prefix(bctx); return &bctx->tsc; diff --git a/src/textsearch/kmp.c b/src/textsearch/kmp.c index d6592b19..4156b344 100644 --- a/src/textsearch/kmp.c +++ b/src/textsearch/kmp.c @@ -39,11 +39,11 @@ kmp_pattern_len(bfdev_ts_context_t *tsc) static unsigned int kmp_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) { - #define find_pattern() (icase ? toupper(text[index]) : text[index]) + #define find_pattern() (icase ? bfdev_toupper(text[index]) : text[index]) struct kmp_context *kctx; unsigned int consumed, length, index, match; const char *text; - bool icase; + bfdev_bool icase; kctx = ts_to_kmp(tsc); icase = bfdev_ts_igcase_test(tsc); @@ -53,7 +53,7 @@ kmp_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) for (;;) { length = tsc->next_block(tsc, tss, consumed, (const void **)&text); if (bfdev_unlikely(!length)) - return UINT_MAX; + return BFDEV_UINT_MAX; for (index = 0; index < length; ++index) { while (match && kctx->pattern[match] != find_pattern()) @@ -92,7 +92,7 @@ kmp_compute_prefix(struct kmp_context *kctx) static bfdev_ts_context_t * kmp_prepare(const bfdev_alloc_t *alloc, const void *pattern, - size_t len, unsigned long flags) + bfdev_size_t len, unsigned long flags) { struct kmp_context *kctx; unsigned int prefix_size, index; @@ -100,16 +100,16 @@ kmp_prepare(const bfdev_alloc_t *alloc, const void *pattern, prefix_size = sizeof(unsigned int) * len; kctx = bfdev_zalloc(alloc, sizeof(*kctx) + prefix_size + len); if (bfdev_unlikely(!kctx)) - return NULL; + return BFDEV_NULL; kctx->tsc.flags = flags; kctx->pattern_len = len; kctx->pattern = (void *)kctx + sizeof(*kctx) + prefix_size; if (!bfdev_ts_igcase_test(&kctx->tsc)) - bfport_memcpy(kctx->pattern, pattern, len); + bfdev_memcpy(kctx->pattern, pattern, len); else for (index = 0; index < len; ++index) - kctx->pattern[index] = toupper(((char *)pattern)[index]); + kctx->pattern[index] = bfdev_toupper(((char *)pattern)[index]); kmp_compute_prefix(kctx); return &kctx->tsc; diff --git a/src/textsearch/sunday.c b/src/textsearch/sunday.c index 1a3d7b31..90521777 100644 --- a/src/textsearch/sunday.c +++ b/src/textsearch/sunday.c @@ -9,8 +9,8 @@ struct sunday_context { bfdev_ts_context_t tsc; unsigned int pattern_len; - unsigned int shift_table[UINT8_MAX]; - uint8_t pattern[0]; + unsigned int shift_table[BFDEV_UINT8_MAX]; + bfdev_u8 pattern[0]; }; #define ts_to_sunday(ptr) \ @@ -39,11 +39,11 @@ sunday_pattern_len(bfdev_ts_context_t *tsc) static unsigned int sunday_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) { - #define find_pattern() (icase ? toupper(text[shift + index]) : text[shift + index]) + #define find_pattern() (icase ? bfdev_toupper(text[shift + index]) : text[shift + index]) struct sunday_context *sctx; unsigned int consumed, length, index, shift; - const uint8_t *text; - bool icase; + const bfdev_u8 *text; + bfdev_bool icase; sctx = ts_to_sunday(tsc); icase = bfdev_ts_igcase_test(tsc); @@ -53,7 +53,7 @@ sunday_find(bfdev_ts_context_t *tsc, bfdev_ts_state_t *tss) for (;;) { length = tsc->next_block(tsc, tss, consumed, (const void **)&text); if (bfdev_unlikely(!length)) - return UINT_MAX; + return BFDEV_UINT_MAX; while (sctx->pattern_len + shift <= length) { for (index = 0; index < sctx->pattern_len; ++index) { @@ -81,13 +81,13 @@ sunday_compute_prefix(struct sunday_context *sctx) { unsigned int index; - for (index = 0; index < UINT8_MAX; ++index) + for (index = 0; index < BFDEV_UINT8_MAX; ++index) sctx->shift_table[index] = sctx->pattern_len + 1; for (index = 0; index < sctx->pattern_len; ++index) { sctx->shift_table[sctx->pattern[index]] = sctx->pattern_len - index; if (bfdev_ts_igcase_test(&sctx->tsc)) { - sctx->shift_table[tolower(sctx->pattern[index])] = + sctx->shift_table[bfdev_tolower(sctx->pattern[index])] = sctx->pattern_len - index; } } @@ -95,22 +95,22 @@ sunday_compute_prefix(struct sunday_context *sctx) static bfdev_ts_context_t * sunday_prepare(const bfdev_alloc_t *alloc, const void *pattern, - size_t len, unsigned long flags) + bfdev_size_t len, unsigned long flags) { struct sunday_context *sctx; unsigned int index; sctx = bfdev_malloc(alloc, sizeof(*sctx) + len); if (!sctx) - return NULL; + return BFDEV_NULL; sctx->tsc.flags = flags; sctx->pattern_len = len; if (!bfdev_ts_igcase_test(&sctx->tsc)) - bfport_memcpy(sctx->pattern, pattern, len); + bfdev_memcpy(sctx->pattern, pattern, len); else for (index = 0; index < len; ++index) - sctx->pattern[index] = toupper(((char *)pattern)[index]); + sctx->pattern[index] = bfdev_toupper(((char *)pattern)[index]); sunday_compute_prefix(sctx); return &sctx->tsc; diff --git a/src/textsearch/textsearch.c b/src/textsearch/textsearch.c index 2720e3fa..e749cea3 100644 --- a/src/textsearch/textsearch.c +++ b/src/textsearch/textsearch.c @@ -16,40 +16,40 @@ textsearch_algorithm_find(const char *name) bfdev_ts_algorithm_t *walk; bfdev_list_for_each_entry(walk, &textsearch_algorithms, list) { - if (!bfport_strcmp(walk->name, name)) + if (!bfdev_strcmp(walk->name, name)) return walk; } - return NULL; + return BFDEV_NULL; } -static bool +static bfdev_bool textsearch_algorithm_exist(bfdev_ts_algorithm_t *algo) { bfdev_ts_algorithm_t *walk; bfdev_list_for_each_entry(walk, &textsearch_algorithms, list) { if (walk == algo) - return true; + return bfdev_true; } - return false; + return bfdev_false; } export bfdev_ts_context_t * bfdev_textsearch_create(const bfdev_alloc_t *alloc, const char *name, - const void *pattern, size_t len, unsigned long flags) + const void *pattern, bfdev_size_t len, unsigned long flags) { bfdev_ts_algorithm_t *algo; bfdev_ts_context_t *tsc; algo = textsearch_algorithm_find(name); if (!algo) - return NULL; + return BFDEV_NULL; tsc = algo->prepare(alloc, pattern, len, flags); if (!tsc) - return NULL; + return BFDEV_NULL; tsc->algo = algo; tsc->alloc = alloc; diff --git a/src/tokenbucket.c b/src/tokenbucket.c index 0ee5544d..389b677d 100644 --- a/src/tokenbucket.c +++ b/src/tokenbucket.c @@ -8,13 +8,13 @@ #include #include -export bool +export bfdev_bool bfdev_tokenbucket(bfdev_tokenbucket_t *limit, bfdev_time_t current) { unsigned int generate; if (!limit->interval) - return true; + return bfdev_true; if (bfdev_unlikely(!limit->last)) { limit->current = limit->capacity; @@ -28,11 +28,11 @@ bfdev_tokenbucket(bfdev_tokenbucket_t *limit, bfdev_time_t current) if (bfdev_unlikely(!limit->current)) { limit->missed++; - return false; + return bfdev_false; } limit->current--; limit->passed++; - return true; + return bfdev_true; } diff --git a/testsuite/array/fuzzy.c b/testsuite/array/fuzzy.c index ad27b167..e16e12d1 100644 --- a/testsuite/array/fuzzy.c +++ b/testsuite/array/fuzzy.c @@ -3,6 +3,7 @@ * Copyright(c) 2024 John Sanpe */ +#include #include #define TEST_CELLS 16 diff --git a/testsuite/bitwalk/fuzzy.c b/testsuite/bitwalk/fuzzy.c index decd02b8..d9083d67 100644 --- a/testsuite/bitwalk/fuzzy.c +++ b/testsuite/bitwalk/fuzzy.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/testsuite/glob/selftest.c b/testsuite/glob/selftest.c index 95a492b2..a203f51e 100644 --- a/testsuite/glob/selftest.c +++ b/testsuite/glob/selftest.c @@ -6,6 +6,8 @@ #define MODULE_NAME "bitwalk-selftest" #define bfdev_log_fmt(fmt) MODULE_NAME ":" fmt +#include +#include #include #include #include diff --git a/testsuite/mpi/empty.c b/testsuite/mpi/empty.c index 94548eef..a0e9fa3c 100644 --- a/testsuite/mpi/empty.c +++ b/testsuite/mpi/empty.c @@ -3,6 +3,7 @@ * Copyright(c) 2024 John Sanpe */ +#include #include #include diff --git a/testsuite/mpi/fuzzy.c b/testsuite/mpi/fuzzy.c index d9a7ff97..07e5b882 100644 --- a/testsuite/mpi/fuzzy.c +++ b/testsuite/mpi/fuzzy.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include diff --git a/testsuite/randpool.h b/testsuite/randpool.h index e8aa5b30..3e4bd858 100644 --- a/testsuite/randpool.h +++ b/testsuite/randpool.h @@ -7,6 +7,7 @@ #define _TESTSUITE_RANDPOOL_H_ #include +#include #include #include #include diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index de63a009..a7506ea2 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -7,6 +7,7 @@ #define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt #include +#include #include #include #include From 17fa482139139b138b1e55a6343b7e227a6fff81 Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Thu, 27 Mar 2025 10:13:41 +0800 Subject: [PATCH 2/4] feat port: added generic platform support Signed-off-by: John Sanpe --- .github/workflows/ubuntu-generic.yml | 50 +++++++++ port/build.cmake | 4 + port/generic/build.cmake | 12 ++ port/generic/log.c | 16 +++ port/generic/stdio.c | 17 +++ port/generic/stdlib.c | 45 ++++++++ port/generic/string.c | 162 +++++++++++++++++++++++++++ 7 files changed, 306 insertions(+) create mode 100644 .github/workflows/ubuntu-generic.yml create mode 100644 port/generic/build.cmake create mode 100644 port/generic/log.c create mode 100644 port/generic/stdio.c create mode 100644 port/generic/stdlib.c create mode 100644 port/generic/string.c diff --git a/.github/workflows/ubuntu-generic.yml b/.github/workflows/ubuntu-generic.yml new file mode 100644 index 00000000..936d8e9f --- /dev/null +++ b/.github/workflows/ubuntu-generic.yml @@ -0,0 +1,50 @@ +name: build generic on ubuntu gcc + +on: + repository_dispatch: + workflow_dispatch: + push: + pull_request: + schedule: + - cron: '0 */2 * * *' + +env: + BUILD_TYPE: Release + +jobs: + build: + name: Test on ${{matrix.os}} + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-22.04] + + steps: + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: install dependencies + run: | + sudo apt update + sudo apt install cmake make gcc ccache + + - name: configure cmake + run: | + cmake -B ${{github.workspace}}/build \ + -D CMAKE_INSTALL_PREFIX=${{github.workspace}}/build/install \ + -D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ + -D CMAKE_C_COMPILER=/usr/lib/ccache/gcc \ + -D CMAKE_SYSTEM_NAME=Generic -Wno-dev \ + -D BFDEV_DEVEL=ON + + - name: make + run: | + cmake --build ${{github.workspace}}/build \ + --config ${{env.BUILD_TYPE}} + + - name: install + run: | + cmake --build ${{github.workspace}}/build \ + --config ${{env.BUILD_TYPE}} -- install diff --git a/port/build.cmake b/port/build.cmake index c543976e..bedad310 100644 --- a/port/build.cmake +++ b/port/build.cmake @@ -15,6 +15,10 @@ if(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD|FreeBSD|NetBSD|OpenBSD|DragonFly") set(BFDEV_PORT_TYPE "posix") endif() +if(CMAKE_SYSTEM_NAME MATCHES "Generic") + set(BFDEV_PORT_TYPE "generic") +endif() + if(BFDEV_PORT_TYPE) include(${BFDEV_PORT_PATH}/${BFDEV_PORT_TYPE}/build.cmake) else() diff --git a/port/generic/build.cmake b/port/generic/build.cmake new file mode 100644 index 00000000..196adb4a --- /dev/null +++ b/port/generic/build.cmake @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# +# Copyright(c) 2025 John Sanpe +# + +set(BFDEV_SOURCE + ${BFDEV_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/log.c + ${CMAKE_CURRENT_LIST_DIR}/stdio.c + ${CMAKE_CURRENT_LIST_DIR}/stdlib.c + ${CMAKE_CURRENT_LIST_DIR}/string.c +) diff --git a/port/generic/log.c b/port/generic/log.c new file mode 100644 index 00000000..951a8815 --- /dev/null +++ b/port/generic/log.c @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include +#include + +/* TODO: PORTME */ + +export int +bfport_log_write(bfdev_log_message_t *msg) +{ + return 0; +} diff --git a/port/generic/stdio.c b/port/generic/stdio.c new file mode 100644 index 00000000..c4794543 --- /dev/null +++ b/port/generic/stdio.c @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include +#include + +/* TODO: PORTME */ + +export int +bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *fmt, + bfdev_va_list arg) +{ + return 0; +} diff --git a/port/generic/stdlib.c b/port/generic/stdlib.c new file mode 100644 index 00000000..00d2565a --- /dev/null +++ b/port/generic/stdlib.c @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include + +/* TODO: PORTME */ + +export __bfdev_malloc void * +bfport_malloc(bfdev_size_t size) +{ + return BFDEV_NULL; +} + +export __bfdev_malloc void * +bfport_calloc(bfdev_size_t nmemb, bfdev_size_t size) +{ + return BFDEV_NULL; +} + +export __bfdev_malloc void * +bfport_realloc(void *ptr, bfdev_size_t size) +{ + return BFDEV_NULL; +} + +export void +bfport_free(void *ptr) +{ + return; +} + +export int +bfport_rand(void) +{ + return 0; +} + +export __bfdev_noreturn void +bfport_abort(void) +{ + for (;;); +} diff --git a/port/generic/string.c b/port/generic/string.c new file mode 100644 index 00000000..da35799f --- /dev/null +++ b/port/generic/string.c @@ -0,0 +1,162 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * Copyright(c) 2025 John Sanpe + */ + +#include +#include + +export void * +bfport_memcpy(void *dest, const void *src, bfdev_size_t n) +{ + const unsigned char *nsrc; + unsigned char *ndest; + + ndest = dest; + nsrc = src; + + while (n--) + *ndest++ = *nsrc++; + + return dest; +} + +export void * +bfport_memset(void *s, int c, bfdev_size_t n) +{ + unsigned char *xs; + + xs = s; + while (n--) + *xs++ = c; + + return s; +} + +export int +bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n) +{ + const unsigned char *su1, *su2; + int res; + + res = 0; + for (su1 = s1, su2 = s2; 0 < n; ++su1, ++su2, n--) { + if ((res = *su1 - *su2) != 0) + break; + } + + return res; +} + +export int +bfport_strcmp(const char *s1, const char *s2) +{ + int cp; + + cp = 0; + while (!(cp = *s1++ - *s2++)) { + if (*s1 == '\0') + break; + } + + return cp; +} + +export char * +bfport_strchr(const char *s, int c) +{ + for (; *s != (char)c; ++s) { + if (*s == '\0') + return BFDEV_NULL; + } + + return (char *)s; +} + +export bfdev_size_t +bfport_strspn(const char *s, const char *accept) +{ + const unsigned char *p, *a; + bfdev_size_t count; + + count = 0; + for (p = s; *p != '\0'; ++p) { + for (a = accept; *a != '\0'; ++a) { + if (*p == *a) + break; + } + if (*a == '\0') + return count; + ++count; + } + + return count; +} + +export bfdev_size_t +bfport_strcspn(const char *s, const char *reject) +{ + const unsigned char *p, *r; + bfdev_size_t count; + + count = 0; + for (p = s; *p != '\0'; ++p) { + for (r = reject; *r != '\0'; ++r) { + if (*p == *r) + return count; + } + ++count; + } + + return count; +} + +export char * +bfport_strcpy(char *dest, const char *src) +{ + unsigned char *tmp; + + tmp = dest; + while ((*tmp++ = *src++) != '\0') + ; + + return dest; +} + +export char * +bfport_strncpy(char *dest, const char *src, bfdev_size_t n) +{ + unsigned char *tmp; + + for (tmp = dest; n--; ++tmp) { + if ((*tmp = *src) != 0) + src++; + } + + return dest; +} + +export bfdev_size_t +bfport_strlen(const char *s) +{ + const unsigned char *len; + + len = s; + while (*len != '\0') + len++; + + return (char *)len - s; +} + +export bfdev_size_t +bfport_strnlen(const char *s, bfdev_size_t len) +{ + const unsigned char *sc; + + for (sc = s; len--; ++sc) { + if (*sc == '\0') + break; + } + + return (char *)sc - s; +} From 6f29c5e7ac3a586c638fb125473d3592d2381ce2 Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Thu, 27 Mar 2025 12:14:45 +0800 Subject: [PATCH 3/4] fixup port: hidden bfdev port functions Signed-off-by: John Sanpe --- port/generic/log.c | 2 +- port/generic/stdio.c | 3 +-- port/generic/stdlib.c | 12 ++++++------ port/generic/string.c | 22 +++++++++++----------- port/posix/log.c | 9 +++++++-- port/posix/stdio.c | 3 +-- port/posix/stdlib.c | 12 ++++++------ port/posix/string.c | 22 +++++++++++----------- src/port/string.c | 22 +++++++++++----------- 9 files changed, 55 insertions(+), 52 deletions(-) diff --git a/port/generic/log.c b/port/generic/log.c index 951a8815..e7ded6d2 100644 --- a/port/generic/log.c +++ b/port/generic/log.c @@ -9,7 +9,7 @@ /* TODO: PORTME */ -export int +hidden int bfport_log_write(bfdev_log_message_t *msg) { return 0; diff --git a/port/generic/stdio.c b/port/generic/stdio.c index c4794543..c3101224 100644 --- a/port/generic/stdio.c +++ b/port/generic/stdio.c @@ -3,13 +3,12 @@ * Copyright(c) 2025 John Sanpe */ -#include #include #include /* TODO: PORTME */ -export int +hidden int bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *fmt, bfdev_va_list arg) { diff --git a/port/generic/stdlib.c b/port/generic/stdlib.c index 00d2565a..b5dd204f 100644 --- a/port/generic/stdlib.c +++ b/port/generic/stdlib.c @@ -8,37 +8,37 @@ /* TODO: PORTME */ -export __bfdev_malloc void * +hidden __bfdev_malloc void * bfport_malloc(bfdev_size_t size) { return BFDEV_NULL; } -export __bfdev_malloc void * +hidden __bfdev_malloc void * bfport_calloc(bfdev_size_t nmemb, bfdev_size_t size) { return BFDEV_NULL; } -export __bfdev_malloc void * +hidden __bfdev_malloc void * bfport_realloc(void *ptr, bfdev_size_t size) { return BFDEV_NULL; } -export void +hidden void bfport_free(void *ptr) { return; } -export int +hidden int bfport_rand(void) { return 0; } -export __bfdev_noreturn void +hidden __bfdev_noreturn void bfport_abort(void) { for (;;); diff --git a/port/generic/string.c b/port/generic/string.c index da35799f..d7df128a 100644 --- a/port/generic/string.c +++ b/port/generic/string.c @@ -6,7 +6,7 @@ #include #include -export void * +hidden void * bfport_memcpy(void *dest, const void *src, bfdev_size_t n) { const unsigned char *nsrc; @@ -21,7 +21,7 @@ bfport_memcpy(void *dest, const void *src, bfdev_size_t n) return dest; } -export void * +hidden void * bfport_memset(void *s, int c, bfdev_size_t n) { unsigned char *xs; @@ -33,7 +33,7 @@ bfport_memset(void *s, int c, bfdev_size_t n) return s; } -export int +hidden int bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n) { const unsigned char *su1, *su2; @@ -48,7 +48,7 @@ bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n) return res; } -export int +hidden int bfport_strcmp(const char *s1, const char *s2) { int cp; @@ -62,7 +62,7 @@ bfport_strcmp(const char *s1, const char *s2) return cp; } -export char * +hidden char * bfport_strchr(const char *s, int c) { for (; *s != (char)c; ++s) { @@ -73,7 +73,7 @@ bfport_strchr(const char *s, int c) return (char *)s; } -export bfdev_size_t +hidden bfdev_size_t bfport_strspn(const char *s, const char *accept) { const unsigned char *p, *a; @@ -93,7 +93,7 @@ bfport_strspn(const char *s, const char *accept) return count; } -export bfdev_size_t +hidden bfdev_size_t bfport_strcspn(const char *s, const char *reject) { const unsigned char *p, *r; @@ -111,7 +111,7 @@ bfport_strcspn(const char *s, const char *reject) return count; } -export char * +hidden char * bfport_strcpy(char *dest, const char *src) { unsigned char *tmp; @@ -123,7 +123,7 @@ bfport_strcpy(char *dest, const char *src) return dest; } -export char * +hidden char * bfport_strncpy(char *dest, const char *src, bfdev_size_t n) { unsigned char *tmp; @@ -136,7 +136,7 @@ bfport_strncpy(char *dest, const char *src, bfdev_size_t n) return dest; } -export bfdev_size_t +hidden bfdev_size_t bfport_strlen(const char *s) { const unsigned char *len; @@ -148,7 +148,7 @@ bfport_strlen(const char *s) return (char *)len - s; } -export bfdev_size_t +hidden bfdev_size_t bfport_strnlen(const char *s, bfdev_size_t len) { const unsigned char *sc; diff --git a/port/posix/log.c b/port/posix/log.c index 070711f5..52b3828d 100644 --- a/port/posix/log.c +++ b/port/posix/log.c @@ -5,10 +5,15 @@ #include #include -#include #include -export int +#if defined(__FreeBSD__) && defined(_KERNEL) +# include +#else +# include +#endif + +hidden int bfport_log_write(bfdev_log_message_t *msg) { FILE *file; diff --git a/port/posix/stdio.c b/port/posix/stdio.c index eee380b0..1fbf9902 100644 --- a/port/posix/stdio.c +++ b/port/posix/stdio.c @@ -3,7 +3,6 @@ * Copyright(c) 2025 John Sanpe */ -#include #include #include @@ -13,7 +12,7 @@ # include #endif -export int +hidden int bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *fmt, bfdev_va_list arg) { diff --git a/port/posix/stdlib.c b/port/posix/stdlib.c index 378915c4..3b25fb4d 100644 --- a/port/posix/stdlib.c +++ b/port/posix/stdlib.c @@ -12,37 +12,37 @@ # include #endif -export __bfdev_malloc void * +hidden __bfdev_malloc void * bfport_malloc(bfdev_size_t size) { return malloc(size); } -export __bfdev_malloc void * +hidden __bfdev_malloc void * bfport_calloc(bfdev_size_t nmemb, bfdev_size_t size) { return calloc(nmemb, size); } -export __bfdev_malloc void * +hidden __bfdev_malloc void * bfport_realloc(void *ptr, bfdev_size_t size) { return realloc(ptr, size); } -export void +hidden void bfport_free(void *ptr) { free(ptr); } -export int +hidden int bfport_rand(void) { return rand(); } -export __bfdev_noreturn void +hidden __bfdev_noreturn void bfport_abort(void) { abort(); diff --git a/port/posix/string.c b/port/posix/string.c index c0e102f5..ff4d080e 100644 --- a/port/posix/string.c +++ b/port/posix/string.c @@ -12,67 +12,67 @@ # include #endif -export void * +hidden void * bfport_memcpy(void *dest, const void *src, bfdev_size_t n) { return memcpy(dest, src, n); } -export void * +hidden void * bfport_memset(void *s, int c, bfdev_size_t n) { return memset(s, c, n); } -export int +hidden int bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n) { return memcmp(s1, s2, n); } -export int +hidden int bfport_strcmp(const char *s1, const char *s2) { return strcmp(s1, s2); } -export char * +hidden char * bfport_strchr(const char *s, int c) { return strchr(s, c); } -export bfdev_size_t +hidden bfdev_size_t bfport_strspn(const char *s, const char *accept) { return strspn(s, accept); } -export bfdev_size_t +hidden bfdev_size_t bfport_strcspn(const char *s, const char *reject) { return strcspn(s, reject); } -export char * +hidden char * bfport_strcpy(char *dest, const char *src) { return strcpy(dest, src); } -export char * +hidden char * bfport_strncpy(char *dest, const char *src, bfdev_size_t n) { return strncpy(dest, src, n); } -export bfdev_size_t +hidden bfdev_size_t bfport_strlen(const char *s) { return strlen(s); } -export bfdev_size_t +hidden bfdev_size_t bfport_strnlen(const char *s, bfdev_size_t len) { return strnlen(s, len); diff --git a/src/port/string.c b/src/port/string.c index 51bd2676..ac17a162 100644 --- a/src/port/string.c +++ b/src/port/string.c @@ -7,67 +7,67 @@ #include #include -export void * +hidden void * bfdev_memcpy(void *dest, const void *src, bfdev_size_t n) { return bfport_memcpy(dest, src, n); } -export void * +hidden void * bfdev_memset(void *s, int c, bfdev_size_t n) { return bfport_memset(s, c, n); } -export int +hidden int bfdev_memcmp(const void *s1, const void *s2, bfdev_size_t n) { return bfport_memcmp(s1, s2, n); } -export int +hidden int bfdev_strcmp(const char *s1, const char *s2) { return bfport_strcmp(s1, s2); } -export char * +hidden char * bfdev_strchr(const char *s, int c) { return bfport_strchr(s, c); } -export bfdev_size_t +hidden bfdev_size_t bfdev_strspn(const char *s, const char *accept) { return bfport_strspn(s, accept); } -export bfdev_size_t +hidden bfdev_size_t bfdev_strcspn(const char *s, const char *reject) { return bfport_strcspn(s, reject); } -export char * +hidden char * bfdev_strcpy(char *dest, const char *src) { return bfport_strcpy(dest, src); } -export char * +hidden char * bfdev_strncpy(char *dest, const char *src, bfdev_size_t n) { return bfport_strncpy(dest, src, n); } -export bfdev_size_t +hidden bfdev_size_t bfdev_strlen(const char *s) { return bfport_strlen(s); } -export bfdev_size_t +hidden bfdev_size_t bfdev_strnlen(const char *s, bfdev_size_t len) { return bfport_strnlen(s, len); From 72eddef7296e18c608d0dd878b446405825c874a Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Thu, 27 Mar 2025 13:41:25 +0800 Subject: [PATCH 4/4] feat port: added posix system environment check Signed-off-by: John Sanpe --- CMakeLists.txt | 4 +++- build.cmake | 1 + port/posix/build.cmake | 35 +++++++++++++++++++++++++++++++++++ scripts/check.cmake | 26 ++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 scripts/check.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b45f9f72..ddf364c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,9 @@ cmake_minimum_required(VERSION 3.12) project(bfdev VERSION 1.0.6 LANGUAGES C) include(GNUInstallDirs) -include(CheckIncludeFiles) +include(CheckIncludeFile) +include(CheckSymbolExists) +include(CheckTypeSize) set(BFDEV_NAME sirius) set(BFDEV_VERSION ${PROJECT_VERSION}) diff --git a/build.cmake b/build.cmake index 0718f64d..e409a822 100644 --- a/build.cmake +++ b/build.cmake @@ -24,6 +24,7 @@ if(BFDEV_STRICT) ) endif() +include(scripts/check.cmake) include(scripts/sanitize.cmake) include(scripts/asm-generic.cmake) diff --git a/port/posix/build.cmake b/port/posix/build.cmake index 196adb4a..46d6595b 100644 --- a/port/posix/build.cmake +++ b/port/posix/build.cmake @@ -10,3 +10,38 @@ set(BFDEV_SOURCE ${CMAKE_CURRENT_LIST_DIR}/stdlib.c ${CMAKE_CURRENT_LIST_DIR}/string.c ) + +check_header_and_exit("stdio.h") +check_header_and_exit("stdlib.h") +check_header_and_exit("string.h") + +check_type_and_exit("char" "1") +check_type_and_exit("short" "2") +check_type_and_exit("int" "4") +check_type_and_exit("long long" "8") + +# stdio +check_symbol_and_exit("stdio.h" "fwrite") +check_symbol_and_exit("stdio.h" "fflush") +check_symbol_and_exit("stdio.h" "vsnprintf") + +# stdlib +check_symbol_and_exit("stdlib.h" "malloc") +check_symbol_and_exit("stdlib.h" "calloc") +check_symbol_and_exit("stdlib.h" "realloc") +check_symbol_and_exit("stdlib.h" "free") +check_symbol_and_exit("stdlib.h" "rand") +check_symbol_and_exit("stdlib.h" "abort") + +# string +check_symbol_and_exit("string.h" "memcpy") +check_symbol_and_exit("string.h" "memset") +check_symbol_and_exit("string.h" "memcmp") +check_symbol_and_exit("string.h" "strcmp") +check_symbol_and_exit("string.h" "strchr") +check_symbol_and_exit("string.h" "strspn") +check_symbol_and_exit("string.h" "strcspn") +check_symbol_and_exit("string.h" "strcpy") +check_symbol_and_exit("string.h" "strncpy") +check_symbol_and_exit("string.h" "strlen") +check_symbol_and_exit("string.h" "strnlen") diff --git a/scripts/check.cmake b/scripts/check.cmake new file mode 100644 index 00000000..be70d05c --- /dev/null +++ b/scripts/check.cmake @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright(c) 2025 John Sanpe +# + +function(check_header_and_exit name) + check_include_file(${name} ${name}_EXISTS) + if(NOT ${name}_EXISTS) + message(FATAL_ERROR "Header ${name} is required but not found.") + endif() +endfunction() + +function(check_symbol_and_exit header name) + check_symbol_exists(${name} ${header} ${name}_EXISTS) + if(NOT ${name}_EXISTS) + message(FATAL_ERROR "Function ${name} is required but not found.") + endif() +endfunction() + +function(check_type_and_exit name size) + string(REPLACE " " "_" safe_name "${name}") + check_type_size("${name}" ${safe_name}_SIZE) + if(NOT "${${safe_name}_SIZE}" STREQUAL "${size}") + message(FATAL_ERROR "Type '${name}' size mismatch (expected ${size}, got ${${safe_name}_SIZE})") + endif() +endfunction()