1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:27:45 +00:00

LibC: The standard C library needs to be able to build as pure C.

Looks like we can't use those comfy C++ attributes in this code then.
This commit is contained in:
Andreas Kling 2019-02-15 22:37:20 +01:00
parent 3b42db0b4c
commit cbfd416279
4 changed files with 14 additions and 12 deletions

View file

@ -4,7 +4,7 @@
__BEGIN_DECLS __BEGIN_DECLS
[[noreturn]] void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func); __attribute__((noreturn)) void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
#define assert(expr) ((expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)) #define assert(expr) ((expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#define CRASH() do { asm volatile("ud2"); } while(0) #define CRASH() do { asm volatile("ud2"); } while(0)

View file

@ -4,41 +4,41 @@
__BEGIN_DECLS __BEGIN_DECLS
[[gnu::always_inline]] inline int isascii(int ch) ALWAYS_INLINE int isascii(int ch)
{ {
return (ch & ~0x7f) == 0; return (ch & ~0x7f) == 0;
} }
[[gnu::always_inline]] inline int isspace(int ch) ALWAYS_INLINE int isspace(int ch)
{ {
return ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\v'; return ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\v';
} }
[[gnu::always_inline]] inline int islower(int c) ALWAYS_INLINE int islower(int c)
{ {
return c >= 'a' && c <= 'z'; return c >= 'a' && c <= 'z';
} }
[[gnu::always_inline]] inline int isupper(int c) ALWAYS_INLINE int isupper(int c)
{ {
return c >= 'A' && c <= 'Z'; return c >= 'A' && c <= 'Z';
} }
[[gnu::always_inline]] inline int tolower(int c) ALWAYS_INLINE int tolower(int c)
{ {
if (isupper(c)) if (isupper(c))
return c | 0x20; return c | 0x20;
return c; return c;
} }
[[gnu::always_inline]] inline int toupper(int c) ALWAYS_INLINE int toupper(int c)
{ {
if (islower(c)) if (islower(c))
return c & ~0x20; return c & ~0x20;
return c; return c;
} }
[[gnu::always_inline]] inline int isdigit(int c) ALWAYS_INLINE int isdigit(int c)
{ {
return c >= '0' && c <= '9'; return c >= '0' && c <= '9';
} }

View file

@ -9,16 +9,16 @@ __BEGIN_DECLS
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#define MB_CUR_MAX 1 #define MB_CUR_MAX 1
[[gnu::malloc, gnu::alloc_size(1)]] void* malloc(size_t); __attribute__((malloc)) __attribute__((alloc_size(1))) void* malloc(size_t);
[[gnu::malloc, gnu::alloc_size(1, 2)]] void* calloc(size_t nmemb, size_t); __attribute__((malloc)) __attribute__((alloc_size(1, 2))) void* calloc(size_t nmemb, size_t);
void free(void*); void free(void*);
void* realloc(void *ptr, size_t); void* realloc(void *ptr, size_t);
char* getenv(const char* name); char* getenv(const char* name);
int atoi(const char*); int atoi(const char*);
long atol(const char*); long atol(const char*);
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
[[noreturn]] void exit(int status); __attribute__((noreturn)) void exit(int status);
[[noreturn]] void abort(); __attribute__((noreturn)) void abort();
char* ptsname(int fd); char* ptsname(int fd);
int ptsname_r(int fd, char* buffer, size_t); int ptsname_r(int fd, char* buffer, size_t);
int abs(int); int abs(int);

View file

@ -2,6 +2,8 @@
#define _POSIX_VERSION 200809L #define _POSIX_VERSION 200809L
#define ALWAYS_INLINE inline __attribute__((always_inline))
#ifdef __cplusplus #ifdef __cplusplus
#define __BEGIN_DECLS extern "C" { #define __BEGIN_DECLS extern "C" {
#define __END_DECLS } #define __END_DECLS }