3 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 #ifndef __DEF_UTIL_H__
18 #define __DEF_UTIL_H__
21 #include <sys/types.h>
23 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
25 #ifndef __CONSTRUCTOR__
26 #define __CONSTRUCTOR__ __attribute__ ((constructor))
29 #define fprintf_fd(fd, fmt, ...) dprintf(fd, fmt, ##__VA_ARGS__)
35 int write_fd(int fd, const void *buf, int len);
37 int copy_bytes(int destfd, int srcfd, off_t *ncopied);
39 int copy_file(char *dst, char *src);
41 int move_file(char *dst, char *src);
43 int dump_file_write_fd(int dfd, char *src);
45 int fsync_path(char *const path);
47 int make_dir(const char *path, const char *name, int mode);
49 int remove_dir(const char *path, int del_dir);
51 int get_exec_pid(const char *execpath);
53 int get_file_count(char *path);
55 off_t get_directory_usage(char *path);
57 int log_kmsg(char *fmt, ...);
59 int find_crash_tid(int pid);
61 bool get_exe_path(pid_t pid, char *outbuf, size_t outbuf_len);
63 typedef bool (*charp0filter)(char *buf, int size, int datalen);
64 bool filter_drop_trailing_whitespace(char *buf, int size, int datalen);
65 bool read_proc_file(pid_t pid, const char * const file, char *outbuf, size_t bufsize, charp0filter filter);
67 char* concatenate(char *const vec[]);
69 bool string_ends_with(const char *string, const char *suffix);
71 bool file_exists(const char *path);
73 bool write_to_file(const char *content, const char *base_dir, const char *file_name);