4 * Copyright (c) 2012 - 2013 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.
20 #ifndef __CORE_COMMON_H__
21 #define __CORE_COMMON_H__
29 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
32 * One byte digit has 3 position in decimal representation
36 * >8 - compile time error
37 * plus 1 null termination byte
38 * plus 1 for negative prefix
40 #define MAX_DEC_SIZE(type) \
41 (2 + (sizeof(type) <= 1 ? 3 : \
42 sizeof(type) <= 2 ? 5 : \
43 sizeof(type) <= 4 ? 10 : \
44 sizeof(type) <= 8 ? 20 : \
45 sizeof(int[-2*(sizeof(type) > 8)])))
47 #ifndef __CONSTRUCTOR__
48 #define __CONSTRUCTOR__ __attribute__ ((constructor))
51 #ifndef __DESTRUCTOR__
52 #define __DESTRUCTOR__ __attribute__ ((destructor))
56 #define __WEAK__ __attribute__ ((weak))
78 #define clamp(x, low, high) \
81 typeof(low) _low = (low); \
82 typeof(high) _high = (high); \
83 ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
88 #define SEC_TO_MSEC(x) ((x)*1000)
91 #define NSEC_TO_MSEC(x) ((double)x/1000000)
94 #define USEC_TO_MSEC(x) ((double)x/1000)
98 #define safe_free(x) safe_free_memory((void**)&(x))
101 static inline void safe_free_memory(void** mem)
109 #define ret_value_if(expr, val) do { \
116 #define ret_value_msg_if(expr, val, fmt, arg...) do { \
123 #define ret_msg_if(expr, fmt, arg...) do { \
130 FILE * open_proc_oom_score_adj_file(int pid, const char *mode);
131 int get_exec_pid(const char *execpath);
132 int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size);
134 int run_child(int argc, const char *argv[]);
135 int remove_dir(const char *path, int del_dir);
136 int sys_get_int(char *fname, int *val);
137 int sys_set_int(char *fname, int val);
138 int terminate_process(char* partition, bool force);
139 int mount_check(const char* path);
140 void print_time(const char *prefix);
142 #endif /* __CORE_COMMON_H__ */