summaryrefslogtreecommitdiffstats
path: root/uniso.c
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 /uniso.c
parentd85aa8295a3169f21033ff5fd8f365d9eeec7e13 (diff)
downloadlibuniso-d0fc345d05ecbbac8aeb5c408aad08c243b4c011.tar.bz2
libuniso-d0fc345d05ecbbac8aeb5c408aad08c243b4c011.tar.xz
uniso: use progress callback
Diffstat (limited to 'uniso.c')
-rw-r--r--uniso.c45
1 files changed, 44 insertions, 1 deletions
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);
}