From 8d0c0c68215a2972053ba7fd8fa0f82aa14f8624 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Sun, 6 Aug 2023 20:39:38 +0200 Subject: vppinfra: add unformat_init_path More conveninet way to unformat file by providing filesystem path. Takes format string for easier constuction of path... Type: improvement Change-Id: I433204fa20dc98e2b11c53914883d047a7fc62c6 Signed-off-by: Damjan Marion --- src/vppinfra/cpu.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/vppinfra/cpu.c') diff --git a/src/vppinfra/cpu.c b/src/vppinfra/cpu.c index 735a1830a48..b66dd4968ad 100644 --- a/src/vppinfra/cpu.c +++ b/src/vppinfra/cpu.c @@ -129,30 +129,28 @@ format(s, "[0x%x] %s ([0x%02x] %s) stepping 0x%x", f, a, m, c, stepping); return format (s, "unknown (family 0x%02x model 0x%02x)", family, model); #elif __aarch64__ - int fd; unformat_input_t input; u32 implementer, primary_part_number, variant, revision; - fd = open ("/proc/cpuinfo", 0); - if (fd < 0) - return format (s, "unknown"); - - unformat_init_clib_file (&input, fd); - while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) + if (unformat_init_file (&input, "/proc/cpuinfo")) { - if (unformat (&input, "CPU implementer%_: 0x%x", &implementer)) - ; - else if (unformat (&input, "CPU part%_: 0x%x", &primary_part_number)) - ; - else if (unformat (&input, "CPU variant%_: 0x%x", &variant)) - ; - else if (unformat (&input, "CPU revision%_: %u", &revision)) - ; - else - unformat_skip_line (&input); + while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (&input, "CPU implementer%_: 0x%x", &implementer)) + ; + else if (unformat (&input, "CPU part%_: 0x%x", &primary_part_number)) + ; + else if (unformat (&input, "CPU variant%_: 0x%x", &variant)) + ; + else if (unformat (&input, "CPU revision%_: %u", &revision)) + ; + else + unformat_skip_line (&input); + } + unformat_free (&input); } - unformat_free (&input); - close (fd); + else + return format (s, "unknown"); #define _(i,p,a,c,_format) if ((implementer == i) && (primary_part_number == p)){ \ if (_format)\ -- cgit 1.2.3-korg