aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2017-04-19 04:08:16 +0200
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2017-04-19 04:08:16 +0200
commitfbe2d46b6f60795118e0edbfc882e4b43bdca1c2 (patch)
treea6e6d359f7e655a78e75f6fcd3c05f272a6ccbb1
parent96202cc92fb452f04c33bf8f01ac33528d8a1534 (diff)
Last bikeshed of the night
-rw-r--r--include/alloca.h4
-rw-r--r--include/assert.h2
-rw-r--r--include/builtin.h2
-rw-r--r--include/byteswap.h2
-rw-r--r--include/cdefs.h240
-rw-r--r--include/compiler.h22
-rw-r--r--include/ctype.h2
-rw-r--r--include/dirent.h2
-rw-r--r--include/dispbios.h1
-rw-r--r--include/endian.h1
-rw-r--r--include/ensigdsp.h2
-rw-r--r--include/errno.h3
-rw-r--r--include/filebios.h1
-rw-r--r--include/fixed.h1
-rw-r--r--include/fx/app.h1
-rw-r--r--include/fx/battery.h2
-rw-r--r--include/fx/bcd.h1
-rw-r--r--include/fx/clock.h1
-rw-r--r--include/fx/comm.h2
-rw-r--r--include/fx/display.h2
-rw-r--r--include/fx/file.h2
-rw-r--r--include/fx/keyboard.h1
-rw-r--r--include/fx/misc.h1
-rw-r--r--include/fx/serial.h1
-rw-r--r--include/fx/timer.h2
-rw-r--r--include/fxlib.h1
-rw-r--r--include/inttypes.h3
-rw-r--r--include/iso646.h1
-rw-r--r--include/keybios.h1
-rw-r--r--include/limits.h4
-rw-r--r--include/malloc.h1
-rw-r--r--include/math.h2
-rw-r--r--include/mathf.h2
-rw-r--r--include/monochrome.h2
-rw-r--r--include/printf.h2
-rw-r--r--include/setjmp.h2
-rw-r--r--include/smachine.h2
-rw-r--r--include/stdio.h2
-rw-r--r--include/stdlib.h2
-rw-r--r--include/string.h2
-rw-r--r--include/sys/cdefs.h211
-rw-r--r--include/timer.h1
-rw-r--r--include/umachine.h2
-rw-r--r--include/unistd.h7
44 files changed, 316 insertions, 235 deletions
diff --git a/include/alloca.h b/include/alloca.h
index 4782dd8..055c730 100644
--- a/include/alloca.h
+++ b/include/alloca.h
@@ -18,9 +18,11 @@
* ************************************************************************** */
#ifndef _ALLOCA_H
# define _ALLOCA_H 1
+# include <cdefs.h>
# include <stddef.h>
-# include <sys/cdefs.h>
+/* there isn't a function in the library.
+ * you should *really* use the macros. */
extern void *alloca(size_t __size) __THROW;
# ifdef __GNUC__
diff --git a/include/assert.h b/include/assert.h
index 2cb66c8..bd6728c 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -19,7 +19,7 @@
#if !defined(_ASSERT_H) && !defined(_ASSERT)
# define _ASSERT_H 1
# define _ASSERT 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
/* make an assertion pop-up */
extern void __assert_popup(const char *__file, int __line, const char *__expr)
diff --git a/include/builtin.h b/include/builtin.h
index bcd1bf7..44bddee 100644
--- a/include/builtin.h
+++ b/include/builtin.h
@@ -19,7 +19,7 @@
#if !defined(_BUILTIN_H) && !defined(_BUILTIN)
# define _BUILTIN_H 1
# define _BUILTIN 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <stdint.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/byteswap.h b/include/byteswap.h
index 9e7453b..14b3012 100644
--- a/include/byteswap.h
+++ b/include/byteswap.h
@@ -18,9 +18,9 @@
* ************************************************************************** */
#ifndef _BYTESWAP_H
# define _BYTESWAP_H 1
+# include <cdefs.h>
# include <stdint.h>
# include <machine.h>
-# include <sys/cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/cdefs.h b/include/cdefs.h
new file mode 100644
index 0000000..d9fcf1c
--- /dev/null
+++ b/include/cdefs.h
@@ -0,0 +1,240 @@
+/* *****************************************************************************
+ * cdefs.h -- C compiler helpers.
+ * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
+ *
+ * This file is part of libcarrot.
+ * libcarrot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3.0 of the License,
+ * or (at your option) any later version.
+ *
+ * libcarrot is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * This header defines the compiler-related macros to have a greater control
+ * on the output. These are based on GCC's attributes.
+ * ************************************************************************** */
+#if !defined(_SYS_CDEFS_H) && !defined(_CDEFS_H) && !defined(_COMPILER_H)
+# define _SYS_CDEFS_H 1
+# define _CDEFS_H 1
+# define _COMPILER_H 1
+# include <fixed.h>
+
+/* Make checks */
+# if !defined(__STDC__)
+# error "You need an ISO C conforming compiler to use the libcarrot headers."
+# endif
+
+/* Renesas/Hitachi compiler */
+# if defined(__RENESAS__) && !defined(__HITACHI__)
+# define __HITACHI__
+# endif
+/* ************************************************************************** */
+/* __THROW: optimize function calls for C++ */
+/* ************************************************************************** */
+/* <TODO: explanation> */
+# ifdef __THROW
+# undef __THROW
+# endif
+# if defined(__cplusplus)
+# define __THROW throw()
+# elif defined(__GNUC__)
+# define __THROW __attribute__((nothrow))
+# endif
+/* ************************************************************************** */
+/* __align: align data */
+/* ************************************************************************** */
+/* When you want to align data for easier management. */
+# ifdef __align
+# undef __align
+# endif
+# if defined(__GNUC__)
+# define __align(_N) __attribute__((aligned(_N)))
+# else
+# define __align(_N)
+# endif
+/* ************************************************************************** */
+/* __inline: force inlining */
+/* ************************************************************************** */
+/* The `inline` function attribute is simply an indication; this attribute
+ * forces the inlining of a function. */
+# ifdef __inline
+# undef __inline
+# endif
+# if defined(__GNUC__)
+# define __inline __attribute__((always_inline, unused))
+# else
+# define __inline
+# endif
+/* ************************************************************************** */
+/* __asm_inline: force inlining for assembly functions */
+/* ************************************************************************** */
+/* This attribute forces inlining and enables optimizations suitable for
+ * inline assembly functions/macros such as the ones defined in `machine.h`. */
+# ifdef __asm_inline
+# undef __asm_inline
+# endif
+# if defined(__GNUC__)
+# define __asm_inline \
+ __attribute__((optimize("unroll-loops"), always_inline, unused))
+# else
+# define __asm_inline
+# endif
+/* ************************************************************************** */
+/* __pure: no side effects */
+/* ************************************************************************** */
+/* For a set of arguments, there is a constant (cacheable) result, and
+ * calculating it doesn't require any side effect. */
+# ifdef __pure
+# undef __pure
+# endif
+# if defined(__GNUC__)
+# define __pure __attribute__((pure))
+# else
+# define __pure
+# endif
+/* ************************************************************************** */
+/* __nonnull: a function requires a pointer argument not to be NULL */
+/* ************************************************************************** */
+/* A warning shall be issued when a NULL value is passed as an argument that
+ * shouldn't be. The macro argument is the argument index, starting from 1. */
+# ifdef __nonnull
+# undef __nonnull
+# endif
+# if defined(__GNUC__)
+# define __nonnull(_N) __attribute__((nonnull(_N)))
+# else
+# define __nonnull(_N)
+# endif
+/* ************************************************************************** */
+/* __wur: warn unused result */
+/* ************************************************************************** */
+/* A warning shall be issued if the result of the function isn't used.
+ * Note that __pure implies __wur, you don't need to put the two. */
+# ifdef __wur
+# undef __wur
+# endif
+# if defined(__GNUC__)
+# define __wur __attribute__((warn_unused_result))
+# else
+# define __wur
+# endif
+/* ************************************************************************** */
+/* __restrict: portable 'restrict' keyword */
+/* ************************************************************************** */
+/* Uses 'restrict' if we're in >=C99, or nothing if not. */
+# ifdef __restrict
+# undef __restrict
+# endif
+# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+# define __restrict restrict
+# else
+# define __restrict
+# endif
+/* ************************************************************************** */
+/* __malloc: is a memory allocation function */
+/* ************************************************************************** */
+/* TODO: why is this attribute useful? */
+# ifdef __malloc
+# undef __malloc
+# endif
+# if defined(__GNUC__)
+# define __malloc __attribute__((malloc))
+# else
+# define __malloc
+# endif
+/* ************************************************************************** */
+/* __format: is a function expecting a printf-like format */
+/* ************************************************************************** */
+# ifdef __format
+# undef __format
+# endif
+# if defined(__GNUC__)
+# define __format(_A, _FMTIND, _FIRST) \
+ __attribute__((format(_A, _FMTIND, _FIRST)))
+# else
+# define __format(_A, _FMTIND, _FIRST)
+# endif
+/* ************************************************************************** */
+/* __alias: the function is an alias for an other */
+/* ************************************************************************** */
+# ifdef __alias
+# undef __alias
+# endif
+# if defined(__GNUC__)
+# define __alias(_A) __attribute__((weak, alias(_A)))
+# else
+# define __alias(_A)
+# endif
+/* ************************************************************************** */
+/* __section: put this function/data in an ELF section */
+/* ************************************************************************** */
+# ifdef __section
+# undef __section
+# endif
+# if defined(__GNUC__)
+# define __section(_S) __attribute__((section(_S)))
+# else
+# define __section(_S)
+# endif
+/* ************************************************************************** */
+/* __concat: Catenate things in macros */
+/* ************************************************************************** */
+# ifdef __concat
+# undef __concat
+# endif
+# ifdef __concat_
+# undef __concat_
+# endif
+# define __concat_(_X, _Y) _X ## _Y
+# define __concat(_X, _Y) __concat_(_X, _Y)
+/* ************************************************************************** */
+/* __count_va_args: count number of elements in __VA_ARGS__ */
+/* ************************************************************************** */
+# ifdef __count_va_args
+# undef __count_va_args
+# endif
+# if defined(__GNUC__)
+/* This is something that should work, although I don't really understand the
+ * trick yet. Source: http://stackoverflow.com/a/2124385/6541022 */
+
+# define __count_va_args(...) \
+ __count_va_args_(__VA_ARGS__, __count_va_args_rseq_N())
+# define __count_va_args_(...) __count_va_args_N(__VA_ARGS__)
+
+# define __count_va_args_N( \
+ _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
+ _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
+ _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
+ _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
+ _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
+ _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
+ _61, _62, _63, _N, ...) _N
+# define __count_va_args_rseq_N() \
+ 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, \
+ 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, \
+ 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, \
+ 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, \
+ 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, \
+ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, \
+ 3, 2, 1, 0
+
+# else
+# define __count_va_args(...) (0)
+# endif
+
+#endif /* _SYS_CDEFS_H, _CDEFS_H, _COMPILER_H */
+#ifndef _SYS_CDEFS_H
+# define _SYS_CDEFS_H 1
+#endif
+#ifndef _CDEFS_H
+# define _CDEFS_H 1
+#endif
+#ifndef _COMPILER_H
+# define _COMPILER_H 1
+#endif
diff --git a/include/compiler.h b/include/compiler.h
new file mode 100644
index 0000000..4c248c9
--- /dev/null
+++ b/include/compiler.h
@@ -0,0 +1,22 @@
+/* *****************************************************************************
+ * compiler.h -- cdefs.h alias.
+ * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
+ *
+ * This file is part of libcarrot.
+ * libcarrot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3.0 of the License,
+ * or (at your option) any later version.
+ *
+ * libcarrot is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * This header defines the compiler-related macros to have a greater control
+ * on the output. These are based on GCC's attributes.
+ * ************************************************************************** */
+#include <cdefs.h>
diff --git a/include/ctype.h b/include/ctype.h
index f9f7ba7..ff7750e 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -23,7 +23,7 @@
# define _CTYPE_H 1
# define _CTYPE_H_ 1
# define _CTYPE 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
/* ************************************************************************** */
/* Symbols (if no macros) */
diff --git a/include/dirent.h b/include/dirent.h
index 3dbe0b5..92cfec5 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -18,7 +18,7 @@
* ************************************************************************** */
#ifndef _DIRENT_H
# define _DIRENT_H 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/dispbios.h b/include/dispbios.h
index 79af863..b31d529 100644
--- a/include/dispbios.h
+++ b/include/dispbios.h
@@ -22,6 +22,7 @@
#if !defined(_DISPBIOS_H) && !defined(__DISPBIOS_H__)
# define _DISPBIOS_H 1
# define __DISPBIOS_H__ 1
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/endian.h b/include/endian.h
index 626eb65..2a462a8 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -22,6 +22,7 @@
#if !defined(_ENDIAN_H) && !defined(__ENDIAN_H__)
# define _ENDIAN_H 1
# define __ENDIAN_H__ 1
+# include <cdefs.h>
# include <byteswap.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/ensigdsp.h b/include/ensigdsp.h
index ed761f8..71f66e6 100644
--- a/include/ensigdsp.h
+++ b/include/ensigdsp.h
@@ -19,7 +19,7 @@
#if !defined(_ENSIGDSP_H) && !defined(_ENSIGDSP)
# define _ENSIGDSP_H 1
# define _ENSIGDSP 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/errno.h b/include/errno.h
index d43ef90..eb3108f 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -1,5 +1,5 @@
/* *****************************************************************************
- * errno.h -- C99-compliant error numbers.
+ * errno.h -- err, no, I don't remember what the errors are.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcarrot.
@@ -19,6 +19,7 @@
#if !defined(_ERRNO_H) && !defined(_ERRNO)
# define _ERRNO_H 1
# define _ERRNO 1
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/filebios.h b/include/filebios.h
index e5e2090..6a6a3d6 100644
--- a/include/filebios.h
+++ b/include/filebios.h
@@ -22,6 +22,7 @@
#if !defined(_FILEBIOS_H) && !defined(__FILEBIOS_H__)
# define _FILEBIOS_H 1
# define __FILEBIOS_H__ 1
+# include <cdefs.h>
# include <stdint.h>
# include <fx/error.h>
# ifdef __cplusplus
diff --git a/include/fixed.h b/include/fixed.h
index 35b0e19..1eab498 100644
--- a/include/fixed.h
+++ b/include/fixed.h
@@ -19,6 +19,7 @@
#if !defined(_FIXED_H) && !defined(_FIXED)
# define _FIXED_H 1
# define _FIXED 1
+# include <cdefs.h>
# ifdef __fixed_defined
# undef __fixed_defined
# endif
diff --git a/include/fx/app.h b/include/fx/app.h
index 4702ea9..f9e4e6b 100644
--- a/include/fx/app.h
+++ b/include/fx/app.h
@@ -20,6 +20,7 @@
# define _FX_APP_H 1
# define _APP_H 1
# define _APP_H_ 1
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/fx/battery.h b/include/fx/battery.h
index 8d998c4..cf12383 100644
--- a/include/fx/battery.h
+++ b/include/fx/battery.h
@@ -18,7 +18,7 @@
* ************************************************************************** */
#ifndef _FX_BATTERY_H
# define _FX_BATTERY_H 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/fx/bcd.h b/include/fx/bcd.h
index bc273e3..03055ed 100644
--- a/include/fx/bcd.h
+++ b/include/fx/bcd.h
@@ -18,6 +18,7 @@
* ************************************************************************** */
#ifndef _FX_BCD_H
# define _FX_BCD_H 1
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/fx/clock.h b/include/fx/clock.h
index b158b61..381fb99 100644
--- a/include/fx/clock.h
+++ b/include/fx/clock.h
@@ -22,6 +22,7 @@
# define _FX_RTC_H 1
# define _RTC_H 1
# define _RTC_H_ 1
+# include <cdefs.h>
extern void RTC_Reset(int __unknown)
__THROW;
diff --git a/include/fx/comm.h b/include/fx/comm.h
index 913bc5f..132a1fb 100644
--- a/include/fx/comm.h
+++ b/include/fx/comm.h
@@ -18,7 +18,7 @@
* ************************************************************************** */
#ifndef _FX_COMM_H
# define _FX_COMM_H 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/fx/display.h b/include/fx/display.h
index 10fea46..1f1797f 100644
--- a/include/fx/display.h
+++ b/include/fx/display.h
@@ -23,7 +23,7 @@
# define _DISP_H_ 1
# define _PRINT_H 1
# define _PRINT_H_ 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <dispbios.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/fx/file.h b/include/fx/file.h
index 095f974..6cd45db 100644
--- a/include/fx/file.h
+++ b/include/fx/file.h
@@ -20,7 +20,7 @@
# define _FX_FILE_H 1
# define _FILE_H 1
# define _FILE_H_ 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <filebios.h>
# define MAX_PATH 50 /* a quick estimation */
# ifdef __cplusplus
diff --git a/include/fx/keyboard.h b/include/fx/keyboard.h
index 3696cff..84db389 100644
--- a/include/fx/keyboard.h
+++ b/include/fx/keyboard.h
@@ -20,6 +20,7 @@
# define _FX_KEYBOARD_H 1
# define _KEY_H 1
# define _KEY_H_ 1
+# include <cdefs.h>
# include <keybios.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/fx/misc.h b/include/fx/misc.h
index 5214995..aab6421 100644
--- a/include/fx/misc.h
+++ b/include/fx/misc.h
@@ -18,6 +18,7 @@
* ************************************************************************** */
#ifndef _FX_MISC_H
# define _FX_MISC_H 1
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/fx/serial.h b/include/fx/serial.h
index 2a3919a..8b36c3e 100644
--- a/include/fx/serial.h
+++ b/include/fx/serial.h
@@ -18,6 +18,7 @@
* ************************************************************************** */
#ifndef _FX_SERIAL_H
# define _FX_SERIAL_H 1
+# include <cdefs.h>
# include <fx/comm.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/fx/timer.h b/include/fx/timer.h
index b4ada0d..1501692 100644
--- a/include/fx/timer.h
+++ b/include/fx/timer.h
@@ -18,7 +18,7 @@
* ************************************************************************** */
#ifndef _FX_TIMER_H
# define _FX_TIMER_H 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <timer.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/fxlib.h b/include/fxlib.h
index 8e528a3..9d05b3e 100644
--- a/include/fxlib.h
+++ b/include/fxlib.h
@@ -23,6 +23,7 @@
#if !defined(_FXLIB_H) && !defined(__FXLIB_H__)
# define _FXLIB_H 1
# define __FXLIB_H__ 1
+# include <cdefs.h>
# include <fx/display.h>
# include <fx/file.h>
# include <fx/keyboard.h>
diff --git a/include/inttypes.h b/include/inttypes.h
index 2662a9c..711b467 100644
--- a/include/inttypes.h
+++ b/include/inttypes.h
@@ -1,5 +1,5 @@
/* *****************************************************************************
- * inttypes.h -- C99-compliant macros for using printf.
+ * inttypes.h -- stdint format macros for printf.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcarrot.
@@ -18,6 +18,7 @@
* ************************************************************************** */
#ifndef _INTTYPES_H
# define _INTTYPES_H 1
+# include <cdefs.h>
/* Prefixes */
# define __P8 "hh"
diff --git a/include/iso646.h b/include/iso646.h
index 4ce5fd2..dd7d48a 100644
--- a/include/iso646.h
+++ b/include/iso646.h
@@ -20,6 +20,7 @@
# define _ISO646_H 1
# define _ISO646_H_ 1
# define _ISO646 1
+# include <cdefs.h>
# ifndef __cplusplus
# define and &&
diff --git a/include/keybios.h b/include/keybios.h
index 4e73e32..4d98375 100644
--- a/include/keybios.h
+++ b/include/keybios.h
@@ -25,6 +25,7 @@
# define __KEYBIOS_H__ 1
# define _KEYCODES_H 1
# define _KEYCODES_H_ 1
+# include <cdefs.h>
/* See fxlib.h to see what this header is about. */
/* ************************************************************************** */
diff --git a/include/limits.h b/include/limits.h
index e5ae112..cd18ad9 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -1,5 +1,5 @@
/* *****************************************************************************
- * limits.h -- C99-compliant header.
+ * limits.h -- push it to the limit!
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcarrot.
@@ -20,7 +20,7 @@
# define _LIMITS_H 1
# define _LIMITS_H_ 1
# define _LIMITS 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
/* Max lengths */
# define MB_LEN_MAX 1
diff --git a/include/malloc.h b/include/malloc.h
index b5a5bd1..179481f 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -18,6 +18,7 @@
* ************************************************************************** */
#ifndef _MALLOC_H
# define _MALLOC_H
+# include <cdefs.h>
# include <alloca.h>
/* Allocate memory */
diff --git a/include/math.h b/include/math.h
index 1a6b8a2..d575f70 100644
--- a/include/math.h
+++ b/include/math.h
@@ -19,7 +19,7 @@
#if !defined(_MATH_H) && !defined(_MATH)
# define _MATH_H 1
# define _MATH 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <errno.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/mathf.h b/include/mathf.h
index 02fe32d..b8c1b96 100644
--- a/include/mathf.h
+++ b/include/mathf.h
@@ -19,7 +19,7 @@
#if !defined(_MATHF_H) && !defined(_MATHF)
# define _MATHF_H 1
# define _MATHF 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <errno.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/monochrome.h b/include/monochrome.h
index 6cccb7a..d33c175 100644
--- a/include/monochrome.h
+++ b/include/monochrome.h
@@ -21,7 +21,7 @@
# define _MONOCHROME_H 1
# define MONOCHROMELIB 1
# define _MONOCHROMELIB_H 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/printf.h b/include/printf.h
index bbe6f9e..f6b7265 100644
--- a/include/printf.h
+++ b/include/printf.h
@@ -18,7 +18,7 @@
* ************************************************************************** */
#ifndef _PRINTF_H
# define _PRINTF_H
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <stdio.h>
# include <stdarg.h>
# ifdef __cplusplus
diff --git a/include/setjmp.h b/include/setjmp.h
index 3567d63..6d7814f 100644
--- a/include/setjmp.h
+++ b/include/setjmp.h
@@ -19,7 +19,7 @@
#if !defined(_SETJMP_H) && !defined(_SETJMP)
# define _SETJMP_H 1
# define _SETJMP 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/smachine.h b/include/smachine.h
index a52fc8d..42dec39 100644
--- a/include/smachine.h
+++ b/include/smachine.h
@@ -24,9 +24,9 @@
#if !defined(_SMACHINE_H) && !defined(_SMACHINE)
# define _SMACHINE_H 1
# define _SMACHINE 1
+# include <cdefs.h>
# include <stdint.h>
# include <builtin.h>
-# include <sys/cdefs.h>
# include <fixed.h>
/* ************************************************************************** */
diff --git a/include/stdio.h b/include/stdio.h
index c3f3a18..d8f0516 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -19,7 +19,7 @@
#if !defined(_STDIO_H) && !defined(_STDIO)
# define _STDIO_H 1
# define _STDIO 1
-# include <sys/cdefs.h>
+# include <cdefs.h>
# include <stddef.h>
# ifdef __cplusplus
extern "C" {
diff --git a/include/stdlib.h b/include/stdlib.h
index 1403483..700fed0 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -22,9 +22,9 @@
# define _STDLIB_H 1
# define _STDLIB_H_ 1
# define _STDLIB 1
+# include <cdefs.h>
# include <stddef.h>
# include <malloc.h>
-# include <sys/cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/string.h b/include/string.h
index c394422..ba3c96c 100644
--- a/include/string.h
+++ b/include/string.h
@@ -22,8 +22,8 @@
# define _STRING_H 1
# define _STRING_H_ 1
# define _STRING 1
+# include <cdefs.h>
# include <stddef.h>
-# include <sys/cdefs.h>
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h
index d4cf3ea..834a933 100644
--- a/include/sys/cdefs.h
+++ b/include/sys/cdefs.h
@@ -1,5 +1,5 @@
/* *****************************************************************************
- * sys/cdefs.h -- compiler helpers.
+ * sys/cdefs.h -- cdefs.h alias.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcarrot.
@@ -19,211 +19,4 @@
* This header defines the compiler-related macros to have a greater control
* on the output. These are based on GCC's attributes.
* ************************************************************************** */
-#ifndef _SYS_CDEFS_H
-# define _SYS_CDEFS_H 1
-# include <fixed.h>
-
-/* Make checks */
-# if !defined(__STDC__)
-# error "You need an ISO C conforming compiler to use the libcarrot headers."
-# endif
-
-/* Renesas/Hitachi compiler */
-# if defined(__RENESAS__) && !defined(__HITACHI__)
-# define __HITACHI__
-# endif
-/* ************************************************************************** */
-/* __THROW: optimize function calls for C++ */
-/* ************************************************************************** */
-/* <TODO: explanation> */
-# ifdef __THROW
-# undef __THROW
-# endif
-# if defined(__cplusplus)
-# define __THROW throw()
-# elif defined(__GNUC__)
-# define __THROW __attribute__((nothrow))
-# endif
-/* ************************************************************************** */
-/* __align: align data */
-/* ************************************************************************** */
-/* When you want to align data for easier management. */
-# ifdef __align
-# undef __align
-# endif
-# if defined(__GNUC__)
-# define __align(_N) __attribute__((aligned(_N)))
-# else
-# define __align(_N)
-# endif
-/* ************************************************************************** */
-/* __inline: force inlining */
-/* ************************************************************************** */
-/* The `inline` function attribute is simply an indication; this attribute
- * forces the inlining of a function. */
-# ifdef __inline
-# undef __inline
-# endif
-# if defined(__GNUC__)
-# define __inline __attribute__((always_inline, unused))
-# else
-# define __inline
-# endif
-/* ************************************************************************** */
-/* __asm_inline: force inlining for assembly functions */
-/* ************************************************************************** */
-/* This attribute forces inlining and enables optimizations suitable for
- * inline assembly functions/macros such as the ones defined in `machine.h`. */
-# ifdef __asm_inline
-# undef __asm_inline
-# endif
-# if defined(__GNUC__)
-# define __asm_inline \
- __attribute__((optimize("unroll-loops"), always_inline, unused))
-# else
-# define __asm_inline
-# endif
-/* ************************************************************************** */
-/* __pure: no side effects */
-/* ************************************************************************** */
-/* For a set of arguments, there is a constant (cacheable) result, and
- * calculating it doesn't require any side effect. */
-# ifdef __pure
-# undef __pure
-# endif
-# if defined(__GNUC__)
-# define __pure __attribute__((pure))
-# else
-# define __pure
-# endif
-/* ************************************************************************** */
-/* __nonnull: a function requires a pointer argument not to be NULL */
-/* ************************************************************************** */
-/* A warning shall be issued when a NULL value is passed as an argument that
- * shouldn't be. The macro argument is the argument index, starting from 1. */
-# ifdef __nonnull
-# undef __nonnull
-# endif
-# if defined(__GNUC__)
-# define __nonnull(_N) __attribute__((nonnull(_N)))
-# else
-# define __nonnull(_N)
-# endif
-/* ************************************************************************** */
-/* __wur: warn unused result */
-/* ************************************************************************** */
-/* A warning shall be issued if the result of the function isn't used.
- * Note that __pure implies __wur, you don't need to put the two. */
-# ifdef __wur
-# undef __wur
-# endif
-# if defined(__GNUC__)
-# define __wur __attribute__((warn_unused_result))
-# else
-# define __wur
-# endif
-/* ************************************************************************** */
-/* __restrict: portable 'restrict' keyword */
-/* ************************************************************************** */
-/* Uses 'restrict' if we're in >=C99, or nothing if not. */
-# ifdef __restrict
-# undef __restrict
-# endif
-# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-# define __restrict restrict
-# else
-# define __restrict
-# endif
-/* ************************************************************************** */
-/* __malloc: is a memory allocation function */
-/* ************************************************************************** */
-/* TODO: why is this attribute useful? */
-# ifdef __malloc
-# undef __malloc
-# endif
-# if defined(__GNUC__)
-# define __malloc __attribute__((malloc))
-# else
-# define __malloc
-# endif
-/* ************************************************************************** */
-/* __format: is a function expecting a printf-like format */
-/* ************************************************************************** */
-# ifdef __format
-# undef __format
-# endif
-# if defined(__GNUC__)
-# define __format(_A, _FMTIND, _FIRST) \
- __attribute__((format(_A, _FMTIND, _FIRST)))
-# else
-# define __format(_A, _FMTIND, _FIRST)
-# endif
-/* ************************************************************************** */
-/* __alias: the function is an alias for an other */
-/* ************************************************************************** */
-# ifdef __alias
-# undef __alias
-# endif
-# if defined(__GNUC__)
-# define __alias(_A) __attribute__((weak, alias(_A)))
-# else
-# define __alias(_A)
-# endif
-/* ************************************************************************** */
-/* __section: put this function/data in an ELF section */
-/* ************************************************************************** */
-# ifdef __section
-# undef __section
-# endif
-# if defined(__GNUC__)
-# define __section(_S) __attribute__((section(_S)))
-# else
-# define __section(_S)
-# endif
-/* ************************************************************************** */
-/* __concat: Catenate things in macros */
-/* ************************************************************************** */
-# ifdef __concat
-# undef __concat
-# endif
-# ifdef __concat_
-# undef __concat_
-# endif
-# define __concat_(_X, _Y) _X ## _Y
-# define __concat(_X, _Y) __concat_(_X, _Y)
-/* ************************************************************************** */
-/* __count_va_args: count number of elements in __VA_ARGS__ */
-/* ************************************************************************** */
-# ifdef __count_va_args
-# undef __count_va_args
-# endif
-# if defined(__GNUC__)
-/* This is something that should work, although I don't really understand the
- * trick yet. Source: http://stackoverflow.com/a/2124385/6541022 */
-
-# define __count_va_args(...) \
- __count_va_args_(__VA_ARGS__, __count_va_args_rseq_N())
-# define __count_va_args_(...) __count_va_args_N(__VA_ARGS__)
-
-# define __count_va_args_N( \
- _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
- _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
- _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
- _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
- _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
- _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
- _61, _62, _63, _N, ...) _N
-# define __count_va_args_rseq_N() \
- 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, \
- 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, \
- 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, \
- 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, \
- 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, \
- 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, \
- 3, 2, 1, 0
-
-# else
-# define __count_va_args(...) (0)
-# endif
-
-#endif /* _SYS_CDEFS_H */
+#include <cdefs.h>
diff --git a/include/timer.h b/include/timer.h
index 639ebd7..e52c68a 100644
--- a/include/timer.h
+++ b/include/timer.h
@@ -22,6 +22,7 @@
#if !defined(_TIMER_H) && !defined(__TIMER_H__)
# define _TIMER_H 1
# define __TIMER_H__ 1
+# include <cdefs.h>
/* ************************************************************************** */
/* User timers IDs */
diff --git a/include/umachine.h b/include/umachine.h
index e23d4f0..e2dc10d 100644
--- a/include/umachine.h
+++ b/include/umachine.h
@@ -24,9 +24,9 @@
#if !defined(_UMACHINE_H) && !defined(_UMACHINE)
# define _UMACHINE_H 1
# define _UMACHINE 1
+# include <cdefs.h>
# include <stdint.h>
# include <builtin.h>
-# include <sys/cdefs.h>
/* ************************************************************************** */
/* GBR interaction */
diff --git a/include/unistd.h b/include/unistd.h
index 135d9d1..fbe97a7 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -18,8 +18,15 @@
* ************************************************************************** */
#ifndef _UNISTD_H
# define _UNISTD_H 1
+# include <cdefs.h>
+# ifdef __cplusplus
+extern "C" {
+# endif
typedef unsigned int useconds_t;
extern int usleep(useconds_t __usec);
+# ifdef __cplusplus
+}
+# endif
#endif /* _UNISTD_H */