/*! * \brief Set error string for a failed operation. * * \sa File::set_error() * * \param error_code Error code * \param fmt `printf()`-style format string * \param ap `printf()`-style format arguments as a va_list * * \return FileStatus::OK if the error was successfully set or * FileStatus::FAILED if an error occured */ FileStatus File::set_error_v(int error_code, const char *fmt, va_list ap) { GET_PIMPL_OR_RETURN(FileStatus::FATAL); priv->error_code = error_code; return format_v(priv->error_string, fmt, ap) ? FileStatus::OK : FileStatus::FAILED; }
/*! * \brief Format a string * * \note This uses the `*printf()` family of functions in the system's C * library. The format string may not be understood the same way by every * platform. * * \note The value of `errno` and `GetLastError()` (on Win32) are preserved if * this function does not fail. * * \param fmt Format string * \param ... Format arguments * * \return Resulting formatted string. * \throws std::exception If an error occurs while formatting the string. */ std::string format(const char *fmt, ...) { va_list ap; va_start(ap, fmt); // TODO: This should use exceptions to report errors, but we currently don't // support them due to the substantial size increase of the compiled // binaries. std::string result = format_v(fmt, ap); va_end(ap); return result; }