[Info-vax] ChatGPT solved it for me, again...

Arne Vajhøj arne at vajhoej.dk
Mon Feb 20 09:00:21 EST 2023


On 2/20/2023 8:49 AM, bill wrote:
> On 2/20/2023 5:09 AM, Johnny Billquist wrote:
>> On 2023-02-17 15:16, 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 ?
>>>
>>> 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.
>>
>> Quoting the man-page I have locally:
>>
>>       The strcspn() function spans the initial part of the 
>> null-terminated
>>       string s as long as the characters from s do not occur in the null-
>>       terminated string charset (it spans the complement of charset). 
>> In other
>>       words, it computes the string array index of the first character 
>> of s
>>       which is also in charset, else the index of the first null 
>> character.
> 
> Is yours from Linux?  Seems the Linux and BSD man pages are quite
> different.  Have to wonder if this is a documentation problem or
> if Linux has a broken implementation of strcspn().

Strictly speaking Linux does not have strcspn - the
C library has.

But glibc strcspn works exactly as it should.

https://github.com/zerovm/glibc/blob/master/string/strcspn.c

Actually I think the code is more readable than
the BSD implementation:

https://android.googlesource.com/platform/bionic/+/ics-mr0/libc/string/strcspn.c

YMMV

Disclaimer: neither of the links are master for glibc or OpenBSD
source code, but I assume the comments about origin are true.

Arne




More information about the Info-vax mailing list