STX  1.0.0
print.h
Go to the documentation of this file.
1 
30 #pragma once
31 
32 #include <cstdio>
33 
37 
39 #define STX_PANIC_EPRINTF_WITH(STX_ARG_BUFFER, STX_ARG_BUFFER_SIZE, \
40  STX_ARG_FORMAT, STX_ARG_VALUE) \
41  { \
42  int fmt_size = std::snprintf(STX_ARG_BUFFER, STX_ARG_BUFFER_SIZE, \
43  STX_ARG_FORMAT, STX_ARG_VALUE); \
44  if (fmt_size >= STX_ARG_BUFFER_SIZE) { \
45  std::fputs("<format buffer insufficient>", stderr); \
46  } else if (fmt_size < 0) { \
47  std::fputs("<format implementation error>", stderr); \
48  } else { \
49  std::fputs(STX_ARG_BUFFER, stderr); \
50  }; \
51  }
52 
54 #define STX_PANIC_EPRINTF(STX_ARG_STR_SIZE, STX_ARG_FORMAT, STX_ARG_VALUE) \
55  { \
56  /* string length + terminating null character */ \
57  char fmt_buffer[STX_ARG_STR_SIZE + 1]; \
58  int fmt_size = std::snprintf(fmt_buffer, STX_ARG_STR_SIZE + 1, \
59  STX_ARG_FORMAT, STX_ARG_VALUE); \
60  if (fmt_size >= STX_ARG_STR_SIZE) { \
61  std::fputs("<format buffer insufficient>", stderr); \
62  } else if (fmt_size < 0) { \
63  std::fputs("<format implementation error>", stderr); \
64  } else { \
65  std::fputs(fmt_buffer, stderr); \
66  }; \
67  }