mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
Implement logger_t::log_fmt for narrow chars by trampolining to wide chars
This satifies the glibc.
This commit is contained in:
parent
92a16921bf
commit
e3b8203187
1 changed files with 19 additions and 4 deletions
23
src/flog.cpp
23
src/flog.cpp
|
@ -56,13 +56,28 @@ void logger_t::log_fmt(const category_t &cat, const wchar_t *fmt, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger_t::log_fmt(const category_t &cat, const char *fmt, ...) {
|
void logger_t::log_fmt(const category_t &cat, const char *fmt, ...) {
|
||||||
|
// glibc dislikes mixing wide and narrow output functions.
|
||||||
|
// So construct a narrow string in-place and output that via wide functions.
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
log1(cat.name);
|
int ret = vsnprintf(nullptr, 0, fmt, va);
|
||||||
log1(": ");
|
|
||||||
std::vfprintf(file_, fmt, va);
|
|
||||||
log1('\n');
|
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("vsnprintf");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t len = static_cast<size_t>(ret) + 1;
|
||||||
|
std::unique_ptr<char[]> buff(new char[len]);
|
||||||
|
|
||||||
|
va_start(va, fmt);
|
||||||
|
ret = vsnprintf(buff.get(), len, fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("vsnprintf");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log_fmt(cat, L"%s", buff.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace flog_details
|
} // namespace flog_details
|
||||||
|
|
Loading…
Reference in a new issue