Commit Diff


commit - 74993f1d9369d6c442c5dc2e6d6ab246a010d485
commit + fc1f1d38881971502de01686af98c14729d7190a
blob - 8c49224c3f3618922f155e0671044215eba5d031
blob + f593c2654e3b83e7aaf1b5fa2a6a2f3311675648
--- include/got_opentemp.h
+++ include/got_opentemp.h
@@ -42,3 +42,6 @@ const struct got_error *got_opentemp_named_fd(char **,
 
 /* Truncate a file. This is useful for re-using open temporary files. */
 const struct got_error *got_opentemp_truncate(FILE *);
+
+/* Truncate a file via a file descriptor. */
+const struct got_error *got_opentemp_truncatefd(int);
blob - 0794b2e04314c60cac1d027dfcaacf239cf877c6
blob + aae9e3f9a424f2d8142440835641b35ea79df48c
--- lib/opentemp.c
+++ lib/opentemp.c
@@ -133,3 +133,13 @@ got_opentemp_truncate(FILE *f)
 		return got_error_from_errno("fseeko");
 	return NULL;
 }
+
+const struct got_error *
+got_opentemp_truncatefd(int fd)
+{
+	if (ftruncate(fd, 0L) == -1)
+		return got_error_from_errno("ftruncate");
+	if (lseek(fd, 0L, SEEK_SET) == -1)
+		return got_error_from_errno("lseek");
+	return NULL;
+}