+/* Write out a CTF archive. The entries in CTF_FILES are referenced by name:
+ the names are passed in the names array, which must have CTF_FILES entries.
+
+ If the filename is NULL, create a temporary file and return a pointer to it.
+
+ Returns 0 on success, or an errno, or an ECTF_* value. */
+int
+ctf_arc_write (const char *file, ctf_file_t ** ctf_files, size_t ctf_file_cnt,
+ const char **names, size_t threshold)
+{
+ int err;
+ int fd;
+
+ if ((fd = open (file, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0666)) < 0)
+ {
+ ctf_dprintf ("ctf_arc_write(): cannot create %s: %s\n", file,
+ strerror (errno));
+ return errno;
+ }
+
+ err = ctf_arc_write_fd (fd, ctf_files, ctf_file_cnt, names, threshold);
+ if (err)
+ goto err;
+
+ if ((err = close (fd)) < 0)
+ {
+ ctf_dprintf ("ctf_arc_write(): Cannot close after writing to archive: "
+ "%s\n", strerror (errno));
+ goto err_close;
+ }
+
+ err:
+ close (fd);
+ if (err < 0)
+ unlink (file);
+
+ return err;
+
+ err_close:
+ if (err < 0)
+ unlink (file);
+
+ return err;
+}
+