diff options
author | bigbiff bigbiff <bigbiff@teamw.in> | 2013-01-09 15:09:08 +0100 |
---|---|---|
committer | bigbiff bigbiff <bigbiff@teamw.in> | 2013-01-09 15:09:08 +0100 |
commit | 9c754053b07a724bdd98d039f34899d6a49115b7 (patch) | |
tree | 464885db361a12d83d60cf152142c765562bb92d /libtar/wrapper.c | |
parent | Add Samsung TouchWiz decryption (diff) | |
download | android_bootable_recovery-9c754053b07a724bdd98d039f34899d6a49115b7.tar android_bootable_recovery-9c754053b07a724bdd98d039f34899d6a49115b7.tar.gz android_bootable_recovery-9c754053b07a724bdd98d039f34899d6a49115b7.tar.bz2 android_bootable_recovery-9c754053b07a724bdd98d039f34899d6a49115b7.tar.lz android_bootable_recovery-9c754053b07a724bdd98d039f34899d6a49115b7.tar.xz android_bootable_recovery-9c754053b07a724bdd98d039f34899d6a49115b7.tar.zst android_bootable_recovery-9c754053b07a724bdd98d039f34899d6a49115b7.zip |
Diffstat (limited to '')
-rw-r--r-- | libtar/wrapper.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/libtar/wrapper.c b/libtar/wrapper.c new file mode 100644 index 000000000..7cd8ed12c --- /dev/null +++ b/libtar/wrapper.c @@ -0,0 +1,155 @@ +/* +** Copyright 1998-2003 University of Illinois Board of Trustees +** Copyright 1998-2003 Mark D. Roth +** All rights reserved. +** +** wrapper.c - libtar high-level wrapper code +** +** Mark D. Roth <roth@uiuc.edu> +** Campus Information Technologies and Educational Services +** University of Illinois at Urbana-Champaign +*/ + +#define DEBUG +#include <internal.h> + +#include <stdio.h> +#include <sys/param.h> +#include <dirent.h> +#include <errno.h> + +#ifdef STDC_HEADERS +# include <string.h> +#endif + +int +tar_extract_glob(TAR *t, char *globname, char *prefix) +{ + char *filename; + char buf[MAXPATHLEN]; + int i; + + while ((i = th_read(t)) == 0) + { + filename = th_get_pathname(t); + if (fnmatch(globname, filename, FNM_PATHNAME | FNM_PERIOD)) + { + if (TH_ISREG(t) && tar_skip_regfile(t)) + return -1; + continue; + } + if (t->options & TAR_VERBOSE) + th_print_long_ls(t); + if (prefix != NULL) + snprintf(buf, sizeof(buf), "%s/%s", prefix, filename); + else + strlcpy(buf, filename, sizeof(buf)); + if (tar_extract_file(t, filename) != 0) + return -1; + } + + return (i == 1 ? 0 : -1); +} + + +int +tar_extract_all(TAR *t, char *prefix) +{ + char *filename; + char buf[MAXPATHLEN]; + int i; + printf("prefix: %s\n", prefix); +#ifdef DEBUG + printf("==> tar_extract_all(TAR *t, \"%s\")\n", + (prefix ? prefix : "(null)")); +#endif + while ((i = th_read(t)) == 0) + { +#ifdef DEBUG + puts(" tar_extract_all(): calling th_get_pathname()"); +#endif + filename = th_get_pathname(t); + if (t->options & TAR_VERBOSE) + th_print_long_ls(t); + if (prefix != NULL) + snprintf(buf, sizeof(buf), "%s/%s", prefix, filename); + else + strlcpy(buf, filename, sizeof(buf)); +#ifdef DEBUG + printf(" tar_extract_all(): calling tar_extract_file(t, " + "\"%s\")\n", buf); +#endif + printf("filename: %s\n", filename); + /* + if (strcmp(filename, "/") == 0) { + printf("skipping /\n"); + continue; + } + */ + if (tar_extract_file(t, buf) != 0) + return -1; + } + return (i == 1 ? 0 : -1); +} + + +int +tar_append_tree(TAR *t, char *realdir, char *savedir) +{ + char realpath[MAXPATHLEN]; + char savepath[MAXPATHLEN]; + struct dirent *dent; + DIR *dp; + struct stat s; + +#ifdef DEBUG + printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n", + t, realdir, (savedir ? savedir : "[NULL]")); +#endif + + if (tar_append_file(t, realdir, savedir) != 0) + return -1; + +#ifdef DEBUG + puts(" tar_append_tree(): done with tar_append_file()..."); +#endif + + dp = opendir(realdir); + if (dp == NULL) + { + if (errno == ENOTDIR) + return 0; + return -1; + } + while ((dent = readdir(dp)) != NULL) + { + if (strcmp(dent->d_name, ".") == 0 || + strcmp(dent->d_name, "..") == 0) + continue; + + snprintf(realpath, MAXPATHLEN, "%s/%s", realdir, + dent->d_name); + if (savedir) + snprintf(savepath, MAXPATHLEN, "%s/%s", savedir, + dent->d_name); + + if (lstat(realpath, &s) != 0) + return -1; + + if (S_ISDIR(s.st_mode)) + { + if (tar_append_tree(t, realpath, + (savedir ? savepath : NULL)) != 0) + return -1; + continue; + } + + if (tar_append_file(t, realpath, + (savedir ? savepath : NULL)) != 0) + return -1; + } + + closedir(dp); + + return 0; +} |