mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
Use mkostemp instead of mktemp where available
This commit is contained in:
parent
cbef88a593
commit
333fb1bf97
2 changed files with 9 additions and 1 deletions
|
@ -523,7 +523,7 @@ fi
|
||||||
|
|
||||||
AC_CHECK_FUNCS( wcsdup wcsndup wcslen wcscasecmp wcsncasecmp fwprintf )
|
AC_CHECK_FUNCS( wcsdup wcsndup wcslen wcscasecmp wcsncasecmp fwprintf )
|
||||||
AC_CHECK_FUNCS( futimes wcwidth wcswidth wcstok fputwc fgetwc )
|
AC_CHECK_FUNCS( futimes wcwidth wcswidth wcstok fputwc fgetwc )
|
||||||
AC_CHECK_FUNCS( wcstol wcslcat wcslcpy lrand48_r killpg )
|
AC_CHECK_FUNCS( wcstol wcslcat wcslcpy lrand48_r killpg mkostemp )
|
||||||
AC_CHECK_FUNCS( backtrace backtrace_symbols sysconf getifaddrs getpeerucred getpeereid )
|
AC_CHECK_FUNCS( backtrace backtrace_symbols sysconf getifaddrs getpeerucred getpeereid )
|
||||||
|
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
|
|
|
@ -1380,12 +1380,20 @@ bool history_t::save_internal_via_rewrite()
|
||||||
for (size_t attempt = 0; attempt < 10 && out_fd == -1; attempt++)
|
for (size_t attempt = 0; attempt < 10 && out_fd == -1; attempt++)
|
||||||
{
|
{
|
||||||
char *narrow_str = wcs2str(tmp_name_template.c_str());
|
char *narrow_str = wcs2str(tmp_name_template.c_str());
|
||||||
|
#if HAVE_MKOSTEMP
|
||||||
|
out_fd = mkostemp(narrow_str, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_CLOEXEC);
|
||||||
|
if (out_fd >= 0)
|
||||||
|
{
|
||||||
|
tmp_name = str2wcstring(narrow_str);
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (narrow_str && mktemp(narrow_str))
|
if (narrow_str && mktemp(narrow_str))
|
||||||
{
|
{
|
||||||
/* It was successfully templated; try opening it atomically */
|
/* It was successfully templated; try opening it atomically */
|
||||||
tmp_name = str2wcstring(narrow_str);
|
tmp_name = str2wcstring(narrow_str);
|
||||||
out_fd = wopen_cloexec(tmp_name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0644);
|
out_fd = wopen_cloexec(tmp_name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0644);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
free(narrow_str);
|
free(narrow_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue