2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __HAL_BACKEND_COMMON_H__
18 #define __HAL_BACKEND_COMMON_H__
28 #define LOG_TAG "HAL_BACKEND_DEVICE"
30 #define _D(fmt, args...) SLOGD(fmt, ##args)
31 #define _I(fmt, args...) SLOGI(fmt, ##args)
32 #define _W(fmt, args...) SLOGW(fmt, ##args)
33 #define _E(fmt, args...) SLOGE(fmt, ##args)
41 #define EXPORT __attribute__ ((visibility("default")))
43 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
45 #define SHARED_H_BUF_MAX 255
47 static inline int sys_read_buf(char *file, char *buf, int len)
51 if (!file || !buf || len < 0)
54 fd = open(file, O_RDONLY);
58 r = read(fd, buf, len);
60 if ((r >= 0) && (r < len))
68 static inline int sys_write_buf(char *file, char *buf)
75 fd = open(file, O_WRONLY);
79 r = write(fd, buf, strlen(buf));
87 static inline int sys_get_int(char *fname, int *val)
89 char buf[SHARED_H_BUF_MAX];
95 r = sys_read_buf(fname, buf, sizeof(buf));
103 static inline int sys_get_str(char *fname, char *str, int len)
107 if (!fname || !str || len < 0)
110 r = sys_read_buf(fname, str, len);
117 static inline int sys_set_int(char *fname, int val)
119 char buf[SHARED_H_BUF_MAX];
125 snprintf(buf, sizeof(buf), "%d", val);
126 r = sys_write_buf(fname, buf);
133 static inline int sys_set_str(char *fname, char *val)
140 r = sys_write_buf(fname, val);
147 #endif /* __HAL_BACKEND_COMMON_H__ */