aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-05-03 15:27:58 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-05-03 15:27:58 -0700
commit333fb1bf97e53725b730fa7047e1873cacceed44 (patch)
tree0c99645100275c8ea66e7fec577aa301e2a69a2c
parentcbef88a593d01194d81fb24bbc616a4d72718546 (diff)
Use mkostemp instead of mktemp where available
-rw-r--r--configure.ac2
-rw-r--r--history.cpp8
2 files changed, 9 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 1b91f962..68b53c20 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 d0933cb0..77414ff7 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);
}