[RFC/PATCH v2 3/5] libbb: add ends_with() function
Xabier Oneca -- xOneca
xoneca at gmail.com
Fri Aug 21 20:34:28 UTC 2015
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);
Also, can len be < 0? Isn't size_t unsigned?
Cheers,
Xabier Oneca_,,_
More information about the busybox
mailing list