util: common: Add sys_get_int helper funciton to get integer 55/271255/5
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 17 Feb 2022 07:05:33 +0000 (16:05 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 18 Feb 2022 07:52:00 +0000 (16:52 +0900)
Change-Id: I8eca9fe1bb1f0c95954d0439d0f398795a5421db
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
include/util/common.h
src/util/common.c

index 263ceea..9cb9373 100644 (file)
@@ -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);
index 04dc78b..defcc0f 100644 (file)
@@ -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;