33#include <seastar/util/modules.hh>
37SEASTAR_MODULE_EXPORT_BEGIN
45void print_safe(
const char *str,
size_t len)
noexcept {
47 auto result = write(STDERR_FILENO, str, len);
51 }
else if (result == 0) {
66void print_safe(
const char *str)
noexcept {
67 print_safe(str, strlen(str));
73template<
typename Integral,
char Padding = ' '>
74requires std::integral<Integral>
75char* convert_hex_safe(
char *buf,
size_t bufsz, Integral n)
noexcept {
76 const char *digits =
"0123456789abcdef";
77 memset(buf, Padding, bufsz);
78 auto* p = buf + bufsz;
81 *--p = digits[n & 0xf];
89template<
typename Integral>
90requires std::integral<Integral>
91void convert_zero_padded_hex_safe(
char *buf,
size_t bufsz, Integral n)
noexcept {
92 convert_hex_safe<Integral, '0'>(buf, bufsz, n);
98template<
typename Integral>
99requires std::unsigned_integral<Integral>
100void print_zero_padded_hex_safe(Integral n)
noexcept {
101 char buf[
sizeof(n) * 2];
102 convert_zero_padded_hex_safe(buf,
sizeof(buf), n);
103 print_safe(buf,
sizeof(buf));
109template<
typename Integral>
110requires std::unsigned_integral<Integral>
111size_t convert_decimal_safe(
char *buf,
size_t bufsz, Integral n)
noexcept {
112 char tmp[
sizeof(n) * 3];
116 tmp[--i] =
'0' + n % 10;
119 memcpy(buf, tmp + i,
sizeof(tmp) - i);
120 return sizeof(tmp) - i;
126template<
typename Integral>
127void print_decimal_safe(Integral n)
noexcept {
128 char buf[
sizeof(n) * 3];
129 unsigned i =
sizeof(buf);
130 auto len = convert_decimal_safe(buf, i, n);
131 print_safe(buf, len);
133SEASTAR_MODULE_EXPORT_END
Seastar API namespace.
Definition: abort_on_ebadf.hh:26