diff options
-rw-r--r-- | libuniso.c | 9 | ||||
-rw-r--r-- | uniso.c | 45 | ||||
-rw-r--r-- | uniso.h | 4 |
3 files changed, 51 insertions, 7 deletions
@@ -1,4 +1,4 @@ -/* uniso.c - Unpack ISO9660 File System from a stream +/* libuniso.c - Unpack ISO9660 File System from a stream * * Copyright (C) 2011 Timo Teräs <timo.teras@iki.fi> * All rights reserved. @@ -14,7 +14,6 @@ /* * TODO: * - fix unaligned 16-bit accesses from iso headers (ARM / MIPS) - * - help, options, verbose logs */ /* needed for SPLICE_F_MOVE */ @@ -32,6 +31,8 @@ #include <endian.h> #include <sys/stat.h> +#include "uniso.h" + /**/ #ifndef container_of @@ -214,7 +215,7 @@ struct uniso_context { unsigned char *tmpbuf; size_t expected_size; void (*update_progress)(size_t completed, size_t expected_size, - char *filename, void *user_data); + const char *filename, void *user_data); void *user_data; char *current_file; }; @@ -592,7 +593,7 @@ static int uniso_read_volume_descriptor(struct uniso_context *ctx, return queue_dirent(ctx, root_dir, "."); } -int uniso(int fd, void (*progress_callback)(size_t, size_t, char*, void *), +int uniso(int fd, void (*progress_callback)(size_t, size_t, const char*, void *), void *user_data) { struct uniso_context context, *ctx = &context; @@ -1,7 +1,50 @@ +/* uniso.c - Unpack ISO9660 File System from a stream + * + * Copyright (C) 2011 Natanael Copa <ncopa@alpinelinux.org> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. See http://www.gnu.org/ for details. + */ + +#include <limits.h> +#include <stdio.h> +#include <string.h> #include <unistd.h> #include <uniso.h> +struct progress_context { + const char *filename; +}; + +static void update_progress_cb(size_t current, size_t total, const char *filename, + void *userdata) +{ + struct progress_context *ctx = (struct progress_context *)userdata; + double percent; + + if (ctx->filename == filename) + return; + + percent = (double)current * 100 / (double)total; + printf("(%5.1f%%) %s\n", percent, filename?filename:""); + ctx->filename = filename; +} + int main(int argc, char *argv[]) { - return uniso(STDIN_FILENO, NULL, NULL); + int opt; + void (*callback)(size_t, size_t, const char*, void*) = NULL; + struct progress_context ctx = { NULL }; + + while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': + callback = &update_progress_cb; + break; + } + } + + return uniso(STDIN_FILENO, callback, &ctx); } @@ -1,7 +1,7 @@ #ifndef UNISO_H #define UNISO_H -int uniso(int fd, void (*progress_callback)(size_t, size_t, char*, void *), - void *user_data); +int uniso(int fd, void (*progress_callback)(size_t current, size_t total, + const char *filename, void *user_data), void *user_data); #endif |