History

tools include: Adopt strstarts() from the kernel

Replacing prefixcmp(), same purpose, inverted result, so standardize on the kernel variant, to reduce silly differences among tools/ and the kernel sources, making it easier for people to work in both codebases. And then doing: if (strstarts(option, "no-")) Looks clearer than doing: if (!prefixcmp(option, "no-")) To figure out if option starts witn "no-".

Arnaldo Carvalho de Melo committed 9 years ago

Commit 8e99b6d1 parent 082ab9a15 files · +50 −46Browse files

Showing the changes to tools/include/linux/string.h (1 of 15 files). Show all

Unified · Split

tools/include/linux/string.h+10−2
@@ -1,8 +1,8 @@
11 #ifndef _TOOLS_LINUX_STRING_H_
22 #define _TOOLS_LINUX_STRING_H_
33
4−
54 #include <linux/types.h> /* for size_t */
5+#include <string.h>
66
77 void *memdup(const void *src, size_t len);
88
@@ -18,6 +18,14 @@ extern size_t strlcpy(char *dest, const char *src, size_t size); · 9 unmodified lines
1818
1919 char *str_error_r(int errnum, char *buf, size_t buflen);
2020
21−int prefixcmp(const char *str, const char *prefix);
21+/**
22+ * strstarts - does @str start with @prefix?
23+ * @str: string to examine
24+ * @prefix: prefix to look for.
25+ */
26+static inline bool strstarts(const char *str, const char *prefix)
27+{
28+ return strncmp(str, prefix, strlen(prefix)) == 0;
29+}
2230
2331 #endif /* _LINUX_STRING_H_ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t