1 module emscripten.assertd;
2 
3 extern (C):
4 
5 version (Emscripten)
6 {
7     union fpos_t
8     {
9         char[16] __opaque = 0;
10         long __lldata;
11         double __align;
12     }
13 
14     struct _IO_FILE;
15     alias _IO_FILE _iobuf; // for phobos2 compat
16     alias shared(_IO_FILE) FILE;
17 
18     extern __gshared FILE* stdin;
19     extern __gshared FILE* stdout;
20     extern __gshared FILE* stderr;
21     enum
22     {
23         _IOFBF = 0,
24         _IOLBF = 1,
25         _IONBF = 2,
26     }
27 
28     // D runtime hooks for assert failures and array bounds checking
29 
30     void __assert(scope const(char)* msg, scope const(char)* file, uint line) @nogc nothrow @trusted
31     {
32         fprintf(stderr, "Assertion failed in %s:%u: %s\n", file, line, msg);
33         abort();
34     }
35 
36     void _d_assert(string file, uint line) @nogc nothrow @trusted
37     {
38         fprintf(stderr, "Assertion failed in %s:%u\n", file.ptr, line);
39         abort();
40     }
41 
42     void _d_assert_msg(string msg, string file, uint line) @nogc nothrow @trusted
43     {
44         __assert(msg.ptr, file.ptr, line);
45     }
46 
47     void abort() @nogc nothrow;
48 
49     pragma(printf)
50     int fprintf(FILE* __restrict, scope const(char)* __restrict, scope...) @nogc nothrow;
51 
52     // boundchecking
53     void _d_arraybounds_index(string file, uint line, size_t index, size_t length) @nogc nothrow @trusted
54     {
55         if (index >= length)
56             __assert("Array index out of bounds".ptr, file.ptr, line);
57     }
58 }