Skip to content

Commit 2f4c278

Browse files
Improve smallfile callback (#211)
This PR improves the smallfile callback error reporting, passing the name of the inspected file in the `filename` argument instead of forcing it to be `KERNEL_MAX_FILENAME` as before.
1 parent b8b29a1 commit 2f4c278

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/linux/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
typedef bool (*cpuinfo_cpulist_callback)(uint32_t, uint32_t, void*);
2828
CPUINFO_INTERNAL bool cpuinfo_linux_parse_cpulist(const char* filename, cpuinfo_cpulist_callback callback, void* context);
29-
typedef bool (*cpuinfo_smallfile_callback)(const char*, const char*, void*);
29+
typedef bool (*cpuinfo_smallfile_callback)(const char*, const char*, const char*, void*);
3030
CPUINFO_INTERNAL bool cpuinfo_linux_parse_small_file(const char* filename, size_t buffer_size, cpuinfo_smallfile_callback, void* context);
3131
typedef bool (*cpuinfo_line_callback)(const char*, const char*, void*, uint64_t);
3232
CPUINFO_INTERNAL bool cpuinfo_linux_parse_multiline_file(const char* filename, size_t buffer_size, cpuinfo_line_callback, void* context);

src/linux/processors.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ inline static bool is_whitespace(char c) {
8888
static const uint32_t default_max_processors_count = CPU_SETSIZE;
8989
#endif
9090

91-
static bool uint32_parser(const char* text_start, const char* text_end, void* context) {
91+
static bool uint32_parser(const char* filename, const char* text_start, const char* text_end, void* context) {
9292
if (text_start == text_end) {
9393
cpuinfo_log_error("failed to parse file %s: file is empty", KERNEL_MAX_FILENAME);
9494
return false;
@@ -98,13 +98,13 @@ static bool uint32_parser(const char* text_start, const char* text_end, void* co
9898
const char* parsed_end = parse_number(text_start, text_end, &kernel_max);
9999
if (parsed_end == text_start) {
100100
cpuinfo_log_error("failed to parse file %s: \"%.*s\" is not an unsigned number",
101-
KERNEL_MAX_FILENAME, (int) (text_end - text_start), text_start);
101+
filename, (int) (text_end - text_start), text_start);
102102
return false;
103103
} else {
104104
for (const char* char_ptr = parsed_end; char_ptr != text_end; char_ptr++) {
105105
if (!is_whitespace(*char_ptr)) {
106106
cpuinfo_log_warning("non-whitespace characters \"%.*s\" following number in file %s are ignored",
107-
(int) (text_end - char_ptr), char_ptr, KERNEL_MAX_FILENAME);
107+
(int) (text_end - char_ptr), char_ptr, filename);
108108
break;
109109
}
110110
}

src/linux/smallfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool cpuinfo_linux_parse_small_file(const char* filename, size_t buffer_size, cp
5555
}
5656
} while (bytes_read != 0);
5757

58-
status = callback(buffer, &buffer[buffer_position], context);
58+
status = callback(filename, buffer, &buffer[buffer_position], context);
5959

6060
cleanup:
6161
if (file != -1) {

0 commit comments

Comments
 (0)