$NetBSD: patch-ae,v 1.2 2007/12/23 04:50:30 minskim Exp $

--- wdiff.c.orig	1994-11-05 23:57:23.000000000 -0800
+++ wdiff.c
@@ -168,6 +168,10 @@ int interrupted;		/* set when some signa
 # define L_tmpnam PATH_MAX
 #endif
 
+#ifdef HAVE_MKSTEMP
+# define MKSTEMP_TEMPLATE	"/tmp/wdiffXXXXXXXX"
+#endif
+
 typedef struct side SIDE;	/* all variables for one side */
 struct side
 {
@@ -555,6 +559,9 @@ static void
 split_file_into_words (SIDE *side)
 {
   struct stat stat_buffer;	/* for checking if file is directory */
+#ifdef HAVE_MKSTEMP
+  int fd;
+#endif
 
   /* Open files.  */
 
@@ -566,10 +573,23 @@ split_file_into_words (SIDE *side)
 	 this temporary local file.  Once done, prepare it for reading.
 	 We do not need the file name itself anymore.  */
 
+#ifdef HAVE_MKSTEMP
+      strcpy (side->temp_name, MKSTEMP_TEMPLATE);
+      if ((fd = mkstemp(side->temp_name)) < 0)
+	error (EXIT_OTHER_REASON, 0, "mkstemp failed");
+      side->file = fdopen (fd, "w+");
+      if (side->file == NULL)
+	{
+	  int e = errno;
+	  (void) unlink (side->temp_name);
+	  error (EXIT_OTHER_REASON, e, side->temp_name);
+	}
+#else
       tmpnam (side->temp_name);
       side->file = fopen (side->temp_name, "w+");
       if (side->file == NULL)
 	error (EXIT_OTHER_REASON, errno, side->temp_name);
+#endif
       if (unlink (side->temp_name) != 0)
 	error (EXIT_OTHER_REASON, errno, side->temp_name);
       while (side->character = getchar (), side->character != EOF)
@@ -593,10 +613,23 @@ split_file_into_words (SIDE *side)
   side->character = getc (side->file);
   side->position = 0;
 
+#ifdef HAVE_MKSTEMP
+  strcpy (side->temp_name, MKSTEMP_TEMPLATE);
+  if ((fd = mkstemp(side->temp_name)) < 0)
+    error (EXIT_OTHER_REASON, 0, "mkstemp failed");
+  side->temp_file = fdopen (fd, "w");
+  if (side->temp_file == NULL)
+    {
+      int e = errno;
+      (void) unlink (side->temp_name);
+      error (EXIT_OTHER_REASON, e, side->temp_name);
+    }
+#else
   tmpnam (side->temp_name);
   side->temp_file = fopen (side->temp_name, "w");
   if (side->temp_file == NULL)
     error (EXIT_OTHER_REASON, errno, side->temp_name);
+#endif
 
   /* Complete splitting input file into words on output.  */
 
@@ -1135,7 +1168,7 @@ Mandatory arguments to long options are 
 | Main program.	 |
 `---------------*/
 
-void
+int
 main (int argc, char *const argv[])
 {
   int option_char;		/* option character */
@@ -1304,12 +1337,13 @@ main (int argc, char *const argv[])
       reformat_diff_output ();
       fclose (input_file);
     }
-
-  /* Clean up.  Beware that input_file and output_file might not exist,
-     if a signal occurred early in the program.  */
-
-  if (input_file)
-    complete_input_program ();
+  else
+    {
+      /* Clean up.  Beware that input_file and output_file might not
+	exist, if a signal occurred early in the program.  */
+      if (input_file)
+	complete_input_program ();
+    }
 
   if (*left_side->temp_name)
     unlink (left_side->temp_name);
@@ -1329,5 +1363,5 @@ main (int argc, char *const argv[])
       || count_changed_left || count_changed_right)
     exit (EXIT_ANY_DIFFERENCE);
 
-  exit (EXIT_NO_DIFFERENCES);
+  return EXIT_NO_DIFFERENCES;
 }
