diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2016-02-28 01:38:28 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2016-02-28 01:38:28 -0800 |
commit | 9151ec709258273a555180696bdbae8bb0794658 (patch) | |
tree | be7eb6824e18216c71064227d277a0a708ba6ae5 /src/common.cpp | |
parent | 3633c51ad8aee79add7727457c998c42a1638f72 (diff) |
Eliminate narrow_string_rep_t
This was used to cache a narrow string representation
of commands, so that if certain system calls returned errors
after fork, we could output error messages without allocating
memory. But in practice these errors are very uncommon, as are
commands that have wide characters. It is simpler to do a best-effort
output of the wide string, instead of caching a narrow string
unconditionally.
Diffstat (limited to 'src/common.cpp')
-rw-r--r-- | src/common.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common.cpp b/src/common.cpp index 21c4b92c..2aa76cc5 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -795,6 +795,24 @@ void format_long_safe(wchar_t buff[64], long val) } } +void narrow_string_safe(char buff[64], const wchar_t *s) +{ + size_t idx = 0; + for (size_t widx = 0; s[widx] != L'\0'; widx++) + { + wchar_t c = s[widx]; + if (c <= 127) + { + buff[idx++] = char(c); + if (idx + 1 == 64) + { + break; + } + } + } + buff[idx] = '\0'; +} + wcstring reformat_for_screen(const wcstring &msg) { wcstring buff; |