[Info-vax] ChatGPT solved it for me, again...
Arne Vajhøj
arne at vajhoej.dk
Fri Feb 17 13:57:00 EST 2023
On 2/17/2023 1:27 PM, Simon Clubley wrote:
> On 2023-02-17, Arne Vajhøj <arne at vajhoej.dk> wrote:
>> On 2/17/2023 9:16 AM, Simon Clubley wrote:
>>> On 2023-02-17, Arne Vajhøj <arne at vajhoej.dk> wrote:
>>>>
>>>> strcspn will stop when it reach the terminating null byte.
>>>
>>> Are you sure about that ?
>>
>> Yes.
>>
>>> https://linux.die.net/man/3/strcspn
>>>
>>> There's no mention of stopping at a null and no mention of what the
>>> return value is when the byte is not found within the string if it
>>> were to stop at a terminating null.
>>
>> "The strcspn() function returns the number of bytes in the initial
>> segment of s which are not in the string reject."
>>
>> strcspn("abc\n", "\n") will return 3.
>>
>> strcspn("abc", "\n") will also return 3.
>>
>> That is what it says.
>
> Then in that case I was wrong and I withdraw the original comment.
>
> However, that man page is extremely misleading because when a routine
> is setup to report that it didn't find something, it usually tells you
> how it does that in the "RETURN VALUE" section of the documentation.
The man page explains what it is returning.
In both examples above it detect 3 bytes in the start of s that
are not in reject, so it returns 3.
The "didn't find case" is not really a special case for
this function.
Arne
More information about the Info-vax
mailing list