Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Buffer contents well-defined after fgets() reaches EOF ?
Date: Tue, 18 Feb 2025 20:17:00 -0800
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <86mseiy3er.fsf@linuxsc.com>
References: <20250210124911.00006b31@yahoo.com> <86ldu9zxkb.fsf@linuxsc.com> <20250214165108.00002984@yahoo.com> <864j0vyxj3.fsf@linuxsc.com> <20250215200856.00007131@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 19 Feb 2025 05:17:01 +0100 (CET)
Injection-Info: dont-email.me; posting-host="69e9ac3a61d8883cfaa10bb46c2a312b"; logging-data="2098247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+b9cZ3EPFwGUqRyL1fZnZp65Ics+7xh2c="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:eyZdDRMOZDbAUqrfZDQKN7ngGnY= sha1:6kYqjpXZSFKWzsTXlZARbVn5wa8=
Xref: csiph.com comp.lang.c:390362
Michael S writes:
> On Sat, 15 Feb 2025 08:37:20 -0800
> Tim Rentsch wrote:
[...]
>> Clearly using fgets() is problematic when the input stream might
>> contain null characters. To me it seems obvious that the original
>> implementors expected that fgets() would not be used in such cases,
>> perhaps with the less severe restriction that the presence of
>> embedded nulls could be detected and simply rejected as bad input,
>> much the same as overly long lines or a final line without a
>> terminating newline character.
>
> My impression is that they didn't spend much time thinking.
I have no idea how much time was spent designing the fgets()
interface, nor do I think it's important to know. I understand the
limitations of fgets() and don't mind using it in circumstances
where it provides a net positive value.