diff --git a/array.h b/array.h index 168610d..1a7870a 100644 --- a/array.h +++ b/array.h @@ -13,7 +13,7 @@ typedef struct { void array_init(array_t* array, uint size, uint align); void array_clear(array_t* array); -#define array_at(array, i) ((uint8_t*)(array)->mem + (i)*(array)->size) +#define array_at(array, i) ((u8*)(array)->mem + (i)*(array)->size) #define array_first(array) array_at(array, 0) #define array_last(array) array_at(array, (array)->count - 1) diff --git a/bitmap.c b/bitmap.c index e445617..8ae92b9 100644 --- a/bitmap.c +++ b/bitmap.c @@ -1,6 +1,6 @@ #include "bitmap.h" -uint bit_log2(uint64_t value) +uint bit_log2(u64 value) { uint pow2 = 0; while (value>>=1) pow2++; diff --git a/bitmap.h b/bitmap.h index ff49504..c851151 100644 --- a/bitmap.h +++ b/bitmap.h @@ -8,7 +8,7 @@ #define bit_test(v, p) (!!(v&(1<<(p)))) #define bit_sub2_up(v, p) ((v>>(p))+!!(v&((1<<(p))-1))) #define bit_align2(v, p) (bit_sub2_up(v, (p))<<(p)) -uint bit_log2(uint64_t value); +uint bit_log2(u64 value); #define bitmap(name, s) uword name[bit_sub2_up(s, CU_WORD_POW2)] = {0} #define bitmap_set(m, p, b) \ diff --git a/cutil.c b/cutil.c index 9e28942..b8170cd 100644 --- a/cutil.c +++ b/cutil.c @@ -30,12 +30,12 @@ void _cu_memmove(void* dst, void* src, size_t size) if (dst > src) { uint d = (uword)dst - (uword)src; - src = (uint8_t*)src + size; - dst = (uint8_t*)dst + size; + src = (u8*)src + size; + dst = (u8*)dst + size; while (size) { - src = (uint8_t*)src - d; - dst = (uint8_t*)dst - d; + src = (u8*)src - d; + dst = (u8*)dst - d; cu_memcpy(dst, src, d); size -= d; } @@ -46,8 +46,8 @@ void _cu_memmove(void* dst, void* src, size_t size) while (size) { cu_memcpy(dst, src, d); - src = (uint8_t*)src + d; - dst = (uint8_t*)dst + d; + src = (u8*)src + d; + dst = (u8*)dst + d; size -= d; } } diff --git a/cutypes.h b/cutypes.h index 6c23bb6..af8d242 100644 --- a/cutypes.h +++ b/cutypes.h @@ -1,9 +1,6 @@ #ifndef __CUTYPES_H #define __CUTYPES_H -#include -#include - #define ARCH_UNKNOWN 0 #define x86_64 1 #define x86_32 2 @@ -95,21 +92,35 @@ # define CU_32BIT #endif +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; + +typedef signed char i8; +typedef signed short i16; +typedef signed int i32; + #if defined(CU_64BIT) # define CU_WORD_BITS 64 # define CU_WORD_POW2 6 -typedef uint64_t uword; -typedef int64_t iword; +typedef unsigned long u64; +typedef signed long i64; + +typedef unsigned long uword; +typedef signed long iword; #elif defined(CU_32BIT) # define CU_WORD_BITS 32 # define CU_WORD_POW2 5 -typedef uint32_t uword; -typedef int32_t iword; +typedef unsigned long long u64; +typedef signed long long i64; + +typedef unsigned int uword; +typedef signed int iword; #else # warning "unknown bus width for arch " CU_ARCH #endif -typedef uint32_t uint; +typedef unsigned int uint; #define CU_UINT_SIZE sizeof(uint) typedef void* cu_ptr; diff --git a/endian.c b/endian.c index 1cf1d6f..4bf1041 100644 --- a/endian.c +++ b/endian.c @@ -3,8 +3,8 @@ enum cu_endian_e cu_endian; static const union { - uint8_t bytes[4]; - uint32_t value; + u8 bytes[4]; + u32 value; } host_order = { {0, 1, 2, 3} }; @@ -20,12 +20,12 @@ static enum cu_endian_e endian_detect() return BigEndian; } -static uint16_t sw_bswap16(uint16_t val) +static u16 sw_bswap16(u16 val) { return (val << 8) | (val >> 8); } -static uint32_t sw_bswap32(uint32_t val) +static u32 sw_bswap32(u32 val) { return (val & 0xFF000000U) >> 24 | (val & 0x00FF0000U) >> 8 @@ -33,7 +33,7 @@ static uint32_t sw_bswap32(uint32_t val) | (val & 0x000000FFU) << 24; } -static uint64_t sw_bswap64(uint64_t val) +static u64 sw_bswap64(u64 val) { return (val & 0xFF00000000000000UL) >> 56 | (val & 0x00FF000000000000UL) >> 40 @@ -46,16 +46,16 @@ static uint64_t sw_bswap64(uint64_t val) } #if (CU_ARCH == x86_32) -extern uint16_t hw_bswap16(uint16_t val); -extern uint32_t hw_bswap32(uint32_t val); +extern u16 hw_bswap16(u16 val); +extern u32 hw_bswap32(u32 val); bswap16_t cu_bswap16 = hw_bswap16; bswap32_t cu_bswap32 = hw_bswap32; bswap64_t cu_bswap64 = sw_bswap64; #elif (CU_ARCH == x86_64) -extern uint16_t hw_bswap16(uint16_t val); -extern uint32_t hw_bswap32(uint32_t val); -extern uint64_t hw_bswap64(uint64_t val); +extern u16 hw_bswap16(u16 val); +extern u32 hw_bswap32(u32 val); +extern u64 hw_bswap64(u64 val); bswap16_t cu_bswap16 = hw_bswap16; bswap32_t cu_bswap32 = hw_bswap32; @@ -66,17 +66,17 @@ bswap32_t cu_bswap32 = sw_bswap32; bswap64_t cu_bswap64 = sw_bswap64; #endif -static uint16_t no_bswap16(uint16_t val) +static u16 no_bswap16(u16 val) { return val; } -static uint32_t no_bswap32(uint32_t val) +static u32 no_bswap32(u32 val) { return val; } -static uint64_t no_bswap64(uint64_t val) +static u64 no_bswap64(u64 val) { return val; } diff --git a/endian.h b/endian.h index 4261f90..ee23a77 100644 --- a/endian.h +++ b/endian.h @@ -10,9 +10,9 @@ enum cu_endian_e { extern enum cu_endian_e cu_endian; -typedef uint16_t (*bswap16_t)(uint16_t); -typedef uint32_t (*bswap32_t)(uint32_t); -typedef uint64_t (*bswap64_t)(uint64_t); +typedef u16 (*bswap16_t)(u16); +typedef u32 (*bswap32_t)(u32); +typedef u64 (*bswap64_t)(u64); extern bswap16_t cu_bswap16; extern bswap32_t cu_bswap32; diff --git a/list.c b/list.c index 1455e07..5957443 100644 --- a/list.c +++ b/list.c @@ -32,7 +32,7 @@ void list_add(list_t* list, uint size, void* data) cu_memset(node, '\0', nodeSize); if (data) { - cu_memcpy((uint8_t*)node + LIST_NODE_SIZE, data, size); + cu_memcpy((u8*)node + LIST_NODE_SIZE, data, size); } list_node_t* last = list->last; diff --git a/list.h b/list.h index 0802b18..c95c596 100644 --- a/list.h +++ b/list.h @@ -6,12 +6,12 @@ typedef struct list_node_s { struct list_node_s* prev; struct list_node_s* next; - uint8_t data[1]; + u8 data[1]; } list_node_t; #define LIST_NODE_SIZE (CU_PTR_SIZE * 2) -#define LIST_NODE_PTR(data) ((uint8_t*)data - LIST_NODE_SIZE) -#define LIST_NODE_DATA(node) ((uint8_t*)node + LIST_NODE_SIZE) +#define LIST_NODE_PTR(data) ((u8*)data - LIST_NODE_SIZE) +#define LIST_NODE_DATA(node) ((u8*)node + LIST_NODE_SIZE) #define LIST_NODE_VALUE(node, type) (*(type*)LIST_NODE_DATA(node)) typedef struct { diff --git a/struct.c b/struct.c index 29420aa..4b21e24 100644 --- a/struct.c +++ b/struct.c @@ -2,10 +2,10 @@ #include "cutil.h" union intvalue_u { - uint8_t int8; - uint16_t int16; - uint32_t int32; - uint64_t int64; + u8 int8; + u16 int16; + u32 int32; + u64 int64; }; uint value_size(struct cu_struct_s* st, uint idx, const void* in) @@ -69,7 +69,7 @@ uint value_array_size(struct cu_struct_s* st, uint idx, const void* in) } else { - const uint8_t* items = (const uint8_t*)in + value_offset(st, idx, in); + const u8* items = (const u8*)in + value_offset(st, idx, in); uint size = value->array.item; while (cu_memtest(items, size)) { diff --git a/struct.h b/struct.h index 53fa995..d025605 100644 --- a/struct.h +++ b/struct.h @@ -4,10 +4,10 @@ #include "cutypes.h" #include "endian.h" -#define VALUE_INT8_SIZE sizeof(uint8_t) -#define VALUE_INT16_SIZE sizeof(uint16_t) -#define VALUE_INT32_SIZE sizeof(uint32_t) -#define VALUE_INT64_SIZE sizeof(uint64_t) +#define VALUE_INT8_SIZE sizeof(u8) +#define VALUE_INT16_SIZE sizeof(u16) +#define VALUE_INT32_SIZE sizeof(u32) +#define VALUE_INT64_SIZE sizeof(u64) enum cu_value_type_e { NoValue, diff --git a/test.c b/test.c index c408d77..f9f3556 100644 --- a/test.c +++ b/test.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "cutil.h" #include "list.h"