Commit Diff


commit - 9f42ff692bc2cb443e1aa112484d293022ce3a30
commit + 793c30b5d7b2959c83174499b64578dde045f9ee
blob - fd76c1551b254d17ac5f497c18317b74d445b335
blob + be07889760fc4487623d8280255a27183820436b
--- got/got.c
+++ got/got.c
@@ -44,6 +44,7 @@
 #include "got_commit_graph.h"
 #include "got_blame.h"
 #include "got_privsep.h"
+#include "got_opentemp.h"
 
 #ifndef nitems
 #define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
@@ -2188,7 +2189,6 @@ collect_commit_logmsg(struct got_pathlist_head *commit
 {
 	struct got_pathlist_entry *pe;
 	const struct got_error *err = NULL;
-	char *tmppath = NULL;
 	char *tmpfile = NULL;
 	char *cmdline_log = (char *)arg;
 	char buf[1024];
@@ -2205,23 +2205,11 @@ collect_commit_logmsg(struct got_pathlist_head *commit
 			return got_error_prefix_errno("malloc");
 		strlcpy(*logmsg, cmdline_log, len);
 		return NULL;
-	}
-
-	tmppath = getenv("TMPDIR");
-	if (tmppath == NULL || strlen(tmppath) == 0)
-		tmppath = "/tmp";
-
-	if (asprintf(&tmpfile, "%s/got-XXXXXXXXXX", tmppath) == -1) {
-		err = got_error_prefix_errno("asprintf");
-		return err;
 	}
 
-	fd = mkstemp(tmpfile);
-	if (fd < 0) {
-		err = got_error_prefix_errno("mktemp");
-		free(tmpfile);
+	err = got_opentemp_named_fd(&tmpfile, &fd, "got-XXXXXXXXXX");
+	if (err)
 		return err;
-	}
 
 	dprintf(fd, "\n"
 	    "# changes to be committed:\n");