ref: 3367504a83d695f670edea4382b87b1ba17f7893
parent: 2b7d11ed0ac110049760a34794686a0cd65071d6
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Jun 13 14:34:49 EDT 2020
libc: Add arch/cdefs.h This new header contains all the common definitions of the architecture in only one file. It makes easier to port to new architectures and to fix errors.
--- /dev/null
+++ b/include/bits/amd64/arch/cdefs.h
@@ -1,0 +1,30 @@
+#ifdef _NEED_SIZET
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+#undef _NEED_SIZET
+#endif
+
+#ifdef _NEED_PTRDIFFT
+#ifndef _PTRDIFFT
+typedef long ptrdiff_t;
+#define _PTRDIFFT
+#endif
+#undef _NEED_PTRDIFFT
+#endif
+
+#ifdef _NEED_NULL
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+#undef _NEED_NULL
+#endif
+
+#ifdef _NEED_WCHART
+#ifndef _WCHART
+typedef int wchar_t;
+#define _WCHART
+#endif
+#undef _NEED_WCHART
+#endif
--- a/include/bits/amd64/arch/stddef.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/include/bits/amd64/arch/stdio.h
+++ b/include/bits/amd64/arch/stdio.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define BUFSIZ 512
#define FILENAME_MAX 256
#define FOPEN_MAX 16
--- a/include/bits/amd64/arch/stdlib.h
+++ b/include/bits/amd64/arch/stdlib.h
@@ -1,14 +1,4 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
#define _ALIGNTYPE long double
--- a/include/bits/amd64/arch/string.h
+++ b/include/bits/amd64/arch/string.h
@@ -1,6 +1,1 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define __NUMCHARS 128
--- a/include/bits/amd64/arch/time.h
+++ b/include/bits/amd64/arch/time.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define _MAXYEAR 9999
-typedef long int time_t;
+typedef long time_t;
--- /dev/null
+++ b/include/bits/arm32/arch/cdefs.h
@@ -1,0 +1,30 @@
+#ifdef _NEED_SIZET
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+#undef _NEED_SIZET
+#endif
+
+#ifdef _NEED_PTRDIFFT
+#ifndef _PTRDIFFT
+typedef long ptrdiff_t;
+#define _PTRDIFFT
+#endif
+#undef _NEED_PTRDIFFT
+#endif
+
+#ifdef _NEED_NULL
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+#undef _NEED_NULL
+#endif
+
+#ifdef _NEED_WCHART
+#ifndef _WCHART
+typedef int wchar_t;
+#define _WCHART
+#endif
+#undef _NEED_WCHART
+#endif
--- a/include/bits/arm32/arch/stddef.h
+++ /dev/null
@@ -1,9 +1,0 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/include/bits/arm32/arch/stdio.h
+++ b/include/bits/arm32/arch/stdio.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define BUFSIZ 512
#define FILENAME_MAX 256
#define FOPEN_MAX 16
--- a/include/bits/arm32/arch/stdlib.h
+++ b/include/bits/arm32/arch/stdlib.h
@@ -1,14 +1,4 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t; // TODO
-#define _WCHAR_T
-#endif
#define _ALIGNTYPE long double
--- a/include/bits/arm32/arch/string.h
+++ b/include/bits/arm32/arch/string.h
@@ -1,6 +1,1 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define __NUMCHARS 128
--- a/include/bits/arm32/arch/time.h
+++ b/include/bits/arm32/arch/time.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define _MAXYEAR 9999
typedef long int time_t;
--- /dev/null
+++ b/include/bits/arm64/arch/cdefs.h
@@ -1,0 +1,30 @@
+#ifdef _NEED_SIZET
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+#undef _NEED_SIZET
+#endif
+
+#ifdef _NEED_PTRDIFFT
+#ifndef _PTRDIFFT
+typedef long ptrdiff_t;
+#define _PTRDIFFT
+#endif
+#undef _NEED_PTRDIFFT
+#endif
+
+#ifdef _NEED_NULL
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+#undef _NEED_NULL
+#endif
+
+#ifdef _NEED_WCHART
+#ifndef _WCHART
+typedef int wchar_t;
+#define _WCHART
+#endif
+#undef _NEED_WCHART
+#endif
--- a/include/bits/arm64/arch/stddef.h
+++ /dev/null
@@ -1,9 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/include/bits/arm64/arch/stdio.h
+++ b/include/bits/arm64/arch/stdio.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define BUFSIZ 512
#define FILENAME_MAX 256
#define FOPEN_MAX 16
--- a/include/bits/arm64/arch/stdlib.h
+++ b/include/bits/arm64/arch/stdlib.h
@@ -1,14 +1,4 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
#define _ALIGNTYPE long double
--- a/include/bits/arm64/arch/string.h
+++ b/include/bits/arm64/arch/string.h
@@ -1,6 +1,1 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define __NUMCHARS 128
--- a/include/bits/arm64/arch/time.h
+++ b/include/bits/arm64/arch/time.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define _MAXYEAR 9999
typedef long int time_t;
--- /dev/null
+++ b/include/bits/i386/arch/cdefs.h
@@ -1,0 +1,30 @@
+#ifdef _NEED_SIZET
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+#undef _NEED_SIZET
+#endif
+
+#ifdef _NEED_PTRDIFFT
+#ifndef _PTRDIFFT
+typedef long ptrdiff_t;
+#define _PTRDIFFT
+#endif
+#undef _NEED_PTRDIFFT
+#endif
+
+#ifdef _NEED_NULL
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+#undef _NEED_NULL
+#endif
+
+#ifdef _NEED_WCHART
+#ifndef _WCHART
+typedef int wchar_t;
+#define _WCHART
+#endif
+#undef _NEED_WCHART
+#endif
--- a/include/bits/i386/arch/stddef.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/include/bits/i386/arch/stdio.h
+++ b/include/bits/i386/arch/stdio.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define BUFSIZ 512
#define FILENAME_MAX 256
#define FOPEN_MAX 16
--- a/include/bits/i386/arch/stdlib.h
+++ b/include/bits/i386/arch/stdlib.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
--- a/include/bits/i386/arch/string.h
+++ b/include/bits/i386/arch/string.h
@@ -1,5 +1,1 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#endif
-
#define __NUMCHARS 128
--- a/include/bits/i386/arch/time.h
+++ b/include/bits/i386/arch/time.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
#define _MAXYEAR 2037
typedef long int time_t;
--- /dev/null
+++ b/include/bits/ppc32/arch/cdefs.h
@@ -1,0 +1,30 @@
+#ifdef _NEED_SIZET
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+#undef _NEED_SIZET
+#endif
+
+#ifdef _NEED_PTRDIFFT
+#ifndef _PTRDIFFT
+typedef long ptrdiff_t;
+#define _PTRDIFFT
+#endif
+#undef _NEED_PTRDIFFT
+#endif
+
+#ifdef _NEED_NULL
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+#undef _NEED_NULL
+#endif
+
+#ifdef _NEED_WCHART
+#ifndef _WCHART
+typedef int wchar_t;
+#define _WCHART
+#endif
+#undef _NEED_WCHART
+#endif
--- a/include/bits/ppc32/arch/stddef.h
+++ /dev/null
@@ -1,9 +1,0 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/include/bits/ppc32/arch/stdio.h
+++ b/include/bits/ppc32/arch/stdio.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define BUFSIZ 512
#define FILENAME_MAX 256
#define FOPEN_MAX 16
--- a/include/bits/ppc32/arch/stdlib.h
+++ b/include/bits/ppc32/arch/stdlib.h
@@ -1,14 +1,4 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t; // TODO
-#define _WCHAR_T
-#endif
#define _ALIGNTYPE long double
--- a/include/bits/ppc32/arch/string.h
+++ b/include/bits/ppc32/arch/string.h
@@ -1,6 +1,1 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define __NUMCHARS 128
--- a/include/bits/ppc32/arch/time.h
+++ b/include/bits/ppc32/arch/time.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned int size_t;
-#define _SIZET
-#endif
-
#define _MAXYEAR 9999
typedef long int time_t;
--- /dev/null
+++ b/include/bits/z80/arch/cdefs.h
@@ -1,0 +1,30 @@
+#ifdef _NEED_SIZET
+#ifndef _SIZET
+typedef unsigned short size_t;
+#define _SIZET
+#endif
+#undef _NEED_SIZET
+#endif
+
+#ifdef _NEED_PTRDIFFT
+#ifndef _PTRDIFFT
+typedef short ptrdiff_t;
+#define _PTRDIFFT
+#endif
+#undef _NEED_PTRDIFFT
+#endif
+
+#ifdef _NEED_NULL
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+#undef _NEED_NULL
+#endif
+
+#ifdef _NEED_WCHART
+#ifndef _WCHART
+typedef int wchar_t;
+#define _WCHART
+#endif
+#undef _NEED_WCHART
+#endif
--- a/include/bits/z80/arch/stddef.h
+++ /dev/null
@@ -1,14 +1,0 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef short wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef short ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/include/bits/z80/arch/stdio.h
+++ b/include/bits/z80/arch/stdio.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
#define BUFSIZ 512
#define FILENAME_MAX 256
#define FOPEN_MAX 16
--- a/include/bits/z80/arch/stdlib.h
+++ b/include/bits/z80/arch/stdlib.h
@@ -1,14 +1,4 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef short wchar_t;
-#define _WCHAR_T
-#endif
#define _ALIGNTYPE int
--- a/include/bits/z80/arch/string.h
+++ b/include/bits/z80/arch/string.h
@@ -1,5 +1,1 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#endif
-
#define __NUMCHARS 128
--- a/include/bits/z80/arch/time.h
+++ b/include/bits/z80/arch/time.h
@@ -1,8 +1,3 @@
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
#define _MAXYEAR 2037
typedef long time_t;
--- a/include/locale.h
+++ b/include/locale.h
@@ -1,9 +1,8 @@
#ifndef _LOCALE_H
#define _LOCALE_H
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
+#define _NEED_NULL
+#include <arch/cdefs.h>
#define LC_ALL 0
#define LC_COLLATE 1
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -1,11 +1,11 @@
#ifndef _STDDEF_H
#define _STDDEF_H
-#include <arch/stddef.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
+#define _NEED_SIZET
+#define _NEED_WCHAR_T
+#define _NEED_PTRDIFFT
+#define _NEED_NULL
+#include <arch/cdefs.h>
#define offsetof(st, m) ((size_t)&(((st *)0)->m))
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,14 +1,13 @@
#ifndef _STDIO_H
#define _STDIO_H
+#define _NEED_NULL
+#define _NEED_SIZET
+#include <arch/cdefs.h>
#include <arch/stdio.h>
#ifndef FOPEN_MAX
#define FOPEN_MAX 12
-#endif
-
-#ifndef NULL
-#define NULL ((void *) 0)
#endif
#define EOF -1
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -1,11 +1,11 @@
#ifndef _STDLIB_H
#define _STDLIB_H
+#define _NEED_NULL
+#define _NEED_SIZET
+#define _NEED_WCHART
+#include <arch/cdefs.h>
#include <arch/stdlib.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
#define _ATEXIT_MAX 32
--- a/include/string.h
+++ b/include/string.h
@@ -1,11 +1,10 @@
#ifndef _STRING_H
#define _STRING_H
+#define _NEED_SIZET
+#define _NEED_NULL
+#include <arch/cdefs.h>
#include <arch/string.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
extern void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
extern void *memmove(void *s1, const void *s2, size_t n);
--- a/include/time.h
+++ b/include/time.h
@@ -1,11 +1,10 @@
#ifndef _TIME_H
#define _TIME_H
+#define _NEED_SIZET
+#define _NEED_NULL
+#include <arch/cdefs.h>
#include <arch/time.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
#define CLOCKS_PER_SEC 1000000