X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=tests%2Flibpspp%2Fzip-test.c;h=e132cb93da5299983a35438bf4d7da00b4d39949;hb=b617e090556354840dbfd5fcac89ae9a7e090c9b;hp=7a2fcb10c47db74258d7dc3996809a10435f8b13;hpb=551202adbc334f9c33f8290a4e407b422651bbd5;p=pspp diff --git a/tests/libpspp/zip-test.c b/tests/libpspp/zip-test.c index 7a2fcb10c4..e132cb93da 100644 --- a/tests/libpspp/zip-test.c +++ b/tests/libpspp/zip-test.c @@ -29,7 +29,7 @@ #include #include -#include "xalloc.h" +#include /* Exit with a failure code. (Place a breakpoint on this function while debugging.) */ @@ -67,28 +67,45 @@ main (int argc, char **argv) int i; struct string str; struct zip_reader *zr = zip_reader_create (argv[2], &str); + if ( NULL == zr) + { + fprintf (stderr, "Could not create zip reader: %s\n", ds_cstr (&str)); + check_die (); + } for (i = 3; i < argc; ++i) { int x = 0; - struct zip_member *zm = zip_member_open (zr, argv[i]); + struct zip_member *zm ; FILE *fp = fopen (argv[i], "w"); + if ( NULL == fp) + { + int e = errno; + fprintf (stderr, "Could not create file %s: %s\n", argv[i], strerror(e)); + check_die (); + } + zm = zip_member_open (zr, argv[i]); + if ( NULL == zm) + { + fprintf (stderr, "Could not open zip member %s from archive: %s\n", + argv[i], ds_cstr (&str)); + check_die (); + } while ((x = zip_member_read (zm, buf, BUFSIZE)) > 0) { fwrite (buf, x, 1, fp); } + zip_member_finish (zm); fclose (fp); if ( x < 0) { - fprintf (stderr, "Unzip failed: %s", ds_cstr (&str)); + fprintf (stderr, "Unzip failed: %s\n", ds_cstr (&str)); check_die (); } - - zip_member_unref (zm); } zip_reader_destroy (zr); } - else + else exit (1); return 0;