--- elvis-tiny-1.4.orig/tmp.c
+++ elvis-tiny-1.4/tmp.c
@@ -23,7 +23,8 @@
 #  include <sys/stat.h>
 # endif
 #endif
-
+#include <malloc.h>
+#include <string.h>
 
 #ifndef NO_MODELINE
 static void do_modeline(l, stop)
@@ -75,7 +76,7 @@
 
 
 /* The FAIL() macro prints an error message and then exits. */
-#define FAIL(why,arg)	mode = MODE_EX; msg(why, arg); endwin(); exit(9)
+#define FAIL(why,arg)	mode = MODE_EX; msg(why, arg); sleep(1); endwin(); exit(9)
 
 /* This is the name of the temp file */
 static char	tmpname[80];
@@ -132,6 +133,13 @@
 				msg("\"%s\" is not a regular file", origname);
 				return tmpstart("");
 			}
+			/* Can't edit files > 500.000 bytes */
+			if (statb.st_size > 500000)
+			{
+				msg("\"%s\" is too big (>500000 bytes)",
+					origname);
+				return tmpstart("");
+			}
 		}
 		else
 		{
@@ -186,7 +194,12 @@
 		tmpname[i++]=SLASH;
 	sprintf(tmpname+i, TMPNAME+3, sum, statb.st_ino, statb.st_dev);
 #else
+#  if USE_SNPRINTF
+	snprintf(tmpname, sizeof(tmpname), TMPNAME,
+		o_directory, sum, statb.st_ino, statb.st_dev);
+#  else
 	sprintf(tmpname, TMPNAME, o_directory, sum, statb.st_ino, statb.st_dev);
+#  endif
 #endif
 
 	/* make sure nobody else is editing the same file */
@@ -202,11 +215,28 @@
 
 	/* create the temp file */
 #if ANY_UNIX
-	close(creat(tmpname, 0600));		/* only we can read it */
+#  if USE_MKSTEMP
+	scan = malloc(strlen(o_directory) + 10 + 1); /* "/elvXXXXXX" */
+	if (scan == NULL) {
+		FAIL("No memory: %s", strerror(errno));
+	}
+	sprintf(scan, "%s/elvXXXXXX", o_directory);
+	if ((tmpfd = mkstemp(scan)) >= 0) {
+		if (link(scan, tmpname) < 0) {
+			close(tmpfd);
+			tmpfd = -1;
+		}
+		unlink(scan);
+	}
+	free(scan);
+#  else
+	tmpfd = open(tmpname, O_CREAT|O_WRONLY|O_TRUNC|O_EXCL, 0600);
+						/* only we can read it */
+#  endif
 #else
 	close(creat(tmpname, FILEPERMS));	/* anybody body can read it, alas */
-#endif
 	tmpfd = open(tmpname, O_RDWR | O_BINARY);
+#endif
 	if (tmpfd < 0)
 	{
 		FAIL("Can't create temporary file, errno=%d", errno);
