Only widen string if necessary

This tried a bunch of times, but only the final one is important.
This commit is contained in:
Fabian Homborg 2019-05-13 21:15:58 +02:00
parent 87b93cd4ca
commit 752b5362ee

View file

@ -511,16 +511,18 @@ bool env_universal_t::open_temporary_file(const wcstring &directory, wcstring *o
int saved_errno;
const wcstring tmp_name_template = directory + L"/fishd.tmp.XXXXXX";
char *narrow_str = nullptr;
for (size_t attempt = 0; attempt < 10 && !success; attempt++) {
char *narrow_str = wcs2str(tmp_name_template);
narrow_str = wcs2str(tmp_name_template);
int result_fd = fish_mkstemp_cloexec(narrow_str);
saved_errno = errno;
success = result_fd != -1;
*out_fd = result_fd;
*out_path = str2wcstring(narrow_str);
free(narrow_str);
}
*out_path = str2wcstring(narrow_str);
free(narrow_str);
if (!success) {
const char *error = std::strerror(saved_errno);
debug(0, _(L"Unable to open temporary file '%ls': %s"), out_path->c_str(), error);