It can open multiple files at once.
#include <stdlib.h> #include <stdio.h> #include "untgz.h" void status(struct untgz_state* tgz, gsize total, gsize current) { printf("%d\n", 100*current/total); fflush(stdout); } int main(int ac, char* av[]) { gint i; struct error* err = e_new(); // For each file do: for (i=1;i<ac;i++) { // Open tgz file. struct untgz_state* tgz = untgz_open(av[i], status, err); if (tgz == 0) { e_print(err); e_clean(err); continue; } // While we can successfully get next file's header from the archive... while (untgz_get_header(tgz) == 0) { // ...we will be extracting that file to a disk using its original name... if (untgz_write_file(tgz, 0)) { // ...until something goes wrong. break; } } // And if something went wrong... if (!e_ok(err)) { // ...we will alert user. e_print(err); e_clean(err); } // Close file. untgz_close(tgz); } e_free(err); return 0; }
Data Structures | |
struct | untgz_state |
Untgz state structure. More... | |
Defines | |
#define | UNTGZ_CORRUPT E(0) |
archive is corrupt | |
#define | UNTGZ_BLOCKED E(1) |
untgz is blocked because of corrupt archive | |
#define | UNTGZ_BADIO E(2) |
can't open/write/create/update/whatever file | |
#define | UNTGZ_BADMETA E(3) |
can't set metainformation for extracted file (file was extracted successfully!) | |
Typedefs | |
typedef void(*) | untgz_status_cb (struct untgz_state *s, gsize total, gsize current) |
Untgz status callback. | |
Enumerations | |
enum | untgz_filetype { UNTGZ_NONE = 0, UNTGZ_DIR, UNTGZ_REG, UNTGZ_LNK, UNTGZ_SYM, UNTGZ_BLK, UNTGZ_CHR, UNTGZ_FIFO } |
File type. More... | |
Functions | |
untgz_state * | untgz_open (const gchar *tgzfile, untgz_status_cb scb, struct error *e) |
Open tgz archive. | |
void | untgz_close (struct untgz_state *s) |
Close archive and free untgz_state object. | |
gint | untgz_get_header (struct untgz_state *s) |
Read next file header from the archive. | |
gint | untgz_write_data (struct untgz_state *s, gchar **buf, gsize *len) |
Write data for the current file to the buffer. | |
gint | untgz_write_file (struct untgz_state *s, gchar *altname) |
Write current file to the disk. |