changeset 9236:c02224afead6

Add mkstemp implementation based on mktemp, for platforms missing it
author Michael Goffioul <michael.goffioul@gmail.com>
date Thu, 21 May 2009 21:12:08 +0100
parents b03953732530
children 3c1762c7e787
files src/ChangeLog src/file-io.cc
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
 2009-05-21  Michael Goffioul  <michael.goffioul@gmail.com>
 
+	* file-io.cc (mkstemp): Add mktemp-based implementation of mkstemp on
+	platforms that do not have it (mkstemp is required by the new help
+	system).
+
 	* TEMPLATE-INST/Array-os.cc: Add "extern template" declaration for
 	Array<octave_idx_type> to avoid implicit instantiation (and duplicate
 	symbols at link-time) [Win32]
--- a/src/file-io.cc
+++ b/src/file-io.cc
@@ -1912,6 +1912,24 @@
 extern "C" int mkstemps (char *pattern, int suffix_len);
 #endif
 
+#if ! defined (HAVE_MKSTEMP) && ! defined (HAVE_MKSTEMPS) && defined (_MSC_VER)
+# if defined (HAVE_FCNTL_H)
+#  include <fcntl.h>
+# endif
+# if defined (HAVE_SYS_STAT_H)
+#  include <sys/stat.h>
+# endif
+int mkstemp (char *tmpl)
+{
+  int ret=-1;
+  mktemp (tmpl);
+  ret = open (tmpl, O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED,
+	      _S_IREAD | _S_IWRITE);
+  return ret;
+}
+#define HAVE_MKSTEMP 1
+#endif
+
 DEFUN (mkstemp, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (@var{template}, @var{delete})\n\