From 333fb1bf97e53725b730fa7047e1873cacceed44 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 3 May 2014 15:27:58 -0700 Subject: [PATCH] Use mkostemp instead of mktemp where available --- configure.ac | 2 +- history.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1b91f962c..68b53c208 100644 --- a/configure.ac +++ b/configure.ac @@ -523,7 +523,7 @@ fi AC_CHECK_FUNCS( wcsdup wcsndup wcslen wcscasecmp wcsncasecmp fwprintf ) 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 ) if test x$local_gettext != xno; then diff --git a/history.cpp b/history.cpp index d0933cb08..77414ff73 100644 --- a/history.cpp +++ b/history.cpp @@ -1380,12 +1380,20 @@ bool history_t::save_internal_via_rewrite() for (size_t attempt = 0; attempt < 10 && out_fd == -1; attempt++) { 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)) { /* It was successfully templated; try opening it atomically */ tmp_name = str2wcstring(narrow_str); out_fd = wopen_cloexec(tmp_name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0644); } +#endif free(narrow_str); }