Compare commits
2 Commits
1043b0772d
...
d0d6557e99
Author | SHA1 | Date | |
---|---|---|---|
d0d6557e99 | |||
8398b2e2e4 |
24
libs/libc/include/assert.h
Normal file
24
libs/libc/include/assert.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef _ASSERT_H
|
||||
#define _ASSERT_H
|
||||
|
||||
#include <bits/macros.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
__lc_noreturn bool __assertion_failed(const char* file, int line, const char* function, const char* expr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define assert(expr) (void)0
|
||||
#else
|
||||
#define assert(expr) (bool)(expr) || __assertion_failed(__FILE__, __LINE__, __FUNCTION__, #expr)
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,8 +1,8 @@
|
||||
#ifndef _BITS_MACROS_H
|
||||
#define _BITS_MACROS_H
|
||||
|
||||
#define noreturn __attribute__((noreturn))
|
||||
#define align(n) __attribute__((aligned(n)))
|
||||
#define deprecated(msg) __attribute__((deprecated(msg)))
|
||||
#define __lc_noreturn __attribute__((noreturn))
|
||||
#define __lc_align(n) __attribute__((aligned(n)))
|
||||
#define __lc_deprecated(msg) __attribute__((deprecated(msg)))
|
||||
|
||||
#endif
|
@ -16,7 +16,7 @@ extern "C"
|
||||
unsigned int msleep(unsigned int ms);
|
||||
|
||||
/* Prints a message to standard error and aborts the program. */
|
||||
noreturn void __luna_abort(const char* message);
|
||||
__lc_noreturn void __luna_abort(const char* message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ extern "C"
|
||||
#endif
|
||||
|
||||
/* Aborts the program. */
|
||||
noreturn void abort();
|
||||
__lc_noreturn void abort();
|
||||
|
||||
/* Normally exits the program with the specified status code. */
|
||||
noreturn void exit(int status);
|
||||
__lc_noreturn void exit(int status);
|
||||
|
||||
/* Registers a handler function to be run at normal program termination. */
|
||||
int atexit(void (*handler)(void));
|
||||
|
@ -22,8 +22,8 @@ extern "C"
|
||||
size_t strlen(const char* str);
|
||||
|
||||
/* Copies the string src into dest. This function is unsafe, use strncpy instead. */
|
||||
deprecated("strcpy is unsafe and should not be used; use strncpy instead") char* strcpy(char* dest,
|
||||
const char* src);
|
||||
__lc_deprecated("strcpy is unsafe and should not be used; use strncpy instead") char* strcpy(char* dest,
|
||||
const char* src);
|
||||
|
||||
/* Copies at most max bytes from the string src into dest. */
|
||||
char* strncpy(char* dest, const char* src, size_t max);
|
||||
@ -32,8 +32,8 @@ extern "C"
|
||||
char* strchr(const char* str, int c);
|
||||
|
||||
/* Concatenates the string src into dest. This function is unsafe, use strncat instead. */
|
||||
deprecated("strcat is unsafe and should not be used; use strncat instead") char* strcat(char* dest,
|
||||
const char* src);
|
||||
__lc_deprecated("strcat is unsafe and should not be used; use strncat instead") char* strcat(char* dest,
|
||||
const char* src);
|
||||
|
||||
/* Concatenates at most max bytes of the string src into dest. */
|
||||
char* strncat(char* dest, const char* src, size_t max);
|
||||
|
@ -25,7 +25,7 @@ extern "C"
|
||||
pid_t fork(void);
|
||||
|
||||
/* Terminates the program with the status code status. */
|
||||
noreturn void _exit(int status);
|
||||
__lc_noreturn void _exit(int status);
|
||||
|
||||
/* Calls the kernel for a specific service, determined by number. */
|
||||
long syscall(long number, ...);
|
||||
|
12
libs/libc/src/assert.cpp
Normal file
12
libs/libc/src/assert.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__lc_noreturn bool __assertion_failed(const char* file, int line, const char* function, const char* expr)
|
||||
{
|
||||
fprintf(stderr, "%s:%d: %s: Assertion '%s' failed.", file, line, function, expr);
|
||||
abort();
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ extern "C"
|
||||
return 0;
|
||||
}
|
||||
|
||||
noreturn void exit(int status)
|
||||
__lc_noreturn void exit(int status)
|
||||
{
|
||||
for (int i = 0; i < atexit_function_count; i++) { atexit_functions[i](); }
|
||||
_exit(status);
|
||||
|
@ -17,7 +17,7 @@ extern "C"
|
||||
return (unsigned int)syscall(SYS_sleep, ms);
|
||||
}
|
||||
|
||||
noreturn void __luna_abort(const char* message)
|
||||
__lc_noreturn void __luna_abort(const char* message)
|
||||
{
|
||||
fputs(message, stderr);
|
||||
abort();
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
extern "C"
|
||||
{
|
||||
noreturn void abort()
|
||||
__lc_noreturn void abort()
|
||||
{
|
||||
_exit(-1);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ extern "C"
|
||||
return syscall(SYS_seek, fd, offset, whence);
|
||||
}
|
||||
|
||||
noreturn void _exit(int status)
|
||||
__lc_noreturn void _exit(int status)
|
||||
{
|
||||
syscall(SYS_exit, status);
|
||||
__builtin_unreachable();
|
||||
|
Loading…
Reference in New Issue
Block a user