From 32757ea50f80db04a045ba2aa22c60d1ff0537c7 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 17 Feb 2022 16:05:33 +0900 Subject: [PATCH] util: common: Add sys_get_int helper funciton to get integer Change-Id: I8eca9fe1bb1f0c95954d0439d0f398795a5421db Signed-off-by: Chanwoo Choi --- include/util/common.h | 1 + src/util/common.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/util/common.h b/include/util/common.h index 263ceea..9cb9373 100644 --- a/include/util/common.h +++ b/include/util/common.h @@ -107,6 +107,7 @@ typedef unsigned long long uint64; #endif int sys_get_str(const char *fname, char *str); +int sysfs_get_int(char *path, int *val); const char *get_string_from_object(json_object *obj, const char *key); const int get_int_from_object(json_object *obj, const char *key); diff --git a/src/util/common.c b/src/util/common.c index 04dc78b..defcc0f 100644 --- a/src/util/common.c +++ b/src/util/common.c @@ -73,6 +73,22 @@ int sys_get_str(const char *fname, char *str) return -1; } +int sysfs_get_int(char *path, int *val) +{ + char buf[BUFF_MAX + 1]; + int r; + + if ((!path) || (!val)) + return -EINVAL; + + r = sys_read_buf(path, buf); + if (r < 0) + return r; + + *val = atoi(buf); + return 0; +} + const char *get_string_from_object(json_object *obj, const char *key) { json_object *tmp = NULL; -- 2.34.1