diff --git a/builtin_set.cpp b/builtin_set.cpp index a29696be1..7eec8eb4b 100644 --- a/builtin_set.cpp +++ b/builtin_set.cpp @@ -74,7 +74,7 @@ static int my_env_set( const wchar_t *key, wcstring_list_t &val, int scope ) int show_hint = 0; struct stat buff; - const wchar_t *dir = val[ i ].c_str(); + const wchar_t *dir = val[i].c_str(); if( wstat( dir, &buff ) ) { @@ -91,7 +91,6 @@ static int my_env_set( const wchar_t *key, wcstring_list_t &val, int scope ) if( error ) { const wchar_t *colon; - append_format(stderr_buffer, _(BUILTIN_SET_PATH_ERROR), L"set", dir, key); colon = wcschr( dir, L':' ); diff --git a/common.cpp b/common.cpp index 0bdb2035b..38ca4d434 100644 --- a/common.cpp +++ b/common.cpp @@ -460,10 +460,13 @@ wcstring vformat_string(const wchar_t *format, va_list va_orig) void append_format(wcstring &str, const wchar_t *format, ...) { + /* Preserve errno across this call since it likes to stomp on it */ + int err = errno; va_list va; va_start( va, format ); str.append(vformat_string(format, va)); va_end( va ); + errno = err; } wchar_t *wcsvarname( const wchar_t *str ) diff --git a/wutil.cpp b/wutil.cpp index 6ef3642f3..2e087aa83 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -372,6 +372,9 @@ const wchar_t *wgettext( const wchar_t *in ) { if( !in ) return in; + + // preserve errno across this since this is often used in printing error messages + int err = errno; wgettext_init_if_necessary(); @@ -384,6 +387,7 @@ const wchar_t *wgettext( const wchar_t *in ) char *out = gettext(mbs_in.c_str()); val = new wcstring(format_string(L"%s", out)); } + errno = err; return val->c_str(); }