Add crash manager API
[platform/core/system/crash-worker.git] / src / shared / util.h
1 /*
2  * crash-manager
3  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #ifndef __DEF_UTIL_H__
18 #define __DEF_UTIL_H__
19
20 #include <stdbool.h>
21 #include <sys/types.h>
22
23 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
24
25 #ifndef __CONSTRUCTOR__
26 #define __CONSTRUCTOR__ __attribute__ ((constructor))
27 #endif
28
29 #define fprintf_fd(fd, fmt, ...) dprintf(fd, fmt, ##__VA_ARGS__)
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 int write_fd(int fd, const void *buf, int len);
36
37 int copy_bytes(int destfd, int srcfd, off_t *ncopied);
38
39 int copy_file(char *dst, char *src);
40
41 int move_file(char *dst, char *src);
42
43 int dump_file_write_fd(int dfd, char *src);
44
45 int fsync_path(char *const path);
46
47 int make_dir(const char *path, const char *name, int mode);
48
49 int remove_dir(const char *path, int del_dir);
50
51 int get_exec_pid(const char *execpath);
52
53 int get_file_count(char *path);
54
55 off_t get_directory_usage(char *path);
56
57 int log_kmsg(char *fmt, ...);
58
59 int find_crash_tid(int pid);
60
61 bool get_exe_path(pid_t pid, char *outbuf, size_t outbuf_len);
62
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);
66
67 char* concatenate(char *const vec[]);
68
69 bool string_ends_with(const char *string, const char *suffix);
70
71 bool file_exists(const char *path);
72
73 bool write_to_file(const char *content, const char *base_dir, const char *file_name);
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 /**
80  * @}
81  */
82 #endif