damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

pcrt.h (1036B)


      1 #ifndef PCRT_H
      2 #define PCRT_H
      3 
      4 #ifdef __cplusplus
      5 extern "C" {
      6 #endif
      7 
      8 
      9 /*
     10  * Assertions and pointer violations in debug mode may trigger a dialog
     11  * on Windows. When running headless this is not helpful, but
     12  * unfortunately it cannot be disabled with a compiler option so code
     13  * must be injected into the runtime early in the main function.
     14  * A call to the provided `init_headless_crt()` macro does this in
     15  * a portable manner.
     16  *
     17  * See also:
     18  * https://stackoverflow.com/questions/13943665/how-can-i-disable-the-debug-assertion-dialog-on-windows
     19  */
     20 
     21 #if defined(_WIN32)
     22 
     23 #include <crtdbg.h>
     24 #include <stdio.h>
     25 #include <stdlib.h>
     26 
     27 static int _portable_msvc_headless_report_hook(int reportType, char *message, int *returnValue)
     28 {
     29     fprintf(stderr, "CRT[%d]: %s\n", reportType, message);
     30     *returnValue = 1;
     31     exit(1);
     32     return 1;
     33 }
     34 
     35 #define init_headless_crt() _CrtSetReportHook(_portable_msvc_headless_report_hook)
     36 
     37 #else
     38 
     39 #define init_headless_crt() ((void)0)
     40 
     41 #endif
     42 
     43 
     44 #ifdef __cplusplus
     45 }
     46 #endif
     47 
     48 #endif /* PCRT_H */