* [LTP] test specific command line options
@ 2016-07-28 8:12 Han Pingtian
2016-07-28 12:23 ` Jan Stancek
0 siblings, 1 reply; 4+ messages in thread
From: Han Pingtian @ 2016-07-28 8:12 UTC (permalink / raw)
To: ltp
Hi,
From the doc I read:
... The 'arg' is where 'optarg' is stored upon match. If option has no
parameter it's set to non-'NULL' value if option was present.
But looks like if a option was present which has no parameter, the 'arg'
will set to NULL?
Thanks in advance.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [LTP] test specific command line options
2016-07-28 8:12 [LTP] test specific command line options Han Pingtian
@ 2016-07-28 12:23 ` Jan Stancek
2016-08-01 9:23 ` Cyril Hrubis
0 siblings, 1 reply; 4+ messages in thread
From: Jan Stancek @ 2016-07-28 12:23 UTC (permalink / raw)
To: ltp
----- Original Message -----
> From: "Han Pingtian" <hanpt@linux.vnet.ibm.com>
> To: ltp@lists.linux.it
> Sent: Thursday, 28 July, 2016 10:12:49 AM
> Subject: [LTP] test specific command line options
>
> Hi,
>
> From the doc I read:
>
> ... The 'arg' is where 'optarg' is stored upon match. If option has no
> parameter it's set to non-'NULL' value if option was present.
>
> But looks like if a option was present which has no parameter, the 'arg'
> will set to NULL?
You're right, that looks like a BUG. If you don't provide colon,
then "arg" stays NULL, but doc say it should be non-NULL:
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 4f417ea345e7..0b99bedd8d81 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -384,6 +384,7 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
{
unsigned int i;
struct tst_option *toptions = tst_test->options;
+ static char *match = "";
for (i = 0; i < topts_len; i++) {
if (toptions[i].optstr[0] == opt)
@@ -393,7 +394,10 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
if (i >= topts_len)
tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
- *(toptions[i].arg) = optarg;
+ if (optarg)
+ *(toptions[i].arg) = optarg;
+ else
+ *(toptions[i].arg) = match;
}
/* see self_exec.c */
Regards,
Jan
>
> Thanks in advance.
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [LTP] test specific command line options
2016-07-28 12:23 ` Jan Stancek
@ 2016-08-01 9:23 ` Cyril Hrubis
2016-08-01 9:50 ` Jan Stancek
0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2016-08-01 9:23 UTC (permalink / raw)
To: ltp
Hi!
> > From the doc I read:
> >
> > ... The 'arg' is where 'optarg' is stored upon match. If option has no
> > parameter it's set to non-'NULL' value if option was present.
> >
> > But looks like if a option was present which has no parameter, the 'arg'
> > will set to NULL?
>
> You're right, that looks like a BUG. If you don't provide colon,
> then "arg" stays NULL, but doc say it should be non-NULL:
Looks like my mistake.
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 4f417ea345e7..0b99bedd8d81 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -384,6 +384,7 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
> {
> unsigned int i;
> struct tst_option *toptions = tst_test->options;
> + static char *match = "";
>
> for (i = 0; i < topts_len; i++) {
> if (toptions[i].optstr[0] == opt)
> @@ -393,7 +394,10 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
> if (i >= topts_len)
> tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
>
> - *(toptions[i].arg) = optarg;
> + if (optarg)
> + *(toptions[i].arg) = optarg;
> + else
> + *(toptions[i].arg) = match;
I would do something as:
*(toptions[i].arg) = optarg ? optarg : "";
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 4+ messages in thread
* [LTP] test specific command line options
2016-08-01 9:23 ` Cyril Hrubis
@ 2016-08-01 9:50 ` Jan Stancek
0 siblings, 0 replies; 4+ messages in thread
From: Jan Stancek @ 2016-08-01 9:50 UTC (permalink / raw)
To: ltp
----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: "Han Pingtian" <hanpt@linux.vnet.ibm.com>, ltp@lists.linux.it
> Sent: Monday, 1 August, 2016 11:23:56 AM
> Subject: Re: [LTP] test specific command line options
>
> Hi!
> > > From the doc I read:
> > >
> > > ... The 'arg' is where 'optarg' is stored upon match. If option has no
> > > parameter it's set to non-'NULL' value if option was present.
> > >
> > > But looks like if a option was present which has no parameter, the 'arg'
> > > will set to NULL?
> >
> > You're right, that looks like a BUG. If you don't provide colon,
> > then "arg" stays NULL, but doc say it should be non-NULL:
>
> Looks like my mistake.
>
> > diff --git a/lib/tst_test.c b/lib/tst_test.c
> > index 4f417ea345e7..0b99bedd8d81 100644
> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -384,6 +384,7 @@ static void parse_topt(unsigned int topts_len, int opt,
> > char *optarg)
> > {
> > unsigned int i;
> > struct tst_option *toptions = tst_test->options;
> > + static char *match = "";
> >
> > for (i = 0; i < topts_len; i++) {
> > if (toptions[i].optstr[0] == opt)
> > @@ -393,7 +394,10 @@ static void parse_topt(unsigned int topts_len, int
> > opt, char *optarg)
> > if (i >= topts_len)
> > tst_brk(TBROK, "Invalid option '%c' (should not happen)",
> > opt);
> >
> > - *(toptions[i].arg) = optarg;
> > + if (optarg)
> > + *(toptions[i].arg) = optarg;
> > + else
> > + *(toptions[i].arg) = match;
>
> I would do something as:
>
> *(toptions[i].arg) = optarg ? optarg : "";
I pushed your version.
Regards,
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-08-01 9:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-28 8:12 [LTP] test specific command line options Han Pingtian
2016-07-28 12:23 ` Jan Stancek
2016-08-01 9:23 ` Cyril Hrubis
2016-08-01 9:50 ` Jan Stancek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox