Index: sort.c
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/sort/sort.c,v
retrieving revision 1.11
diff -u -r1.11 sort.c
--- sort.c	1998/03/06 19:00:26	1.11
+++ sort.c	2000/12/26 23:01:23
@@ -369,7 +369,7 @@
   FILE *fp;
   int fd;
 
-  fd = open (file, O_EXCL | O_WRONLY | O_CREAT | O_TRUNC, 0600);
+  fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
   if (fd < 0 || (fp = fdopen (fd, "w")) == NULL)
     {
       error (0, errno, "%s", file);
@@ -449,22 +449,24 @@
 static char *
 tempname (void)
 {
-  static unsigned int seq;
+  int fd;
   int len = strlen (temp_file_prefix);
   char *name = xmalloc (len + 1 + sizeof ("sort") - 1 + 5 + 5 + 1);
   struct tempnode *node;
 
   node = (struct tempnode *) xmalloc (sizeof (struct tempnode));
   sprintf (name,
-	   "%s%ssort%5.5d%5.5d",
+	   "%s%ssortXXXXXX",
 	   temp_file_prefix,
-	   (len && temp_file_prefix[len - 1] != '/') ? "/" : "",
-	   (unsigned int) getpid () & 0xffff, seq);
+	   (len && temp_file_prefix[len - 1] != '/') ? "/" : "");
 
-  /* Make sure that SEQ's value fits in 5 digits.  */
-  ++seq;
-  if (seq >= 100000)
-    seq = 0;
+  if ((fd = mkstemp(name)) == -1)
+    {
+      error (0, errno, _("mkstemp error"));
+      cleanup ();
+      exit (2);
+    }
+  close(fd);
 
   node->name = name;
   node->next = temphead.next;
