diff options
| author | David Herrmann <dh.herrmann@gmail.com> | 2013-10-30 08:24:43 +0100 |
|---|---|---|
| committer | Peter Hutterer <peter.hutterer@who-t.net> | 2013-10-31 11:23:13 +1000 |
| commit | 5183bf37634f2eaeb3616baf6c76993ea697cfdd (patch) | |
| tree | b2da758d3e77b437ef3da2f408b1175a28ed2f14 /libevdev/libevdev-util.h | |
| parent | 639a5a9b56644c5c6f3d83bac661f5d97e39d1a9 (diff) | |
| download | libevdev-5183bf37634f2eaeb3616baf6c76993ea697cfdd.tar.gz | |
Add startswith() helper
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@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'libevdev/libevdev-util.h')
| -rw-r--r-- | libevdev/libevdev-util.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libevdev/libevdev-util.h b/libevdev/libevdev-util.h index 3a40a61..227363c 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, plen); +} + static inline int bit_is_set(const unsigned long *array, int bit) { |
