From: Crystal Wood <crwood@redhat.com>
To: Costa Shulyupin <costa.shul@redhat.com>,
linux-rt-users <linux-rt-users@vger.kernel.org>,
John Kacur <jkacur@redhat.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Tomas Glozar <tglozar@redhat.com>
Subject: Re: [PATCH v1] cyclictest: Generate optstring dynamically from long_options
Date: Mon, 12 Jan 2026 15:13:22 -0600 [thread overview]
Message-ID: <e64e7188a920634fce126fc71ccc09696984f42f.camel@redhat.com> (raw)
In-Reply-To: <20260110113738.2376456-1-costa.shul@redhat.com>
On Sat, 2026-01-10 at 13:37 +0200, Costa Shulyupin wrote:
> diff --git a/src/include/opt.h b/src/include/opt.h
> new file mode 100644
> index 000000000000..4d01917be024
> --- /dev/null
> +++ b/src/include/opt.h
> @@ -0,0 +1,11 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +#pragma once
> +
> +#include <getopt.h>
> +
> +/*
> + * build_optstring - allocate and build optstring from long_options
> + *
> + * Free resulted optstring aftre use.
> + */
"Free resulting optstring after use"
> +char *build_optstring(const struct option *long_opts);
> diff --git a/src/lib/opt.c b/src/lib/opt.c
> new file mode 100644
> index 000000000000..d235788001d9
> --- /dev/null
> +++ b/src/lib/opt.c
> @@ -0,0 +1,29 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +#include <stdlib.h>
> +
> +#include "opt.h"
> +
> +char *build_optstring(const struct option *long_opts)
> +{
> + char *opts = NULL;
> + int n = 0;
> +
> + for (int i = 0; long_opts[i].name; i++) {
> + opts = realloc(opts, n + 4);
I realize this isn't going to be noticeable even if it ends up being a
copy each time, but linear realloc like this makes me twinge and think
of how just about every other language in common use would have a
readily available growable string implementation :-P
> +
> + if (long_opts[i].flag || long_opts[i].val < 32 || long_opts[i].val > 127)
> + continue;
What happens if the OPT enum grows beyond 32 entries? It's already at
16. Maybe start the enum at 0x100, and print an error if val is less
than that but not valid for getopt?
Why is the implementation (slightly) different here versus the rtla
patch? We should probably use an enum in rtla instead of '4', '\1',
etc. as well.
-Crystal
next prev parent reply other threads:[~2026-01-12 21:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-10 11:37 [PATCH v1] cyclictest: Generate optstring dynamically from long_options Costa Shulyupin
2026-01-12 21:13 ` Crystal Wood [this message]
2026-01-13 8:13 ` Sebastian Andrzej Siewior
2026-01-13 10:00 ` Costa Shulyupin
2026-01-13 11:14 ` Sebastian Andrzej Siewior
2026-01-13 23:41 ` Crystal Wood
2026-01-13 23:34 ` Crystal Wood
2026-01-13 12:45 ` Costa Shulyupin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e64e7188a920634fce126fc71ccc09696984f42f.camel@redhat.com \
--to=crwood@redhat.com \
--cc=bigeasy@linutronix.de \
--cc=costa.shul@redhat.com \
--cc=jkacur@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=tglozar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox