static void foreach_attr_close( gpointer key G_GNUC_UNUSED, gpointer value, gpointer user_data) { amar_attr_t *attr = value; GError **error = user_data; /* return immediately if we've already seen an error */ if (*error) return; if (!attr->wrote_eoa) { (void)amar_attr_close(attr, error); } }
static void do_create(char *opt_file, int opt_verbose, int argc, char **argv) { FILE *output = stdout; amar_t *archive; amar_file_t *file; amar_attr_t *attribute; GError *error = NULL; int i, fd_out, fd_in; off_t filesize = 0; if (opt_file != NULL && strcmp(opt_file,"-") != 0) { fd_out = open(opt_file, O_CREAT|O_WRONLY|O_TRUNC, 0660); if (fd_out <= 0) { error("open of '%s' failed: %s\n", opt_file, strerror(errno)); } } else { fd_out = fileno(stdout); output = stderr; } archive = amar_new(fd_out, O_WRONLY, &error); if (!archive) error_exit("amar_new", error); i = 0; while (i<argc) { fd_in = open(argv[i], O_RDONLY); if (fd_in <= 0) { g_fprintf(stderr, "open of '%s' failed: %s\n", argv[i], strerror(errno)); i++; continue; } filesize = 0; file = amar_new_file(archive, argv[i], strlen(argv[i]), NULL, &error); if (error) error_exit("amar_new_file", error); attribute = amar_new_attr(file, AMAR_ATTR_GENERIC_DATA, &error); if (error) error_exit("amar_new_attr", error); filesize += amar_attr_add_data_fd(attribute, fd_in, 1, &error); if (error) error_exit("amar_attr_add_data_fd", error); if (!amar_attr_close(attribute, &error)) error_exit("amar_attr_close", error); if (!amar_file_close(file, &error)) error_exit("amar_file_close", error); if (opt_verbose == 1) { g_fprintf(output,"%s\n", argv[i]); } else if (opt_verbose > 1) { g_fprintf(output,"%llu %s\n", (unsigned long long)filesize, argv[i]); } close(fd_in); i++; } if (!amar_close(archive, &error)) error_exit("amar_close", error); close(fd_out); }