Typedefs | Functions
FMT_BEGIN_NAMESPACE Namespace Reference

Typedefs

typedef void(* FormatFunc) (internal::buffer &, int, string_view)
 

Functions

int safe_strerror (int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT
 
void format_error_code (internal::buffer &out, int error_code, string_view message) FMT_NOEXCEPT
 
void report_error (FormatFunc func, int error_code, string_view message) FMT_NOEXCEPT
 

Typedef Documentation

typedef void(* FMT_BEGIN_NAMESPACE::FormatFunc) (internal::buffer &, int, string_view)

Definition at line 88 of file format-inl.h.

Function Documentation

void FMT_BEGIN_NAMESPACE::format_error_code ( internal::buffer out,
int  error_code,
string_view  message 
)

Definition at line 159 of file format-inl.h.

160  {
161  // Report error code making sure that the output fits into
162  // inline_buffer_size to avoid dynamic memory allocation and potential
163  // bad_alloc.
164  out.resize(0);
165  static const char SEP[] = ": ";
166  static const char ERROR_STR[] = "error ";
167  // Subtract 2 to account for terminating null characters in SEP and ERROR_STR.
168  std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2;
169  typedef internal::int_traits<int>::main_type main_type;
170  main_type abs_value = static_cast<main_type>(error_code);
172  abs_value = 0 - abs_value;
173  ++error_code_size;
174  }
175  error_code_size += internal::to_unsigned(internal::count_digits(abs_value));
176  writer w(out);
177  if (message.size() <= inline_buffer_size - error_code_size) {
178  w.write(message);
179  w.write(SEP);
180  }
181  w.write(ERROR_STR);
182  w.write(error_code);
183  assert(out.size() <= inline_buffer_size);
184 }
void resize(std::size_t new_size)
Definition: core.h:264
FMT_CONSTEXPR size_t size() const
Definition: core.h:389
std::size_t size() const FMT_NOEXCEPT
Definition: core.h:250
FMT_CONSTEXPR std::enable_if< std::numeric_limits< T >::is_signed, bool >::type is_negative(T value)
Definition: format.h:727
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:208
int count_digits(uint64_t n)
Definition: format.h:777
void FMT_BEGIN_NAMESPACE::report_error ( FormatFunc  func,
int  error_code,
string_view  message 
)

Definition at line 186 of file format-inl.h.

187  {
188  memory_buffer full_message;
189  func(full_message, error_code, message);
190  // Use Writer::data instead of Writer::c_str to avoid potential memory
191  // allocation.
192  std::fwrite(full_message.data(), full_message.size(), 1, stderr);
193  std::fputc('\n', stderr);
194 }
T * data() FMT_NOEXCEPT
Definition: core.h:256
std::size_t size() const FMT_NOEXCEPT
Definition: core.h:250
def func()
Definition: docstring.py:7
int FMT_BEGIN_NAMESPACE::safe_strerror ( int  error_code,
char *&  buffer,
std::size_t  buffer_size 
)

Definition at line 99 of file format-inl.h.

100  {
101  FMT_ASSERT(buffer != FMT_NULL && buffer_size != 0, "invalid buffer");
102 
103  class dispatcher {
104  private:
105  int error_code_;
106  char *&buffer_;
107  std::size_t buffer_size_;
108 
109  // A noop assignment operator to avoid bogus warnings.
110  void operator=(const dispatcher &) {}
111 
112  // Handle the result of XSI-compliant version of strerror_r.
113  int handle(int result) {
114  // glibc versions before 2.13 return result in errno.
115  return result == -1 ? errno : result;
116  }
117 
118  // Handle the result of GNU-specific version of strerror_r.
119  int handle(char *message) {
120  // If the buffer is full then the message is probably truncated.
121  if (message == buffer_ && strlen(buffer_) == buffer_size_ - 1)
122  return ERANGE;
123  buffer_ = message;
124  return 0;
125  }
126 
127  // Handle the case when strerror_r is not available.
128  int handle(internal::null<>) {
129  return fallback(strerror_s(buffer_, buffer_size_, error_code_));
130  }
131 
132  // Fallback to strerror_s when strerror_r is not available.
133  int fallback(int result) {
134  // If the buffer is full then the message is probably truncated.
135  return result == 0 && strlen(buffer_) == buffer_size_ - 1 ?
136  ERANGE : result;
137  }
138 
139 #if !FMT_MSC_VER
140  // Fallback to strerror if strerror_r and strerror_s are not available.
141  int fallback(internal::null<>) {
142  errno = 0;
143  buffer_ = strerror(error_code_);
144  return errno;
145  }
146 #endif
147 
148  public:
149  dispatcher(int err_code, char *&buf, std::size_t buf_size)
150  : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
151 
152  int run() {
153  return handle(strerror_r(error_code_, buffer_, buffer_size_));
154  }
155  };
156  return dispatcher(error_code, buffer, buffer_size).run();
157 }
static QCString result
fmt::internal::null strerror_s(char *, std::size_t,...)
Definition: format-inl.h:61
int errno
Contains the last error code.
Definition: structcmd.h:53
fmt::internal::null strerror_r(int, char *,...)
Definition: format-inl.h:58
#define FMT_NULL
Definition: core.h:107
#define FMT_ASSERT(condition, message)
Definition: core.h:170
unsigned int run