grokking libgsf
- From: Allin Cottrell <cottrell wfu edu>
- To: gnumeric-list gnome org
- Subject: grokking libgsf
- Date: Fri, 1 May 2009 20:07:17 -0400 (EDT)
I'm trying some tests with the hope of switching to libgsf in
place of low-level fiddling with pkzip structures in reading and
writing zipfiles.  So far I'm only partially successful and I'd
much appreciate any guidance.
I have the following C source (with correct headers included, and
followed by a trivial main() function).  The idea is to print the
structure of a zipfile and then "unzip" it to a specified
location.
The printing part, "print_kids", is working fine, but the
"unzipping" part is giving me an empty directory "foo".  I have
removed error-checking from the following for brevity, but no
errors were triggered when running the full version of the code.
static void print_kids (GsfInfile *infile, int level)
{
    int nkids = gsf_infile_num_children(infile);
    const char *cname;
    GsfInput *child;
    gsf_off_t sz;
    int i, j;
    for (i=0; i<nkids; i++) {
        child = gsf_infile_child_by_index(infile, i);
        cname = gsf_input_name(child);
        sz = gsf_input_size(child);
        for (j=0; j<level; j++) {
            putchar(' ');
        }
        printf("child %d: '%s' (%d bytes)\n", i, cname, (int) sz);
        print_kids(GSF_INFILE(child), ++level);
        g_object_unref(child);
    }
}
static int gsf_test_zipread (const char *fname)
{
    GsfInput *src, *uncomp;
    GsfInfile *zipfile;
    GsfOutfile *outfile;
    gsf_init();
    src = gsf_input_stdio_new(fname, NULL);
    zipfile = gsf_infile_zip_new(src, NULL);
    g_object_unref(src);
    print_kids(zipfile, 0);
    uncomp = gsf_input_uncompress(GSF_INPUT(zipfile));
    g_object_unref(zipfile);
    outfile = gsf_outfile_stdio_new("foo", &err);
    gsf_input_seek(uncomp, 0, G_SEEK_SET);
    gsf_output_seek(GSF_OUTPUT(outfile), 0, G_SEEK_SET);
    if (!gsf_input_copy(uncomp, GSF_OUTPUT(outfile))) {
        fprintf(stderr, "gsf_input_copy failed\n");
    }
    gsf_output_close(GSF_OUTPUT(outfile));
    gsf_shutdown();
    return 0;
}
Please, what am I doing wrong in gsf_test_zipread?
-- 
Allin Cottrell
Department of Economics
Wake Forest University
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]