From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/4] lib/tst_tmpdir: Normalize user defined TMPDIR
Date: Fri, 23 Feb 2024 16:39:32 +0100 [thread overview]
Message-ID: <Zdi8NN-jwhz-eAxP@yuki> (raw)
In-Reply-To: <20240207160628.125908-2-pvorel@suse.cz>
Hi!
> + if (env_tmpdir[strlen(env_tmpdir)-1] == '/') {
> + env_tmpdir[strlen(env_tmpdir)-1] = '\0';
> + fixed = 1;
> + }
> +
> + while ((p = strstr(env_tmpdir, "//")) != NULL) {
> + memmove(p, p + 1, strlen(env_tmpdir) - (p - env_tmpdir));
> + fixed = 1;
> + }
> +
> + if (fixed) {
> + tst_resm(TINFO, "WARNING: Remove double or trailing slashes from TMPDIR,"
> + " please fix your setup to: TMPDIR='%s'",
> + env_tmpdir);
> + }
> +
This whole thing can be just a single loop (beware untested):
size_t s = 0, d = 0;
char prev_c = 0;
for (;;) {
switch (env_tmpdir[s]) {
case '/':
if (prev_c != '/')
d++;
s++;
break;
case '\0':
if (d && prev_c == '/')
env_tmpdir[d-1] = '\0';
break;
break;
default:
env_tmpdir[d++] = env_tmpdir[s++];
}
}
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-02-23 15:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 16:06 [LTP] [PATCH 0/4] Remove double or trailing slashes in TMPDIR in C API Petr Vorel
2024-02-07 16:06 ` [LTP] [PATCH 1/4] lib/tst_tmpdir: Normalize user defined TMPDIR Petr Vorel
2024-02-07 16:17 ` Petr Vorel
2024-02-23 15:39 ` Cyril Hrubis [this message]
2024-03-21 7:14 ` Petr Vorel
2024-02-23 15:41 ` Cyril Hrubis
2024-02-07 16:06 ` [LTP] [PATCH 2/4] lib: Add test for tst_tmpdir Petr Vorel
2024-02-07 16:18 ` Petr Vorel
2024-02-07 16:06 ` [LTP] [PATCH 3/4] tst_test.sh: Print warning if slashes in $TMPDIR Petr Vorel
2024-02-07 16:06 ` [LTP] [PATCH 4/4] lib: Improve doc related to $TMPDIR default value Petr Vorel
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=Zdi8NN-jwhz-eAxP@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.