From: Tim Kientzle Date: Thu, 10 Sep 2009 04:34:41 +0000 (-0400) Subject: Make the owner_parse() test quiet by having the function X-Git-Tag: v2.8.0~361 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=805ea8e190fbc27f24b82856c970a33ad2c3d300;p=thirdparty%2Flibarchive.git Make the owner_parse() test quiet by having the function return an error string instead of emitting it. SVN-Revision: 1447 --- diff --git a/cpio/cpio.c b/cpio/cpio.c index 10448324b..f3fc29adf 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -123,6 +123,7 @@ main(int argc, char *argv[]) static char buff[16384]; struct cpio _cpio; /* Allocated on stack. */ struct cpio *cpio; + const char *errmsg; int uid, gid; int opt; @@ -268,8 +269,11 @@ main(int argc, char *argv[]) cpio->quiet = 1; break; case 'R': /* GNU cpio, also --owner */ - if (owner_parse(cpio->optarg, &uid, &gid)) + errmsg = owner_parse(cpio->optarg, &uid, &gid); + if (errmsg) { + lafe_warnc(-1, "%s", errmsg); usage(); + } if (uid != -1) cpio->uid_override = uid; if (gid != -1) diff --git a/cpio/cpio.h b/cpio/cpio.h index ddea31dc6..3eed83494 100644 --- a/cpio/cpio.h +++ b/cpio/cpio.h @@ -91,7 +91,7 @@ struct cpio { size_t buff_size; }; -int owner_parse(const char *, int *, int *); +const char *owner_parse(const char *, int *, int *); /* Fake short equivalents for long options that otherwise lack them. */ diff --git a/cpio/test/test_owner_parse.c b/cpio/test/test_owner_parse.c index e63ba8949..9875e91e4 100644 --- a/cpio/test/test_owner_parse.c +++ b/cpio/test/test_owner_parse.c @@ -65,45 +65,45 @@ DEFINE_TEST(test_owner_parse) #else int uid, gid; - assertEqualInt(0, owner_parse(ROOT, &uid, &gid)); + assert(NULL == owner_parse(ROOT, &uid, &gid)); assert(int_in_list(uid, root_uids, sizeof(root_uids)/sizeof(root_uids[0]))); assertEqualInt(-1, gid); - assertEqualInt(0, owner_parse(ROOT ":", &uid, &gid)); + assert(NULL == owner_parse(ROOT ":", &uid, &gid)); assert(int_in_list(uid, root_uids, sizeof(root_uids)/sizeof(root_uids[0]))); assert(int_in_list(gid, root_gids, sizeof(root_gids)/sizeof(root_gids[0]))); - assertEqualInt(0, owner_parse(ROOT ".", &uid, &gid)); + assert(NULL == owner_parse(ROOT ".", &uid, &gid)); assert(int_in_list(uid, root_uids, sizeof(root_uids)/sizeof(root_uids[0]))); assert(int_in_list(gid, root_gids, sizeof(root_gids)/sizeof(root_gids[0]))); - assertEqualInt(0, owner_parse("111", &uid, &gid)); + assert(NULL == owner_parse("111", &uid, &gid)); assertEqualInt(111, uid); assertEqualInt(-1, gid); - assertEqualInt(0, owner_parse("112:", &uid, &gid)); + assert(NULL == owner_parse("112:", &uid, &gid)); assertEqualInt(112, uid); /* Can't assert gid, since we don't know gid for user #112. */ - assertEqualInt(0, owner_parse("113.", &uid, &gid)); + assert(NULL == owner_parse("113.", &uid, &gid)); assertEqualInt(113, uid); /* Can't assert gid, since we don't know gid for user #113. */ - assertEqualInt(0, owner_parse(":114", &uid, &gid)); + assert(NULL == owner_parse(":114", &uid, &gid)); assertEqualInt(-1, uid); assertEqualInt(114, gid); - assertEqualInt(0, owner_parse(".115", &uid, &gid)); + assert(NULL == owner_parse(".115", &uid, &gid)); assertEqualInt(-1, uid); assertEqualInt(115, gid); - assertEqualInt(0, owner_parse("116:117", &uid, &gid)); + assert(NULL == owner_parse("116:117", &uid, &gid)); assertEqualInt(116, uid); assertEqualInt(117, gid); @@ -113,19 +113,9 @@ DEFINE_TEST(test_owner_parse) * users. */ - /* - * TODO: Rework owner_parse to either return a char * pointing - * to an error message or accept a function pointer to an - * error-reporting routine so that the following tests don't - * generate any output. - * - * Alternatively, redirect stderr temporarily to suppress the output. - */ - - lafe_progname = "Ignore this message"; - assertEqualInt(1, owner_parse(":nonexistentgroup", &uid, &gid)); - assertEqualInt(1, owner_parse(ROOT ":nonexistentgroup", &uid, &gid)); - assertEqualInt(1, + assert(NULL != owner_parse(":nonexistentgroup", &uid, &gid)); + assert(NULL != owner_parse(ROOT ":nonexistentgroup", &uid, &gid)); + assert(NULL != owner_parse("nonexistentuser:nonexistentgroup", &uid, &gid)); #endif }