mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[liba] Define ssize_t and offsetof
Change-Id: Icbf546cd09f4e3c3e849f830bb3c60ffa3c13b6c
This commit is contained in:
committed by
Romain Goyet
parent
750b51dd2f
commit
c8e2b0d2be
@@ -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
|
||||
|
||||
7
liba/test/helpers.h
Normal file
7
liba/test/helpers.h
Normal file
@@ -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
|
||||
13
liba/test/stddef.c
Normal file
13
liba/test/stddef.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <quiz.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#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__);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <quiz.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user