This commit is contained in:
parent
34a9b35037
commit
cb59a4e0e3
@ -7,6 +7,7 @@ set(SOURCES
|
||||
src/unistd.cpp
|
||||
src/errno.cpp
|
||||
src/string.cpp
|
||||
src/assert.cpp
|
||||
src/atexit.cpp
|
||||
src/ctype.cpp
|
||||
src/time.cpp
|
||||
|
33
libc/include/assert.h
Normal file
33
libc/include/assert.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* assert.h: Debug assertions. */
|
||||
|
||||
#ifndef _ASSERT_H
|
||||
#define _ASSERT_H
|
||||
|
||||
#include <bits/attrs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
__noreturn void __assertion_failed(const char* file, int line, const char* function, const char* expr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
#define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define assert(expr)
|
||||
#else
|
||||
#define assert(expr) ((expr) ? (void)0 : __assertion_failed(__FILE__, __LINE__, __func__, #expr))
|
||||
#endif
|
||||
|
||||
#ifdef _LUNA_SOURCE
|
||||
#define release_assert(expr) ((expr) ? (void)0 : __assertion_failed(__FILE__, __LINE__, __func__, #expr))
|
||||
#endif
|
||||
|
||||
#endif
|
@ -3,7 +3,7 @@
|
||||
#ifndef _BITS_ATTRS_H
|
||||
#define _BITS_ATTRS_H
|
||||
|
||||
#if !defined(_STDLIB_H) && !defined(_STRING_H)
|
||||
#if !defined(_STDLIB_H) && !defined(_STRING_H) && !defined(_ASSERT_H)
|
||||
#error "Never include bits/attrs.h directly; use one of the standard library headers."
|
||||
#endif
|
||||
|
||||
|
14
libc/src/assert.cpp
Normal file
14
libc/src/assert.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include <assert.h>
|
||||
#include <luna/Attributes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
_weak [[noreturn]] void __assertion_failed(const char* file, int line, const char* function, const char* expr)
|
||||
{
|
||||
// FIXME: Output to standard error instead of standard output.
|
||||
printf("%s:%d: %s: Assertion '%s' failed.\n", file, line, function, expr);
|
||||
abort();
|
||||
}
|
||||
}
|
@ -54,10 +54,12 @@
|
||||
#define ETIMEDOUT 110 // Connection timed out
|
||||
#define EALREADY 114 // Operation already in progress
|
||||
|
||||
#if defined(IN_MOON) || defined(USE_FREESTANDING) || defined(_LUNA_SYSTEM_ERROR_EXTENSIONS)
|
||||
#if defined(IN_MOON) || defined(USE_FREESTANDING) || defined(_LUNA_SYSTEM_ERROR_EXTENSIONS) || defined(_LUNA_SOURCE)
|
||||
// This one is Luna-specific.
|
||||
#define EFIXME 342 // Functionality not yet implemented
|
||||
|
||||
#ifndef _LUNA_SOURCE
|
||||
const char* error_string(int error);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user