Merge tag 'powerpc-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux/fpc-iii.git] / tools / perf / util / find-map.c
blob7b2300588ece08c6f5a29de1527300772efa9174
1 // SPDX-License-Identifier: GPL-2.0
2 static int find_map(void **start, void **end, const char *name)
4 FILE *maps;
5 char line[128];
6 int found = 0;
8 maps = fopen("/proc/self/maps", "r");
9 if (!maps) {
10 fprintf(stderr, "cannot open maps\n");
11 return -1;
14 while (!found && fgets(line, sizeof(line), maps)) {
15 int m = -1;
17 /* We care only about private r-x mappings. */
18 if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
19 start, end, &m))
20 continue;
21 if (m < 0)
22 continue;
24 if (!strncmp(&line[m], name, strlen(name)))
25 found = 1;
28 fclose(maps);
29 return !found;