[PATCH libevdev v2 2/5] Add startswith() helper
David Herrmann
dh.herrmann at gmail.com
Tue Oct 29 07:39:08 CET 2013
Hi Ran
On Tue, Oct 29, 2013 at 7:34 AM, Ran Benita <ran234 at gmail.com> wrote:
> On Mon, Oct 28, 2013 at 05:16:44PM +0100, David Herrmann wrote:
>> Simple helper that use strncmp() to test whether a given string
>> starts with a given suffix. While it doesn't reduce code-size by much,
>> it is a lot more readable than the strncmp() usage.
>>
>> Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
>> ---
>> libevdev/libevdev-util.h | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/libevdev/libevdev-util.h b/libevdev/libevdev-util.h
>> index 3a40a61..ad26853 100644
>> --- a/libevdev/libevdev-util.h
>> +++ b/libevdev/libevdev-util.h
>> @@ -24,8 +24,16 @@
>> #define _UTIL_H_
>>
>> #include <config.h>
>> +#include <stdbool.h>
>> +#include <string.h>
>> #include "libevdev-int.h"
>>
>> +static inline bool
>> +startswith(const char *str, size_t len, const char *prefix, size_t plen)
>> +{
>> + return len >= plen && !strncmp(str, prefix, min(len, plen));
>
> Isn't the min() redundant here?
Whoops, I added the "len >= plen" in a late revision once my tests
triggered it. Forgot to remove the min(). Fixed in v3 to:
return len >= plen && !strncmp(str, prefix, plen);
Thanks
David
> Ran
>
>> +}
>> +
>> static inline int
>> bit_is_set(const unsigned long *array, int bit)
>> {
>> --
>> 1.8.4.1
>>
>> _______________________________________________
>> Input-tools mailing list
>> Input-tools at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/input-tools
More information about the Input-tools
mailing list