diff --git a/liba/include/stddef.h b/liba/include/stddef.h index 628d26fd2..4ed45eca6 100644 --- a/liba/include/stddef.h +++ b/liba/include/stddef.h @@ -3,10 +3,9 @@ #define NULL 0 -/* C99 says that size_t is an unsigned integer type of at least 16 bit. - * Moreover, size_t is the return type of the "sizeof" operator, which is - * defined by the compiler. That's why both GCC and clang define a __SIZE_TYPE__ - * macro to let the libc header know about the type used by the compiler. */ -typedef __SIZE_TYPE__ size_t; +typedef int ssize_t; +typedef unsigned int size_t; + +#define offsetof(st, m) __builtin_offsetof(st, m) #endif diff --git a/liba/test/helpers.h b/liba/test/helpers.h new file mode 100644 index 000000000..bcd8441f1 --- /dev/null +++ b/liba/test/helpers.h @@ -0,0 +1,7 @@ +#ifndef LIBA_TEST_HELPERS_H +#define LIBA_TEST_HELPERS_H + +#define assert_signed(type) assert((type)-1 < 0) +#define assert_unsigned(type) assert((type)-1 >= 0) + +#endif diff --git a/liba/test/stddef.c b/liba/test/stddef.c new file mode 100644 index 000000000..06a845643 --- /dev/null +++ b/liba/test/stddef.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include "helpers.h" + +QUIZ_CASE(liba_stddef) { + assert(NULL == 0); + + assert_unsigned(size_t); + assert(sizeof(size_t) == __SIZEOF_SIZE_T__); + assert_signed(ssize_t); + assert(sizeof(ssize_t) == __SIZEOF_SIZE_T__); +} diff --git a/liba/test/stdint.c b/liba/test/stdint.c index 263cee40c..4165837ec 100644 --- a/liba/test/stdint.c +++ b/liba/test/stdint.c @@ -1,6 +1,7 @@ #include #include #include +#include "helpers.h" QUIZ_CASE(liba_stdint_size) { assert(sizeof(uint8_t) == 1); @@ -14,9 +15,6 @@ QUIZ_CASE(liba_stdint_size) { assert(sizeof(int64_t) == 8); } -#define assert_signed(type) assert((type)-1 < 0) -#define assert_unsigned(type) assert((type)-1 >= 0) - QUIZ_CASE(liba_stdint_signedness) { assert_signed(int8_t); assert_signed(int16_t);