From d407a0f6d1b3730e6d9c15571eacd7da83f5f326 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 2 Feb 2007 12:08:56 +0100 Subject: [PATCH] The great type cleanup: Use C99 types where applicable. LibUCW types (u16 and friends) are now based on the C99 types. Old-style sbyte, word, sword and addr_int_t are gone (I've removed all refs to them in the previous commits). is now included automatically, bringing types like size_t and also NULL. The operations on pointers (GET_P, PUT_P etc.) have been removed from lib/config.h as nobody uses them and bgetp() is just a duplicate of bgeta() from lib/fastbuf.h. BYTES_PER_P is gone as well. #define _GNU_SOURCE had to be moved to lib/config.h, where it belongs anyway. --- lib/config.h | 56 +++++++++++++++++++++------------------------------- lib/lib.h | 12 +++-------- 2 files changed, 25 insertions(+), 43 deletions(-) diff --git a/lib/config.h b/lib/config.h index 6f24c6d5..72be2f98 100644 --- a/lib/config.h +++ b/lib/config.h @@ -1,7 +1,7 @@ /* * UCW Library -- Configuration-Dependent Definitions * - * (c) 1997--2004 Martin Mares + * (c) 1997--2007 Martin Mares * (c) 2006 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -15,46 +15,34 @@ #include "lib/autoconf.h" -/* Types */ - -typedef unsigned char byte; /* exactly 8 bits, unsigned */ -typedef signed char sbyte; /* exactly 8 bits, signed */ -typedef unsigned char u8; /* exactly 8 bits, unsigned */ -typedef signed char s8; /* exactly 8 bits, signed */ -typedef unsigned short word; /* exactly 16 bits, unsigned */ -typedef short sword; /* exactly 16 bits, signed */ -typedef unsigned short u16; /* exactly 16 bits, unsigned */ -typedef short s16; /* exactly 16 bits, signed */ -typedef unsigned int u32; /* exactly 32 bits, unsigned */ -typedef int s32; /* exactly 32 bits, signed */ -typedef unsigned int uns; /* at least 32 bits */ -typedef unsigned long long int u64; /* exactly 64 bits, unsigned */ -typedef long long int s64; /* exactly 64 bits, signed */ -typedef unsigned long addr_int_t; /* Both integer and address */ -typedef unsigned int sh_time_t; /* Timestamp */ +/* Tell libc we're going to use all extensions available */ -#ifndef NULL -#define NULL (void *)0 +#ifndef _GNU_SOURCE +#define _GNU_SOURCE #endif +/* Types (based on standard C99 integers) */ + +#include +#include + +typedef uint8_t byte; /* exactly 8 bits, unsigned */ +typedef uint8_t u8; /* exactly 8 bits, unsigned */ +typedef int8_t s8; /* exactly 8 bits, signed */ +typedef uint16_t u16; /* exactly 16 bits, unsigned */ +typedef int16_t s16; /* exactly 16 bits, signed */ +typedef uint32_t u32; /* exactly 32 bits, unsigned */ +typedef int32_t s32; /* exactly 32 bits, signed */ +typedef uint64_t u64; /* exactly 64 bits, unsigned */ +typedef int64_t s64; /* exactly 64 bits, signed */ + +typedef unsigned int uns; /* at least 32 bits */ +typedef u32 sh_time_t; /* Timestamp */ + #ifdef CONFIG_LARGE_FILES /* File positions */ typedef s64 sh_off_t; #else typedef s32 sh_off_t; #endif -#ifdef CPU_64BIT_POINTERS -#define BYTES_PER_P 8 -#define bgetp(f) bgetq(f) -#define bputp(f,l) bputq(f,l) -#define GET_P(p) GET_U64(p) -#define PUT_P(p,x) PUT_U64(p,x) -#else -#define BYTES_PER_P 4 -#define bgetp(f) bgetl(f) -#define bputp(f,l) bputl(f,l) -#define GET_P(p) GET_U32(p) -#define PUT_P(p,x) PUT_U32(p,x) -#endif - #endif diff --git a/lib/lib.h b/lib/lib.h index 27a7511b..ea795c92 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -1,7 +1,7 @@ /* * The UCW Library -- Miscellaneous Functions * - * (c) 1997--2006 Martin Mares + * (c) 1997--2007 Martin Mares * (c) 2005 Tomas Valla * (c) 2006 Robert Spalek * @@ -15,12 +15,6 @@ #include "lib/config.h" #include -/* Tell libc we're going to use all extensions available */ - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - /* Macros for handling structurues, offsets and alignment */ #define CHECK_PTR_TYPE(x, type) ((x)-(type)(x) + (type)(x)) @@ -28,8 +22,8 @@ #define OFFSETOF(s, i) ((unsigned int) PTR_TO(s, i)) #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) #define ALIGN_TO(s, a) (((s)+a-1)&~(a-1)) -#define ALIGN_PTR(p, s) ((addr_int_t)(p) % (s) ? (typeof(p))((addr_int_t)(p) + (s) - (addr_int_t)(p) % (s)) : (p)) -#define UNALIGNED_PART(ptr, type) (((addr_int_t) (ptr)) % sizeof(type)) +#define ALIGN_PTR(p, s) ((uintptr_t)(p) % (s) ? (typeof(p))((uintptr_t)(p) + (s) - (uintptr_t)(p) % (s)) : (p)) +#define UNALIGNED_PART(ptr, type) (((uintptr_t) (ptr)) % sizeof(type)) /* Some other macros */ -- 2.39.5