ping6: do not play dirty tricks with argv

function                                             old     new   delta
common_ping_main                                       -     368    +368
ping6_main                                            30      14     -16
ping_main                                            370      11    -359
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 368/-375)           Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-11-20 18:12:12 +01:00
parent 8684cbb5cc
commit ad7d94bdc7

View File

@ -173,13 +173,14 @@ static void ping6(len_and_sockaddr *lsa)
}
#endif
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping_main(int argc UNUSED_PARAM, char **argv)
#if !ENABLE_PING6
# define common_ping_main(af, argv) common_ping_main(argv)
#endif
static int common_ping_main(sa_family_t af, char **argv)
{
len_and_sockaddr *lsa;
#if ENABLE_PING6
sa_family_t af = AF_UNSPEC;
#if ENABLE_PING6
while ((++argv)[0] && argv[0][0] == '-') {
if (argv[0][1] == '4') {
af = AF_INET;
@ -716,12 +717,10 @@ static void ping(len_and_sockaddr *lsa)
ping4(lsa);
}
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping_main(int argc UNUSED_PARAM, char **argv)
static int common_ping_main(int opt, char **argv)
{
len_and_sockaddr *lsa;
char *str_s;
int opt;
INIT_G();
@ -765,13 +764,25 @@ int ping_main(int argc UNUSED_PARAM, char **argv)
#endif /* FEATURE_FANCY_PING */
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping_main(int argc UNUSED_PARAM, char **argv)
{
#if !ENABLE_FEATURE_FANCY_PING
return common_ping_main(AF_UNSPEC, argv);
#else
return common_ping_main(0, argv);
#endif
}
#if ENABLE_PING6
int ping6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping6_main(int argc UNUSED_PARAM, char **argv)
{
argv[0] = (char*)"-6";
return ping_main(0 /* argc+1 - but it's unused anyway */,
argv - 1);
# if !ENABLE_FEATURE_FANCY_PING
return common_ping_main(AF_INET6, argv);
# else
return common_ping_main(OPT_IPV6, argv);
# endif
}
#endif