commit d6bab2982477fc276aa4559a2f1c1b5df5e640ce
parent a927f6f629d8faa068aa1aff9ebf1dcce7f349ca
Author: sin <sin@2f30.org>
Date: Thu, 3 Dec 2015 12:26:06 +0000
mkstemp() returns a file descriptor
Diffstat:
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/ed.c b/ed.c
@@ -218,21 +218,18 @@ clearbuf()
static void
setscratch()
{
- int k, flags = O_CREAT | O_TRUNC | O_RDWR | O_EXCL;
- mode_t mode = S_IRUSR | S_IWUSR;
+ int k;
clearbuf();
strcpy(tmpname, "ed.XXXXXX");
- if (mkstemp(tmpname) < 0) {
+ if ((scratch = mkstemp(tmpname)) < 0) {
/* try /tmp if cwd is not writable */
strcpy(tmpname, "/tmp/ed.XXXXXX");
- if (mkstemp(tmpname) < 0)
+ if ((scratch = mkstemp(tmpname)) < 0)
error("failed to create scratch file");
}
- if ((scratch = open(tmpname, flags, mode)) < 0 ||
- (k = makeline("", NULL))) {
+ if ((k = makeline("", NULL)))
error("input/output error in scratch file");
- }
relink(k, k, k, k);
modflag = 0;
}