Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
c19e33a
Documentation
arch
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools/perf
Documentation
bench
util
include
PERF-VERSION-GEN
abspath.c
alias.c
cache.h
callchain.c
callchain.h
color.c
color.h
config.c
ctype.c
data_map.c
data_map.h
debug.c
debug.h
debugfs.c
debugfs.h
environment.c
event.c
event.h
exec_cmd.c
exec_cmd.h
generate-cmdlist.sh
header.c
header.h
help.c
help.h
hist.c
hist.h
levenshtein.c
levenshtein.h
map.c
pager.c
parse-events.c
parse-events.h
parse-options.c
parse-options.h
path.c
probe-event.c
probe-event.h
probe-finder.c
probe-finder.h
quote.c
quote.h
run-command.c
run-command.h
sigchain.c
sigchain.h
sort.c
sort.h
strbuf.c
strbuf.h
string.c
string.h
strlist.c
strlist.h
svghelper.c
svghelper.h
symbol.c
symbol.h
thread.c
thread.h
trace-event-info.c
trace-event-parse.c
trace-event-read.c
trace-event.h
types.h
usage.c
util.h
values.c
values.h
wrapper.c
.gitignore
CREDITS
Makefile
builtin-annotate.c
builtin-bench.c
builtin-buildid-list.c
builtin-help.c
builtin-kmem.c
builtin-list.c
builtin-probe.c
builtin-record.c
builtin-report.c
builtin-sched.c
builtin-stat.c
builtin-timechart.c
builtin-top.c
builtin-trace.c
builtin.h
command-list.txt
design.txt
perf.c
perf.h
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
tools
/
perf
/
util
/
string.c
Blame
Blame
Latest commit
History
History
228 lines (195 loc) · 3.57 KB
Breadcrumbs
linux
/
tools
/
perf
/
util
/
string.c
Top
File metadata and controls
Code
Blame
228 lines (195 loc) · 3.57 KB
Raw
#include "string.h" #include "util.h" static int hex(char ch) { if ((ch >= '0') && (ch <= '9')) return ch - '0'; if ((ch >= 'a') && (ch <= 'f')) return ch - 'a' + 10; if ((ch >= 'A') && (ch <= 'F')) return ch - 'A' + 10; return -1; } /* * While we find nice hex chars, build a long_val. * Return number of chars processed. */ int hex2u64(const char *ptr, u64 *long_val) { const char *p = ptr; *long_val = 0; while (*p) { const int hex_val = hex(*p); if (hex_val < 0) break; *long_val = (*long_val << 4) | hex_val; p++; } return p - ptr; } char *strxfrchar(char *s, char from, char to) { char *p = s; while ((p = strchr(p, from)) != NULL) *p++ = to; return s; } #define K 1024LL /* * perf_atoll() * Parse (\d+)(b|B|kb|KB|mb|MB|gb|GB|tb|TB) (e.g. "256MB") * and return its numeric value */ s64 perf_atoll(const char *str) { unsigned int i; s64 length = -1, unit = 1; if (!isdigit(str[0])) goto out_err; for (i = 1; i < strlen(str); i++) { switch (str[i]) { case 'B': case 'b': break; case 'K': if (str[i + 1] != 'B') goto out_err; else goto kilo; case 'k': if (str[i + 1] != 'b') goto out_err; kilo: unit = K; break; case 'M': if (str[i + 1] != 'B') goto out_err; else goto mega; case 'm': if (str[i + 1] != 'b') goto out_err; mega: unit = K * K; break; case 'G': if (str[i + 1] != 'B') goto out_err; else goto giga; case 'g': if (str[i + 1] != 'b') goto out_err; giga: unit = K * K * K; break; case 'T': if (str[i + 1] != 'B') goto out_err; else goto tera; case 't': if (str[i + 1] != 'b') goto out_err; tera: unit = K * K * K * K; break; case '\0': /* only specified figures */ unit = 1; break; default: if (!isdigit(str[i])) goto out_err; break; } } length = atoll(str) * unit; goto out; out_err: length = -1; out: return length; } /* * Helper function for splitting a string into an argv-like array. * originaly copied from lib/argv_split.c */ static const char *skip_sep(const char *cp) { while (*cp && isspace(*cp)) cp++; return cp; } static const char *skip_arg(const char *cp) { while (*cp && !isspace(*cp)) cp++; return cp; } static int count_argc(const char *str) { int count = 0; while (*str) { str = skip_sep(str); if (*str) { count++; str = skip_arg(str); } } return count; } /** * argv_free - free an argv * @argv - the argument vector to be freed * * Frees an argv and the strings it points to. */ void argv_free(char **argv) { char **p; for (p = argv; *p; p++) free(*p); free(argv); } /** * argv_split - split a string at whitespace, returning an argv * @str: the string to be split * @argcp: returned argument count * * Returns an array of pointers to strings which are split out from * @str. This is performed by strictly splitting on white-space; no * quote processing is performed. Multiple whitespace characters are * considered to be a single argument separator. The returned array * is always NULL-terminated. Returns NULL on memory allocation * failure. */ char **argv_split(const char *str, int *argcp) { int argc = count_argc(str); char **argv = zalloc(sizeof(*argv) * (argc+1)); char **argvp; if (argv == NULL) goto out; if (argcp) *argcp = argc; argvp = argv; while (*str) { str = skip_sep(str); if (*str) { const char *p = str; char *t; str = skip_arg(str); t = strndup(p, str-p); if (t == NULL) goto fail; *argvp++ = t; } } *argvp = NULL; out: return argv; fail: argv_free(argv); return NULL; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
You can’t perform that action at this time.