Esempio n. 1
0
File: tar.c Progetto: calccrypto/tar
int tar_extract(const int fd, struct tar_t * archive, const size_t filecount, const char * files[], const char verbosity){
    int ret = 0;

    // extract entries with given names
    if (filecount){
        if (!files){
            V_PRINT(stderr, "Error: Received non-zero file count but got NULL file list\n");
            return -1;
        }

        while (archive){
            for(size_t i = 0; i < filecount; i++){
                if (!strncmp(archive -> name, files[i], MAX(strlen(archive -> name), strlen(files[i])))){
                    if (lseek(fd, archive -> begin, SEEK_SET) == (off_t) (-1)){
                        RC_ERROR(stderr, "Error: Unable to seek file: %s\n", strerror(rc));
                    }

                    if (extract_entry(fd, archive, verbosity) < 0){
                        ret = -1;
                    }
                    break;
                }
            }
            archive = archive -> next;
        }
    }
    // extract all
    else{
        // move offset to beginning
        if (lseek(fd, 0, SEEK_SET) == (off_t) (-1)){
            RC_ERROR(stderr, "Error: Unable to seek file: %s\n", strerror(rc));
        }

        // extract each entry
        while (archive){
            if (extract_entry(fd, archive, verbosity) < 0){
                ret = -1;
            }
            archive = archive -> next;
        }
    }

    return ret;
}
Esempio n. 2
0
static bool extract(chm_file* h, const char* base_path) {
    /* extract as many entries as possible */
    for (int i = 0; i < h->n_entries; i++) {
        if (!extract_entry(h, h->entries[i], base_path)) {
            return false;
        }
    }
    if (h->parse_entries_failed) {
        return false;
    }
    return true;
}
Esempio n. 3
0
int list_tar_entries (char* tarname, int verbose) {
  if (file_exists(tarname) == -1) {
    printf("tarino-native: Archive \'%s\' does not exist.\n", tarname);
    return -1;
  }

  int offsets[10000];
  get_entry_offsets(tarname, offsets);
  int entries = get_entries(offsets);
  if (verbose == 1) {
    printf("tarino-native: Listing %d entries from archive.\n\n", entries);
  }
  int i;
  for (i = 0; i < entries; i++) {
    extract_entry(tarname, offsets[i], 0, verbose, 0);
  }
  return 0;
}
Esempio n. 4
0
int get_starting_point ( Constraint_list *CL)
{
    int a;


    int l;





    int **seq;
    int start;
    int *entry=NULL;

    l=strlen ( (CL->S)->seq[0]);

    seq=declare_int ( l, 2);



    while (entry=extract_entry (CL))
    {
        seq[entry[R1]][1]=entry[R1];
        seq[entry[R2]][1]=entry[R2];
        if ((CL->moca) && (CL->moca)->forbiden_residues && ((CL->moca)->forbiden_residues[0][entry[R1]]==UNDEFINED||(CL->moca)->forbiden_residues[0][entry[R2]]==UNDEFINED ))continue;
        else
        {
            seq[entry[R1]][0]+=entry[MISC];
            seq[entry[R2]][0]+=entry[MISC];
        }
    }

    sort_int_inv ( seq, 2, 0, 0, l-1);
    fprintf ( stderr, "\nStart=%d %d", seq[0][1], seq[0][0]);
    start=seq[0][1];


    free_int ( seq, -1);
    return start;


}
Esempio n. 5
0
/* Extract all files in an archive to the filesystem under the path given by
 * dest. Returns 0 on success or <0 on error.
 */
static int extract_all(struct archive *a, const char *dest, int flags)
{
    struct archive *disk;
    struct archive_entry *entry;
    int r;
    int eof;

    disk = open_disk(flags);
    if (!disk)
        return -1;

    while (1) {
        entry = read_header(a, &eof);
        if (eof)
            break;
        if (!entry) {
            r = -1;
            goto err_cleanup;
        }

        r = transform_all_paths(entry, dest);
        if (r == 1)
            continue;
        if (r < 0) {
            opkg_msg(ERROR, "Failed to transform path.\n");
            goto err_cleanup;
        }

        print_paths(entry);

        r = extract_entry(a, entry, disk);
        if (r < 0)
            goto err_cleanup;
    }

    r = ARCHIVE_OK;
 err_cleanup:
    archive_write_free(disk);
    return (r == ARCHIVE_OK) ? 0 : -1;
}
Esempio n. 6
0
int zippy::main( int argc, char*argv[] ) {
    /*
     * quick example of how to use the library:
     * please: don't program this way!!
     */

    std::string entry    = "";
    std::string zip_file = "";
    bool extract_all     = false;
    bool print_entries   = false;

    // get arguments
    if( argc == 1 ) {
        print_usage();
        return 0;
    }

    for( int narg=2; narg<=argc; narg++ ) {
        if( std::string( argv[narg-1] ).length() > 1 && !std::string( argv[narg-1] ).substr(0,1).compare( "-" ) ) {
            for( int nsarg=1; nsarg<std::string( argv[narg-1] ).length(); nsarg++ ) {
                if( !std::string( argv[narg-1] ).substr(nsarg,nsarg).compare( "a" ) ) {
                    if( zip.is_open() || print_entries ) {
                        print_usage();
                        return 1;
                    }
                    extract_all = true;
                } else if( !std::string( argv[narg-1] ).substr(nsarg,nsarg).compare( "t" ) ) {
                    if( zip.is_open() || extract_all ) {
                        print_usage();
                        return 1;
                    }
                    print_entries = true;
                } else {
                    std::cerr << "invalid argument: ";
                    std::cerr << std::string( argv[narg-1] ).substr(nsarg,nsarg) << std::endl;
                    return 1;
                }
            }
        } else if( narg+1 == argc ) {
            if( print_entries || extract_all ) {
                print_usage();
                return 1;
            }
            zip_file = argv[narg-1];
        } else if( narg == argc ) {
            if( print_entries || extract_all ) {
                zip_file = argv[narg-1];
            } else {
                entry = argv[narg-1];
            }
        } else {
            std::cerr << "invalid argument: ";
            std::cerr << argv[narg-1] << std::endl;
            return 1;
        }
    }

    // check if the zip was found
    if( !zip.open( zip_file.c_str() ).is_open() ) {
        std::cerr << "error: the zip file wasn't found, it's corrupted or it's not compatible" << std::endl;
        return 1;
    } else {
        // extract entries
        if( print_entries ) {
            if( zip.is_open() ) {
                std::vector<std::string> entries = zip.entries();
                // read entries
                for( int i=0; i<entries.size(); i++ ) {
                    std::cout << entries[i] << std::endl;
                }
            } else {
                std::cout << zip.error() << std::endl;
            }
        } else if( extract_all ) {
            if( zip.is_open() ) {
                std::vector<std::string> entries = zip.entries();
                // read entries
                for( int i=0; i<entries.size(); i++ ) {
                    std::cout << "[zippy::" << entries[i] << "]" << std::endl;
                    extract_entry( entries[i] );
                }
            } else {
                std::cout << zip.error() << std::endl;
            }
        } else if( !entry.empty() ) {
            extract_entry( entry );
        }
    }

    return 0;
}