diff options
author | Yunmi Ha <yunmi.ha@samsung.com> | 2021-01-19 17:54:08 +0900 |
---|---|---|
committer | Yunmi Ha <yunmi.ha@samsung.com> | 2021-01-19 17:54:08 +0900 |
commit | f5178ae60007f4433d95555448f13bc6a164cf2e (patch) | |
tree | 3c9836cdc4c5e28b3c8faffdcb622febabaee067 | |
parent | c511a48aaf54e15346cfbb2e32dd05cdc2c3eb62 (diff) | |
download | device-emulator-f5178ae60007f4433d95555448f13bc6a164cf2e.tar.gz device-emulator-f5178ae60007f4433d95555448f13bc6a164cf2e.tar.bz2 device-emulator-f5178ae60007f4433d95555448f13bc6a164cf2e.zip |
Use file library of libsyscommon
Change-Id: I574682ab013f430f848bcd9dcee466ea848f7109
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
-rw-r--r-- | hw/battery/battery.c | 1 | ||||
-rw-r--r-- | hw/common/common.h | 109 | ||||
-rw-r--r-- | hw/display/display.c | 1 | ||||
-rw-r--r-- | hw/external_connection/external_connection.c | 1 |
4 files changed, 3 insertions, 109 deletions
diff --git a/hw/battery/battery.c b/hw/battery/battery.c index dca5f1f..2b323a9 100644 --- a/hw/battery/battery.c +++ b/hw/battery/battery.c @@ -26,6 +26,7 @@ #include <hal/device/hal-battery-interface.h> #include <hal/hal-common-interface.h> +#include <libsyscommon/file.h> #include "../dbus.h" #include "common.h" diff --git a/hw/common/common.h b/hw/common/common.h index 710f67b..413ed8a 100644 --- a/hw/common/common.h +++ b/hw/common/common.h @@ -17,13 +17,6 @@ #ifndef __HAL_BACKEND_COMMON_H__ #define __HAL_BACKEND_COMMON_H__ -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - #ifdef FEATURE_DLOG #define LOG_TAG "HAL_BACKEND_DEVICE" #include <dlog.h> @@ -41,106 +34,4 @@ #define EXPORT __attribute__ ((visibility("default"))) -#define SHARED_H_BUF_MAX 255 - -static inline int sys_read_buf(char *file, char *buf, int len) -{ - int fd, r; - - if (!file || !buf || len < 0) - return -EINVAL; - - fd = open(file, O_RDONLY); - if (fd == -1) - return -ENOENT; - - r = read(fd, buf, len); - close(fd); - if ((r >= 0) && (r < len)) - buf[r] = '\0'; - else - return -EIO; - - return 0; -} - -static inline int sys_write_buf(char *file, char *buf) -{ - int fd, r; - - if (!file || !buf) - return -EINVAL; - - fd = open(file, O_WRONLY); - if (fd == -1) - return -EPERM; - - r = write(fd, buf, strlen(buf)); - close(fd); - if (r < 0) - return -EIO; - - return 0; -} - -static inline int sys_get_int(char *fname, int *val) -{ - char buf[SHARED_H_BUF_MAX]; - int r; - - if (!fname || !val) - return -EINVAL; - - r = sys_read_buf(fname, buf, sizeof(buf)); - if (r < 0) - return r; - - *val = atoi(buf); - return 0; -} - -static inline int sys_get_str(char *fname, char *str, int len) -{ - int r; - - if (!fname || !str || len < 0) - return -EINVAL; - - r = sys_read_buf(fname, str, len); - if (r < 0) - return r; - - return 0; -} - -static inline int sys_set_int(char *fname, int val) -{ - char buf[SHARED_H_BUF_MAX]; - int r; - - if (!fname) - return -EINVAL; - - snprintf(buf, sizeof(buf), "%d", val); - r = sys_write_buf(fname, buf); - if (r < 0) - return r; - - return 0; -} - -static inline int sys_set_str(char *fname, char *val) -{ - int r; - - if (!fname || !val) - return -EINVAL; - - r = sys_write_buf(fname, val); - if (r < 0) - return r; - - return 0; -} - #endif /* __HAL_BACKEND_COMMON_H__ */ diff --git a/hw/display/display.c b/hw/display/display.c index f4bf894..ee59d19 100644 --- a/hw/display/display.c +++ b/hw/display/display.c @@ -25,6 +25,7 @@ #include <hal/device/hal-display-interface.h> #include <hal/hal-common-interface.h> +#include <libsyscommon/file.h> #include "common.h" diff --git a/hw/external_connection/external_connection.c b/hw/external_connection/external_connection.c index c61a716..1505477 100644 --- a/hw/external_connection/external_connection.c +++ b/hw/external_connection/external_connection.c @@ -27,6 +27,7 @@ #include <hal/device/hal-external_connection-interface.h> #include <hal/hal-common-interface.h> +#include <libsyscommon/file.h> #include "../dbus.h" #include "common.h" |