From: Chanwoo Choi Date: Thu, 17 Feb 2022 07:05:33 +0000 (+0900) Subject: util: common: Add sys_get_int helper funciton to get integer X-Git-Tag: submit/tizen/20220302.025412~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32757ea50f80db04a045ba2aa22c60d1ff0537c7;p=platform%2Fcore%2Fsystem%2Fpass.git util: common: Add sys_get_int helper funciton to get integer Change-Id: I8eca9fe1bb1f0c95954d0439d0f398795a5421db Signed-off-by: Chanwoo Choi --- 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;