4 * Copyright (c) 2015 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.
24 #include <sys/types.h>
31 static int sys_read_buf(char *file, char *buf, int len)
35 if (!file || !buf || len < 0)
38 fd = open(file, O_RDONLY);
42 r = read(fd, buf, len);
44 if ((r >= 0) && (r < len))
52 static int sys_write_buf(char *file, char *buf)
59 fd = open(file, O_WRONLY);
63 r = write(fd, buf, strlen(buf));
71 int sys_get_int(char *fname, int *val)
79 r = sys_read_buf(fname, buf, sizeof(buf));
87 int sys_get_str(char *fname, char *str, int len)
91 if (!fname || !str || len < 0)
94 r = sys_read_buf(fname, str, len);
101 int sys_set_int(char *fname, int val)
109 snprintf(buf, sizeof(buf), "%d", val);
110 r = sys_write_buf(fname, buf);
117 int sys_set_str(char *fname, char *val)
124 r = sys_write_buf(fname, val);