aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cfuns-c.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c
index ec9a139d..856e4bcc 100644
--- a/src/lib/cfuns-c.c
+++ b/src/lib/cfuns-c.c
@@ -79,6 +79,11 @@
#endif
namespace OpenAxiom {
+ // Make a copy of string data on free store.
+ static char*
+ copy_c_str(const std::string& s) {
+ return strdup(s.c_str());
+ }
OPENAXIOM_C_EXPORT int
addtopath(char *dir)
@@ -500,11 +505,12 @@ oa_acquire_temporary_pathname() {
exit(1);
}
return strdup(buf);
+#elif HAVE_DECL_MKTEMP
+ return mktemp(copy_c_str(std::string{ oa_get_tmpdir() } + "/oa-XXXXXX"));
#elif HAVE_DECL_TEMPNAM
return tempnam(oa_get_tmpdir(), "oa-");
#else
- std::string s = "oa-" + std::to_string(random());
- return strdup(s.c_str());
+ return copy_c_str("oa-" + std::to_string(random()));
#endif
}