Change tryopen to allow opening multiple files during one run. Return number of errors at end. Adapt test cases.
diff --git a/regress/open_cons_extrabytes.test b/regress/open_cons_extrabytes.test index 8fdf2cc..1a74f67 100644 --- a/regress/open_cons_extrabytes.test +++ b/regress/open_cons_extrabytes.test
@@ -4,3 +4,4 @@ args -c testextrabytes.zip return 1 stdout opening `testextrabytes.zip' returned error 21 +stderr 1 errors
diff --git a/regress/open_new_but_exists.test b/regress/open_new_but_exists.test index 9fb0460..be3c9d1 100644 --- a/regress/open_new_but_exists.test +++ b/regress/open_new_but_exists.test
@@ -4,3 +4,4 @@ return 1 file test.zip test.zip test.zip stdout opening `test.zip' returned error 10 +stderr 1 errors
diff --git a/regress/open_nonarchive.test b/regress/open_nonarchive.test index 979a26e..c2a9fd5 100644 --- a/regress/open_nonarchive.test +++ b/regress/open_nonarchive.test
@@ -4,3 +4,4 @@ args Makefile.am return 1 stdout opening `Makefile.am' returned error 19 +stderr 1 errors
diff --git a/regress/open_nosuchfile.test b/regress/open_nosuchfile.test index bd70a74..414cd5c 100644 --- a/regress/open_nosuchfile.test +++ b/regress/open_nosuchfile.test
@@ -3,3 +3,4 @@ args nosuchfile return 1 stdout opening `nosuchfile' returned error 11/2 +stderr 1 errors
diff --git a/regress/tryopen.c b/regress/tryopen.c index cab1460..6842bfa 100644 --- a/regress/tryopen.c +++ b/regress/tryopen.c
@@ -42,8 +42,6 @@ #include "zip.h" -const char *prg; - const char *usage = "usage: %s [-cent] file\n"; @@ -55,9 +53,9 @@ struct zip *z; int c, flags, ze; zip_uint64_t count; + int error; flags = 0; - prg = argv[0]; while ((c=getopt(argc, argv, "cent")) != -1) { switch (c) { @@ -75,28 +73,32 @@ break; default: - fprintf(stderr, usage, prg); + fprintf(stderr, usage, argv[0]); return 1; } } - if (argc != optind+1) { - fprintf(stderr, usage, prg); - return 1; + + error = 0; + for (; optind < argc; optind++) { + fname = argv[optind]; + errno = 0; + + if ((z=zip_open(fname, flags, &ze)) != NULL) { + count = zip_get_num_entries(z, 0); + printf("opening `%s' succeeded, %lld entries\n", fname, count); + zip_close(z); + continue; + } + + printf("opening `%s' returned error %d", fname, ze); + if (zip_error_get_sys_type(ze) == ZIP_ET_SYS) + printf("/%d", errno); + printf("\n"); + error++; } - fname = argv[optind]; - errno = 0; + if (error > 0) + fprintf(stderr, "%d errors\n", error); - if ((z=zip_open(fname, flags, &ze)) != NULL) { - count = zip_get_num_entries(z, 0); - printf("opening `%s' succeeded, %lld entries\n", fname, count); - zip_close(z); - return 0; - } - - printf("opening `%s' returned error %d", fname, ze); - if (zip_error_get_sys_type(ze) == ZIP_ET_SYS) - printf("/%d", errno); - printf("\n"); - return 1; + return error ? 1 : 0; }