Commit Diff


commit - 57efb1af5959f9ae3844d2ee45e5e1970c820423
commit + 80f4afe898106e3eae350da9d42ecaf3a7d19124
blob - 53b63eff8f31d9fb8abb59dc9c33972ed6d43060
blob + d1ceebbeaf4f607651a7bc7f2fcec650e1c6b04a
--- lib/got_lib_path.h
+++ lib/got_lib_path.h
@@ -34,6 +34,10 @@ char *got_path_get_absolute(const char *);
  */
 char *got_path_normalize(const char *);
 
+/* Open a file descriptor to a new temporary file for writing.
+ * The file is not visible in the filesystem. */
+int got_opentempfd(void);
+
 /* Open a new temporary file for writing.
  * The file is not visible in the filesystem. */
 FILE *got_opentemp(void);
blob - 8f96a5ac2f50abfaf71dbecfc5616812983db43a
blob + 659eaea0299a501e44b05d9f6f3dfc0e603a0da5
--- lib/path.c
+++ lib/path.c
@@ -82,21 +82,30 @@ got_path_segment_count(int *count, const char *path)
 	return NULL;
 }
 
-FILE *
-got_opentemp(void)
+int
+got_opentempfd(void)
 {
 	char name[PATH_MAX];
 	int fd;
-	FILE *f;
 
 	if (strlcpy(name, "/tmp/got.XXXXXXXX", sizeof(name)) >= sizeof(name))
-		return NULL;
+		return -1;
 
 	fd = mkstemp(name);
+	unlink(name);
+	return fd;
+}
+
+FILE *
+got_opentemp(void)
+{
+	int fd;
+	FILE *f;
+
+	fd = got_opentempfd();
 	if (fd < 0)
 		return NULL;
 
-	unlink(name);
 	f = fdopen(fd, "w+");
 	if (f == NULL) {
 		close(fd);