Initialize Tizen 2.3
[framework/system/deviced.git] / src / core / common.h
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19
20 #ifndef __CORE_COMMON_H__
21 #define __CORE_COMMON_H__
22
23 #include <stdio.h>
24 #include <error.h>
25 #include <stdbool.h>
26 #include <unistd.h>
27
28 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
29
30 /*
31  * One byte digit has 3 position in decimal representation
32  * 2 - 5
33  * 4 - 10
34  * 8 - 20
35  * >8 - compile time error
36  * plus 1 null termination byte
37  * plus 1 for negative prefix
38  */
39 #define MAX_DEC_SIZE(type) \
40         (2 + (sizeof(type) <= 1 ? 3 : \
41         sizeof(type) <= 2 ? 5 : \
42         sizeof(type) <= 4 ? 10 : \
43         sizeof(type) <= 8 ? 20 : \
44         sizeof(int[-2*(sizeof(type) > 8)])))
45
46 #ifndef __CONSTRUCTOR__
47 #define __CONSTRUCTOR__ __attribute__ ((constructor))
48 #endif
49
50 #ifndef __DESTRUCTOR__
51 #define __DESTRUCTOR__ __attribute__ ((destructor))
52 #endif
53
54 #ifndef __WEAK__
55 #define __WEAK__ __attribute__ ((weak))
56 #endif
57
58 #ifndef max
59 #define max(a, b)                       \
60         __extension__ ({                \
61                 typeof(a) _a = (a);     \
62                 typeof(b) _b = (b);     \
63                 _a > _b ? _a : _b;      \
64         })
65 #endif
66
67 #ifndef min
68 #define min(a, b)                       \
69         __extension__ ({                \
70                 typeof(a) _a = (a);     \
71                 typeof(b) _b = (b);     \
72                 _a < _b ? _a : _b;      \
73         })
74 #endif
75
76 #ifndef clamp
77 #define clamp(x, low, high)                                             \
78         __extension__ ({                                                \
79                 typeof(x) _x = (x);                                     \
80                 typeof(low) _low = (low);                               \
81                 typeof(high) _high = (high);                            \
82                 ((_x > _high) ? _high : ((_x < _low) ? _low : _x));     \
83         })
84 #endif
85
86 #ifndef SEC_TO_MSEC
87 #define SEC_TO_MSEC(x)          ((x)*1000)
88 #endif
89 #ifndef NSEC_TO_MSEC
90 #define NSEC_TO_MSEC(x)         ((double)x/1000000)
91 #endif
92 #ifndef USEC_TO_MSEC
93 #define USEC_TO_MSEC(x)         ((double)x/1000)
94 #endif
95
96 FILE * open_proc_oom_score_adj_file(int pid, const char *mode);
97 int get_exec_pid(const char *execpath);
98 int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size);
99 int is_vip(int pid);
100 int run_child(int argc, const char *argv[]);
101 int remove_dir(const char *path, int del_dir);
102 int sys_get_int(char *fname, int *val);
103 int sys_set_int(char *fname, int val);
104 int terminate_process(char* partition, bool force);
105 int mount_check(const char* path);
106
107 #endif  /* __CORE_COMMON_H__ */
108