From 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Thu, 16 May 2024 03:11:33 +0000
Subject: [PATCH] AX88772C_eeprom and ax8872c build together
---
kernel/tools/lib/symbol/kallsyms.c | 84 +++++++++++++++++++++--------------------
1 files changed, 43 insertions(+), 41 deletions(-)
diff --git a/kernel/tools/lib/symbol/kallsyms.c b/kernel/tools/lib/symbol/kallsyms.c
index 96d8305..e335ac2 100644
--- a/kernel/tools/lib/symbol/kallsyms.c
+++ b/kernel/tools/lib/symbol/kallsyms.c
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
-#include <ctype.h>
#include "symbol/kallsyms.h"
+#include "api/io.h"
#include <stdio.h>
-#include <stdlib.h>
+#include <sys/stat.h>
+#include <fcntl.h>
u8 kallsyms2elf_type(char type)
{
@@ -16,61 +17,62 @@
return symbol_type == 'T' || symbol_type == 'W';
}
+static void read_to_eol(struct io *io)
+{
+ int ch;
+
+ for (;;) {
+ ch = io__get_char(io);
+ if (ch < 0 || ch == '\n')
+ return;
+ }
+}
+
int kallsyms__parse(const char *filename, void *arg,
int (*process_symbol)(void *arg, const char *name,
char type, u64 start))
{
- char *line = NULL;
- size_t n;
- int err = -1;
- FILE *file = fopen(filename, "r");
+ struct io io;
+ char bf[BUFSIZ];
+ int err;
- if (file == NULL)
- goto out_failure;
+ io.fd = open(filename, O_RDONLY, 0);
+
+ if (io.fd < 0)
+ return -1;
+
+ io__init(&io, io.fd, bf, sizeof(bf));
err = 0;
-
- while (!feof(file)) {
- u64 start;
- int line_len, len;
+ while (!io.eof) {
+ __u64 start;
+ int ch;
+ size_t i;
char symbol_type;
- char *symbol_name;
+ char symbol_name[KSYM_NAME_LEN + 1];
- line_len = getline(&line, &n, file);
- if (line_len < 0 || !line)
- break;
-
- line[--line_len] = '\0'; /* \n */
-
- len = hex2u64(line, &start);
-
- /* Skip the line if we failed to parse the address. */
- if (!len)
+ if (io__get_hex(&io, &start) != ' ') {
+ read_to_eol(&io);
continue;
-
- len++;
- if (len + 2 >= line_len)
- continue;
-
- symbol_type = line[len];
- len += 2;
- symbol_name = line + len;
- len = line_len - len;
-
- if (len >= KSYM_NAME_LEN) {
- err = -1;
- break;
}
+ symbol_type = io__get_char(&io);
+ if (io__get_char(&io) != ' ') {
+ read_to_eol(&io);
+ continue;
+ }
+ for (i = 0; i < sizeof(symbol_name); i++) {
+ ch = io__get_char(&io);
+ if (ch < 0 || ch == '\n')
+ break;
+ symbol_name[i] = ch;
+ }
+ symbol_name[i] = '\0';
err = process_symbol(arg, symbol_name, symbol_type, start);
if (err)
break;
}
- free(line);
- fclose(file);
+ close(io.fd);
return err;
-
-out_failure:
- return -1;
}
--
Gitblit v1.6.2