From 9151ec709258273a555180696bdbae8bb0794658 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 28 Feb 2016 01:38:28 -0800 Subject: 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. --- src/common.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/common.cpp') 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; -- cgit v1.2.3