[RFC/PATCH v2 3/5] libbb: add ends_with() function
Xabier Oneca -- xOneca
xoneca at gmail.com
Fri Aug 21 20:38:04 UTC 2015
2015-08-21 22:34 GMT+02:00 Xabier Oneca -- xOneca <xoneca at gmail.com>:
> Hello Walter,
>
> 2015-08-21 18:26 GMT+02:00 walter harms <wharms at bfs.de>:
>>
>> maybe its a bit late but ...
>>
>> the function name is a bit unfortunate whats about has_suffix() ?
>>
>> you can improve readability by returning strcmp directly and calculating
>> the len immediately.
>>
>> int has_suffix(const char *str, const char *key)
>> {
>> size_t len = strlen(str)-strlen(key);
>>
>> if (len < 0 )
>> return -1;
>>
>> return strcmp(str + len, key);
>> }
>>
>> re,
>> wh
>
> strcmp returns 0 when they match. I think it makes more sense if
> has_suffix returns 1 if match, 0 otherwise:
>
> return !strcmp(str + str_len - key_len, key);
Should have been:
return !strcmp(str + len, key);
Sorry, I copied Bartosz's strcmp line, but you get it.. ;)
Cheers,
Xabier Oneca_,,_
More information about the busybox
mailing list