$NetBSD$

--- main.c.orig	2001-04-02 08:57:20.000000000 -0500
+++ main.c
@@ -1,7 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <malloc.h>
 
 #ifndef MSW  /*rwj  --  make portable*/
 #include <signal.h>
@@ -324,9 +323,11 @@ char *tmpdir;
     text_file_name[len + 5] = 't';
     union_file_name[len + 5] = 'u';
 
+#ifdef WITHOUT_MKSTEMP
     mktemp(action_file_name);
     mktemp(text_file_name);
     mktemp(union_file_name);
+#endif
 
     if (jflag)/*rwj*/
       {
@@ -380,6 +381,9 @@ char *tmpdir;
 
 void open_files(void)
 {
+#ifndef WITHOUT_MKSTEMP
+  int fd;
+#endif
   create_file_names();
 
   if (input_file == 0)
@@ -389,11 +393,25 @@ void open_files(void)
 	    open_error(input_file_name);
     }
 
-  action_file = fopen(action_file_name, "w");
+#ifdef WITHOUT_MKSTEMP
+  action_file = fopen(action_file_name, "w+");
+#else
+  action_file = NULL;
+  fd = mkstemp(action_file_name);
+  if (fd >= 0)
+    action_file = fdopen(fd, "w");
+#endif
   if (action_file == 0)
    	open_error(action_file_name);
 
-  text_file = fopen(text_file_name, "w");
+#ifdef WITHOUT_MKSTEMP
+  text_file = fopen(text_file_name, "w+");
+#else
+  text_file = NULL;
+  fd = mkstemp(text_file_name);
+  if (fd >= 0)
+    action_file = fdopen(fd, "w");
+#endif
   if (text_file == 0)
 	open_error(text_file_name);
 
@@ -409,7 +427,14 @@ void open_files(void)
 	 defines_file = fopen(defines_file_name, "w");
 	 if (defines_file == 0)
 	    open_error(defines_file_name);
-	 union_file = fopen(union_file_name, "w");
+#ifdef WITHOUT_MKSTEMP
+	 union_file = fopen(union_file_name, "w+");
+#else
+	 union_file = NULL;
+	 fd = mkstemp(union_file_name);
+	 if (fd >= 0)
+	   union_file = fdopen(fd, "w");
+#endif
 	 if (union_file ==  0)
 	    open_error(union_file_name);
     }
