From 7acf66de3ef893100d469c115054409d95506117 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 30 Apr 2020 17:46:06 +0100 Subject: [PATCH] Added errno.h and ptrdiff_t --- photon/libc/errno/errno.c | 9 +++++++++ photon/libc/include/errno.h | 18 ++++++++++++++++++ photon/libc/include/stddef.h | 12 ++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 photon/libc/errno/errno.c create mode 100644 photon/libc/include/errno.h diff --git a/photon/libc/errno/errno.c b/photon/libc/errno/errno.c new file mode 100644 index 0000000..db94f50 --- /dev/null +++ b/photon/libc/errno/errno.c @@ -0,0 +1,9 @@ + + +/* XXX This isn't thread safe */ +static int __errno = 0; + +int *__errno_location(void) +{ + return &__errno; +} diff --git a/photon/libc/include/errno.h b/photon/libc/include/errno.h new file mode 100644 index 0000000..b50e308 --- /dev/null +++ b/photon/libc/include/errno.h @@ -0,0 +1,18 @@ +#ifndef ERRNO_H_ +#define ERRNO_H_ + +#include + +#define errno (*__errno_location()) + +#if defined(__cplusplus) +extern "C" { +#endif + +extern int *__errno_location(void); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/photon/libc/include/stddef.h b/photon/libc/include/stddef.h index 594fd56..591a8ae 100644 --- a/photon/libc/include/stddef.h +++ b/photon/libc/include/stddef.h @@ -10,13 +10,21 @@ extern "C" { #endif /* defined(__cplusplus) */ +#ifndef __ptrdiff_t_defined +#define __ptrdiff_t_defined typedef __intptr_t ptrdiff_t; +#endif -#ifndef __SIZE_T_DEFINED -#define __SIZE_T_DEFINED +#ifndef __size_t_defined +#define __size_t_defined typedef __uintptr_t size_t; #endif +#ifndef __ssize_t_defined +#define __ssize_t_defined +typedef __intptr_t ssize_t; +#endif + #if defined(__cplusplus) } #endif /* defined(__cplusplus) */