예제 #1
0
파일: wim.c 프로젝트: twwbond/wimlib
/* API function documented in wimlib.h  */
WIMLIBAPI void
wimlib_free(WIMStruct *wim)
{
    if (!wim)
        return;

    while (!list_empty(&wim->subwims)) {
        WIMStruct *subwim;

        subwim = list_entry(wim->subwims.next, WIMStruct, subwim_node);
        list_del(&subwim->subwim_node);
        wimlib_free(subwim);
    }

    if (filedes_valid(&wim->in_fd))
        filedes_close(&wim->in_fd);
    if (filedes_valid(&wim->out_fd))
        filedes_close(&wim->out_fd);

    free_blob_table(wim->blob_table);

    wimlib_free_decompressor(wim->decompressor);

    FREE(wim->filename);
    free_wim_info(wim->wim_info);
    if (wim->image_metadata) {
        for (unsigned i = 0; i < wim->hdr.image_count; i++)
            put_image_metadata(wim->image_metadata[i], NULL);
        FREE(wim->image_metadata);
    }
    FREE(wim);
}
예제 #2
0
int main(int argc, char **argv)
{
	const char *in_filename;
	const char *out_filename;
	int in_fd;
	int out_fd;
	uint32_t ctype;
	uint32_t chunk_size;
	int ret;
	struct wimlib_decompressor *decompressor;

	if (argc != 3) {
		fprintf(stderr, "Usage: %s INFILE OUTFILE\n", argv[0]);
		return 2;
	}

	in_filename = argv[1];
	out_filename = argv[2];

	/* Open input file and output file.  */
	in_fd = open(in_filename, O_RDONLY);
	if (in_fd < 0)
		error(1, errno, "Failed to open \"%s\"", in_filename);
	out_fd = open(out_filename, O_WRONLY | O_TRUNC | O_CREAT, 0644);
	if (out_fd < 0)
		error(1, errno, "Failed to open \"%s\"", out_filename);

	/* Get compression type and chunk size.  */
	if (read(in_fd, &ctype, sizeof(uint32_t)) != sizeof(uint32_t) ||
	    read(in_fd, &chunk_size, sizeof(uint32_t)) != sizeof(uint32_t))
		error(1, errno, "Error reading from \"%s\"", in_filename);

	/* Create a decompressor for the compression type and chunk size with
	 * the default parameters.  */
	ret = wimlib_create_decompressor(ctype, chunk_size, &decompressor);
	if (ret != 0)
		error(1, 0, "Failed to create decompressor: %s",
		      wimlib_get_error_string(ret));

	/* Decompress and write the data.  */
	do_decompress(in_fd, in_filename,
		      out_fd, out_filename,
		      chunk_size, decompressor);

	/* Cleanup and return.  */
	if (close(out_fd))
		error(1, errno, "Error closing \"%s\"", out_filename);
	wimlib_free_decompressor(decompressor);
	return 0;
}