diff options
author | Damjan Marion <damarion@cisco.com> | 2023-08-06 20:39:38 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2023-08-07 17:33:09 +0000 |
commit | 8d0c0c68215a2972053ba7fd8fa0f82aa14f8624 (patch) | |
tree | 035f14012dfd939890cf360898be6d4e71021504 /src/vppinfra/cpu.c | |
parent | 696db20e332fcbecaaef9c5505cc2e132bfaa9e2 (diff) |
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 <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/cpu.c')
-rw-r--r-- | src/vppinfra/cpu.c | 36 |
1 files changed, 17 insertions, 19 deletions
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)\ |