})
#endif
-#ifndef clamp
-#define clamp(x, low, high) \
- __extension__ ({ \
- typeof(x) _x = (x); \
- typeof(low) _low = (low); \
- typeof(high) _high = (high); \
- ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
- })
-#endif
-
#ifndef SEC_TO_MSEC
#define SEC_TO_MSEC(x) ((x)*1000)
#endif
#define USEC_TO_MSEC(x) ((double)x/1000)
#endif
-#define NANO_SECOND_MULTIPLIER 1000000 /* 1ms = 1,000,000 nsec */
-
-#ifndef safe_free
-#define safe_free(x) safe_free_memory((void**)&(x))
-#endif
-
-static inline void safe_free_memory(void** mem)
-{
- if (mem && *mem) {
- free(*mem);
- *mem = NULL;
- }
-}
-
-#define ret_value_if(expr, val) do { \
- if (expr) { \
- _E("(%s)", #expr); \
- return (val); \
- } \
-} while (0)
-
-#define ret_value_msg_if(expr, val, fmt, arg...) do { \
- if (expr) { \
- _E(fmt, ##arg); \
- return val; \
- } \
-} while (0)
-
-#define ret_msg_if(expr, fmt, arg...) do { \
- if (expr) { \
- _E(fmt, ##arg); \
- return; \
- } \
-} while (0)
-
-FILE * open_proc_oom_score_adj_file(int pid, const char *mode);
-int get_exec_pid(const char *execpath);
-int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size);
-int is_vip(int pid);
-int remove_dir(const char *path, int del_dir);
-int sys_check_node(char *path);
int sys_get_int(char *fname, int *val);
-int sys_set_int(char *fname, int val);
int sys_get_str(char *fname, char *str);
-int sys_set_str(char *fname, char *val);
-int terminate_process(const char *partition, bool force);
-int mount_check(const char* path);
-void print_time(const char *prefix);
-int get_privilege(pid_t pid, char *name, size_t len);
#endif /* __CORE_COMMON_H__ */
#define BUFF_MAX 255
-int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size)
-{
- int fd, ret;
- char buf[PATH_MAX + 1];
- char *filename;
-
- if (!cmdline_size)
- return -1;
-
- snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
- fd = open(buf, O_RDONLY);
- if (fd < 0) {
- errno = ESRCH;
- return -1;
- }
-
- ret = read(fd, buf, PATH_MAX);
- close(fd);
- if ((ret >= 0) && (ret <= PATH_MAX)) {
- buf[ret] = '\0';
- } else {
- errno = EIO;
- return -1;
- }
-
- filename = strrchr(buf, '/');
- if (filename == NULL)
- filename = buf;
- else
- filename = filename + 1;
-
- if ((cmdline_size - 1) < strlen(filename)) {
- errno = EOVERFLOW;
- return -1;
- }
-
- strncpy(cmdline, filename, cmdline_size - 1);
- cmdline[cmdline_size - 1] = '\0';
- return 0;
-}
-
-/*
- * Helper function
- * - Read from sysfs entry
- * - Write to sysfs entry
- */
-int sys_check_node(char *path)
-{
- int fd;
-
- fd = open(path, O_RDONLY);
- if (fd == -1)
- return -1;
-
- close(fd);
- return 0;
-}
-
static int sys_read_buf(char *file, char *buf)
{
int fd;
return ret;
}
-static int sys_write_buf(char *file, char *buf)
-{
- int fd;
- int r;
- int ret = 0;
-
- fd = open(file, O_WRONLY);
- if (fd == -1)
- return -ENOENT;
-
- r = write(fd, buf, strlen(buf));
- if (r < 0)
- ret = -EIO;
-
- close(fd);
-
- return ret;
-}
-
int sys_get_int(char *fname, int *val)
{
char buf[BUFF_MAX];
return ret;
}
-int sys_set_int(char *fname, int val)
-{
- char buf[BUFF_MAX];
- int ret = 0;
-
- snprintf(buf, sizeof(buf), "%d", val);
-
- if (sys_write_buf(fname, buf) != 0)
- ret = -EIO;
-
- return ret;
-}
-
int sys_get_str(char *fname, char *str)
{
char buf[BUFF_MAX] = {0};
return -1;
}
-
-int sys_set_str(char *fname, char *val)
-{
- int r = -1;
-
- if (val != NULL) {
- if (sys_write_buf(fname, val) == 0)
- r = 0;
- }
-
- return r;
-}