summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-11-24 10:22:18 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2011-11-24 10:22:18 +0100
commitd0fc345d05ecbbac8aeb5c408aad08c243b4c011 (patch)
tree0b520023a13221b2a38e88130a521f24fc91bc96
parentd85aa8295a3169f21033ff5fd8f365d9eeec7e13 (diff)
downloadlibuniso-d0fc345d05ecbbac8aeb5c408aad08c243b4c011.tar.bz2
libuniso-d0fc345d05ecbbac8aeb5c408aad08c243b4c011.tar.xz
uniso: use progress callback
-rw-r--r--libuniso.c9
-rw-r--r--uniso.c45
-rw-r--r--uniso.h4
3 files changed, 51 insertions, 7 deletions
diff --git a/libuniso.c b/libuniso.c
index 2f927da..7c2686e 100644
--- a/libuniso.c
+++ b/libuniso.c
@@ -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;
diff --git a/uniso.c b/uniso.c
index f8d4427..f84efcd 100644
--- a/uniso.c
+++ b/uniso.c
@@ -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);
}
diff --git a/uniso.h b/uniso.h
index a30bfa5..a6138b9 100644
--- a/uniso.h
+++ b/uniso.h
@@ -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