2 * PASS (Power Aware System Service)
4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 static int sysfs_read_buf(char *path, char *buf, int len)
31 if ((!path) || (!buf) || (len < 0))
34 fd = open(path, O_RDONLY);
38 r = read(fd, buf, len);
41 if ((r < 0) || (r > len))
49 static int sysfs_write_buf(char *path, char *buf)
53 if ((!path) || (!buf))
56 fd = open(path, O_WRONLY);
60 w = write(fd, buf, strlen(buf));
69 int sysfs_read_int(char *path, int *val)
71 char buf[MAX_BUF_SIZE + 1];
74 if ((!path) || (!val))
77 r = sysfs_read_buf(path, buf, MAX_BUF_SIZE);
85 int sysfs_read_str(char *path, char *str, int len)
89 if ((!path) || (!str) || (len <= 0))
92 r = sysfs_read_buf(path, str, len);
99 int sysfs_write_int(char *path, int val)
101 char buf[MAX_BUF_SIZE + 1];
107 snprintf(buf, MAX_BUF_SIZE, "%d", val);
108 w = sysfs_write_buf(path, buf);
115 int sysfs_write_str(char *path, char *str)
119 if ((!path) || (!str))
122 w = sysfs_write_buf(path, str);