mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Danish Khateeb <danishkhateeb03@gmail.com>
Cc: Willy Tarreau <w@1wt.eu>, Shuah Khan <shuah@kernel.org>,
	 linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] selftests/nolibc: test fopen() errors and update modes
Date: Thu, 29 Oct 2026 18:47:20 +0100	[thread overview]
Message-ID: <e4336d00-2ce7-432f-bac1-0a847fd4957f@t-8ch.de> (raw)
In-Reply-To: <20261028200743.154151-4-danishkhateeb03@gmail.com>

On 2026-10-28 15:07:43-0500, Danish Khateeb wrote:
> Check that fopen() of a missing file fails with ENOENT, and that a
> stream opened in "rb+" or "wb+" mode can be both read and written.
> 
> Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
> ---
>  tools/testing/selftests/nolibc/nolibc-test.c | 24 ++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index f3d0d27cdbe1..be501b5298d7 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -1035,6 +1035,27 @@ int test_file_stream_wsr(void)
>  	return 0;
>  }
>  
> +/* checks that a stream opened with <mode> is readable and writable */
> +int test_fopen_rw(const char *mode)
> +{
> +	FILE *f;
> +	char c;
> +	int r;
> +
> +	f = fopen("/dev/null", mode);
> +	if (!f)
> +		return -1;
> +
> +	/* reading /dev/null hits end-of-file, so a write may follow */
> +	errno = 0;
> +	r = fread(&c, 1, 1, f) != 0 || errno || fwrite("x", 1, 1, f) != 1;

That's too funky.

I have a series for fcntl() prepared, with which the test could use
fcntl(F_GETFL). It would be much easier to also test other flag combinations:

test_fopen_flags("rb+", O_RDWR);
test_fopen_flags("r", O_RDONLY);
...

> +
> +	if (fclose(f) == EOF)
> +		return -1;
> +
> +	return r ? -1 : 0;
> +}
> +

(...)

      reply	other threads:[~2026-10-29 17:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 20:07 [PATCH 0/3] tools/nolibc: fix fopen() errno and "rb+" modes Danish Khateeb
2026-10-28 20:07 ` [PATCH 1/3] tools/nolibc: fix fopen() errno when open() fails Danish Khateeb
2026-10-29 17:38   ` Thomas Weißschuh
2026-10-28 20:07 ` [PATCH 2/3] tools/nolibc: fix fopen() with the "rb+", "wb+" and "ab+" modes Danish Khateeb
2026-10-29 17:41   ` Thomas Weißschuh
2026-10-28 20:07 ` [PATCH 3/3] selftests/nolibc: test fopen() errors and update modes Danish Khateeb
2026-10-29 17:47   ` Thomas Weißschuh [this message]

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=e4336d00-2ce7-432f-bac1-0a847fd4957f@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=danishkhateeb03@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=w@1wt.eu \
    /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

all inboxes | Powered by JetHome®