From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/2] lib: safe_file_ops: Add SAFE_FILE_READ_STR()
Date: Thu, 9 Apr 2026 15:35:28 +0200 [thread overview]
Message-ID: <aderIKSVgzrb_hFR@yuki.lan> (raw)
In-Reply-To: <20260409103041.8253-2-chrubis@suse.cz>
Hi!
> diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c
> index 8314c4b1b..2d163c0af 100644
> --- a/lib/safe_file_ops.c
> +++ b/lib/safe_file_ops.c
> @@ -160,6 +160,30 @@ void safe_file_scanf(const char *file, const int lineno,
> }
> }
>
> +void safe_file_read_str(const char *file, const int lineno,
> + const char *path, char *buf, size_t buf_size)
> +{
> + FILE *f;
> +
> + f = fopen(path, "r");
> + if (!f) {
> + tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
> + "Failed to open FILE '%s' for reading", path);
We need a return; here in an unlikely case that someone would call this
from a test cleanup() callback.
> + }
> +
> + if (!fgets(buf, buf_size, f))
> + buf[0] = 0;
> +
> + size_t len = strlen(buf);
> +
> + if (len && buf[len-1] == '\n')
> + buf[len-1] = 0;
> +
> + if (fclose(f)) {
> + tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
> + "Failed to close FILE '%s'", path);
> + }
> +}
>
> /*
> * Try to parse each line from file specified by 'path' according
> --
> 2.52.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-04-09 13:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 10:30 [LTP] [PATCH 0/2] Fix proc parsing in newuname01 Cyril Hrubis
2026-04-09 10:30 ` [LTP] [PATCH 1/2] lib: safe_file_ops: Add SAFE_FILE_READ_STR() Cyril Hrubis
2026-04-09 13:35 ` Cyril Hrubis [this message]
2026-04-09 10:30 ` [LTP] [PATCH 2/2] syscalls: newuname01: Fix fail on empty domainname Cyril Hrubis
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=aderIKSVgzrb_hFR@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/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