Re: [PATCH 05/16] lslogins: reject unknown time format arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Dec 14, 2014 at 05:44:01PM +0000, Sami Kerola wrote:
> @@ -1398,8 +1388,18 @@ int main(int argc, char *argv[])
>  			break;
>  		case OPT_TIME_FMT:
>  			{
> +				struct lslogins_timefmt {
> +					const char *name;
> +					const int val;
> +				};
> +				const struct lslogins_timefmt timefmts[] = {

 static const ....

> +					{ "iso", TIME_ISO },
> +					{ "full", TIME_FULL },
> +					{ "short", TIME_SHORT },
> +				};
>  				size_t i;
>  
> +				ctl->time_mode = TIME_INVALID;
>  				for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
>  					if (strcmp(timefmts[i].name, optarg) == 0) {
>  						ctl->time_mode = timefmts[i].val;
> @@ -1407,7 +1407,7 @@ int main(int argc, char *argv[])
>  					}
>  				}
>  				if (ctl->time_mode == TIME_INVALID)
> -					usage(stderr);
> +					errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);

This is not elegant solution, it would be better to move all the code
to small function parse_time_mode() and keep the main() less "crowded".

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux