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 @@
1#ifndef _TOOLS_LINUX_STRING_H_1#ifndef _TOOLS_LINUX_STRING_H_
2#define _TOOLS_LINUX_STRING_H_2#define _TOOLS_LINUX_STRING_H_
3 3
4
5#include <linux/types.h> /* for size_t */4#include <linux/types.h> /* for size_t */
5#include <string.h>
6 6
7void *memdup(const void *src, size_t len);7void *memdup(const void *src, size_t len);
8 8
@@ -18,6 +18,14 @@ extern size_t strlcpy(char *dest, const char *src, size_t size); · 9 unmodified lines
18 18
19char *str_error_r(int errnum, char *buf, size_t buflen);19char *str_error_r(int errnum, char *buf, size_t buflen);
20 20
21int 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 */
26static inline bool strstarts(const char *str, const char *prefix)
27{
28 return strncmp(str, prefix, strlen(prefix)) == 0;
29}
22 30
23#endif /* _LINUX_STRING_H_ */31#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