ARM64: juno: add GPIO keys
[linux/fpc-iii.git] / tools / lib / symbol / kallsyms.c
blob18bc271a4bbc7fe4232e6cc6f5fd2b2bf392846a
1 #include "symbol/kallsyms.h"
2 #include <stdio.h>
3 #include <stdlib.h>
5 int kallsyms__parse(const char *filename, void *arg,
6 int (*process_symbol)(void *arg, const char *name,
7 char type, u64 start))
9 char *line = NULL;
10 size_t n;
11 int err = -1;
12 FILE *file = fopen(filename, "r");
14 if (file == NULL)
15 goto out_failure;
17 err = 0;
19 while (!feof(file)) {
20 u64 start;
21 int line_len, len;
22 char symbol_type;
23 char *symbol_name;
25 line_len = getline(&line, &n, file);
26 if (line_len < 0 || !line)
27 break;
29 line[--line_len] = '\0'; /* \n */
31 len = hex2u64(line, &start);
33 len++;
34 if (len + 2 >= line_len)
35 continue;
37 symbol_type = line[len];
38 len += 2;
39 symbol_name = line + len;
40 len = line_len - len;
42 if (len >= KSYM_NAME_LEN) {
43 err = -1;
44 break;
47 err = process_symbol(arg, symbol_name, symbol_type, start);
48 if (err)
49 break;
52 free(line);
53 fclose(file);
54 return err;
56 out_failure:
57 return -1;