ed/ed-0.2-tmpfile.patch

52 lines
1.1 KiB
Diff

--- buf.c
+++ buf.c Mon Nov 27 00:06:51 2000
@@ -194,21 +194,17 @@
extern int newline_added;
-char sfn[15] = ""; /* scratch file name */
-
/* open_sbuf: open scratch file */
int
open_sbuf ()
{
- char *mktemp ();
int u;
isbinary = newline_added = 0;
u = umask(077);
- strcpy (sfn, "/tmp/ed.XXXXXX");
- if (mktemp (sfn) == NULL || (sfp = fopen (sfn, "w+")) == NULL)
+ if ((sfp = tmpfile()) == NULL)
{
- fprintf (stderr, "%s: %s\n", sfn, strerror (errno));
+ fprintf (stderr, "%s\n", strerror (errno));
sprintf (errmsg, "Cannot open temp file");
umask(u);
return ERR;
@@ -226,14 +222,14 @@
{
if (fclose (sfp) < 0)
{
- fprintf (stderr, "%s: %s\n", sfn, strerror (errno));
+ fprintf (stderr, "Cannot close temp file: %s\n", strerror (errno));
sprintf (errmsg, "Cannot close temp file");
return ERR;
}
sfp = NULL;
- unlink (sfn);
}
sfseek = seek_write = 0;
+
return 0;
}
@@ -246,7 +242,6 @@
if (sfp)
{
fclose (sfp);
- unlink (sfn);
}
exit (n);
}