aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/common.h
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-28 01:38:28 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-28 01:38:28 -0800
commit9151ec709258273a555180696bdbae8bb0794658 (patch)
treebe7eb6824e18216c71064227d277a0a708ba6ae5 /src/common.h
parent3633c51ad8aee79add7727457c998c42a1638f72 (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.h')
-rw-r--r--src/common.h33
1 files changed, 3 insertions, 30 deletions
diff --git a/src/common.h b/src/common.h
index 2ba49854..d255ac62 100644
--- a/src/common.h
+++ b/src/common.h
@@ -396,6 +396,9 @@ void debug_safe(int level, const char *msg, const char *param1 = NULL, const cha
void format_long_safe(char buff[64], long val);
void format_long_safe(wchar_t buff[64], long val);
+/** "Narrows" a wide character string. This just grabs any ASCII characters and trunactes. */
+void narrow_string_safe(char buff[64], const wchar_t *s);
+
template<typename T>
T from_string(const wcstring &x)
@@ -526,36 +529,6 @@ public:
/* Helper function to convert from a null_terminated_array_t<wchar_t> to a null_terminated_array_t<char_t> */
void convert_wide_array_to_narrow(const null_terminated_array_t<wchar_t> &arr, null_terminated_array_t<char> *output);
-/* Helper class to cache a narrow version of a wcstring in a malloc'd buffer, so that we can read it after fork() */
-class narrow_string_rep_t
-{
-private:
- const char *str;
-
- /* No copying */
- narrow_string_rep_t &operator=(const narrow_string_rep_t &);
- narrow_string_rep_t(const narrow_string_rep_t &x);
-
-public:
- ~narrow_string_rep_t()
- {
- free((void *)str);
- }
-
- narrow_string_rep_t() : str(NULL) {}
-
- void set(const wcstring &s)
- {
- free((void *)str);
- str = wcs2str(s.c_str());
- }
-
- const char *get() const
- {
- return str;
- }
-};
-
bool is_forked_child();