Add error checking macros
[apps/native/ttsd-worker-task.git] / src / procfs.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #include <stdio.h>
18
19 #include "procfs.h"
20 #include "log.h"
21 #include "err-check.h"
22
23 #define LOADAVG_FILEPATH "/proc/loadavg"
24
25 int procfs_read_system_load_average(struct procfs_load_average_info *info)
26 {
27         float a1, a5, a15;
28
29         ON_NULL_RETURN_VAL(info, -1);
30
31         FILE *loadavg_fp = fopen(LOADAVG_FILEPATH, "r");
32         if (!loadavg_fp) {
33                 ERR("failed to open " LOADAVG_FILEPATH);
34                 return -1;
35         }
36
37         if (fscanf(loadavg_fp, "%f %f %f", &a1, &a5, &a15) != 3) {
38                 ERR("failed to read " LOADAVG_FILEPATH);
39                 fclose(loadavg_fp);
40                 return -1;
41         }
42
43         info->one_min_avg = a1;
44         info->five_min_avg = a5;
45         info->fifteen_min_avg = a15;
46
47         fclose(loadavg_fp);
48
49         return 0;
50 }
51
52 int profcs_read_system_cpu_usage(struct procfs_system_cpu_usage_info *usage)
53 {
54         return -1;
55 }
56
57 int profcs_read_system_percpu_usage(struct procfs_system_percpu_usage_info **usage)
58 {
59         return -1;
60 }
61
62 int procfs_read_system_memory_usage(struct procfs_system_memory_usage_info *usage)
63 {
64         return -1;
65 }
66
67 int procfs_read_process_memory_usage(int pid, struct procfs_process_memory_usage_info *usage)
68 {
69         return -1;
70 }
71
72 int procfs_read_process_cpu_usage(int pid, struct procfs_process_cpu_usage_info *usage)
73 {
74         return -1;
75 }
76
77 int procfs_read_uptime(int *uptime)
78 {
79         return -1;
80 }
81
82 int procfs_read_cpu_count(int *cpu_count)
83 {
84         return -1;
85 }