X-Git-Url: https://git.saurik.com/minimal.git/blobdiff_plain/50b825894d028eac1015c3e4d3f974d43eb022d0..9f1a211eb5e9be2ad45a040428394ced9e49bbe9:/stdlib.h diff --git a/stdlib.h b/stdlib.h index a9faa14..8d0f8c9 100644 --- a/stdlib.h +++ b/stdlib.h @@ -35,10 +35,29 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef MINIMAL_STDLIB_H +#define MINIMAL_STDLIB_H + +#ifdef __i386__ +#define _breakpoint() \ + __asm__ ("int $0x03") +#else +#define _breakpoint() +#endif + +#ifdef __cplusplus +#define _assert_(e) \ + throw e +#else +#define _assert_(e) \ + exit(1) +#endif + #define _assert(expr) \ do if (!(expr)) { \ fprintf(stderr, "%s(%u): _assert(%u:%s)\n", __FILE__, __LINE__, errno, #expr); \ - exit(1); \ + _breakpoint(); \ + _assert_(#expr); \ } while (false) #define _syscall(expr) \ @@ -55,12 +74,39 @@ for (;;) #define _trace() \ - printf("_trace(%s:%u)\n", __FILE__, __LINE__) + fprintf(stderr, "_trace(%s:%u): %s\n", __FILE__, __LINE__, __FUNCTION__) #define _not(type) \ ((type) ~ (type) 0) +#define _disused \ + __attribute__((unused)) + +#define _label__(x) _label ## x +#define _label_(y) _label__(y) +#define _label _label_(__LINE__) + +#define _packed \ + __attribute__((packed)) + +#ifdef __cplusplus + +template +struct Iterator_ { + typedef typename Type_::const_iterator Result; +}; + +#define _foreach(item, list) \ + for (bool _stop(true); _stop; ) \ + for (const __typeof__(list) &_list = (list); _stop; _stop = false) \ + for (Iterator_<__typeof__(list)>::Result item = _list.begin(); item != _list.end(); ++item) + +#endif + +#include #include #include #include #include + +#endif/*MINIMAL_STDLIB_H*/