10 #define ATTR_FORMAT(x, y, z) __attribute__((format (x, y, z)))
11 #define ATTR_NORETURN __attribute__((noreturn));
13 #define ATTR_FORMAT(x, y, z)
18 #define MYNAME "ccache"
21 extern const char CCACHE_VERSION[];
23 // Statistics fields in storage order.
30 STATS_PREPROCESSOR = 5,
33 STATS_CACHEHIT_CPP = 8,
38 STATS_OBSOLETE_MAXFILES = 13,
39 STATS_OBSOLETE_MAXSIZE = 14,
40 STATS_SOURCELANG = 15,
45 STATS_UNSUPPORTED_OPTION = 20,
47 STATS_CACHEHIT_DIR = 22,
49 STATS_EMPTYOUTPUT = 24,
50 STATS_BADEXTRAFILE = 25,
52 STATS_CANTUSEPCH = 27,
53 STATS_PREPROCESSING = 28,
54 STATS_NUMCLEANUPS = 29,
55 STATS_UNSUPPORTED_DIRECTIVE = 30,
56 STATS_ZEROTIMESTAMP = 31,
61 #define SLOPPY_INCLUDE_FILE_MTIME 1
62 #define SLOPPY_INCLUDE_FILE_CTIME 2
63 #define SLOPPY_FILE_MACRO 4
64 #define SLOPPY_TIME_MACROS 8
65 #define SLOPPY_PCH_DEFINES 16
66 // Allow us to match files based on their stats (size, mtime, ctime), without
67 // looking at their contents.
68 #define SLOPPY_FILE_STAT_MATCHES 32
69 // Allow us to not include any system headers in the manifest include files,
70 // similar to -MM versus -M for dependencies.
71 #define SLOPPY_NO_SYSTEM_HEADERS 64
73 #define str_eq(s1, s2) (strcmp((s1), (s2)) == 0)
74 #define str_startswith(s, prefix) \
75 (strncmp((s), (prefix), strlen((prefix))) == 0)
76 #define str_endswith(s, suffix) \
77 (strlen(s) >= strlen(suffix) \
78 && str_eq((s) + strlen(s) - strlen(suffix), (suffix)))
79 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
81 // Buffer size for I/O operations. Should be a multiple of 4 KiB.
82 #define READ_BUFFER_SIZE 65536
84 // ----------------------------------------------------------------------------
92 struct args *args_init(int, char **);
93 struct args *args_init_from_string(const char *);
94 struct args *args_init_from_gcc_atfile(const char *filename);
95 struct args *args_copy(struct args *args);
96 void args_free(struct args *args);
97 void args_add(struct args *args, const char *s);
98 void args_add_prefix(struct args *args, const char *s);
99 void args_extend(struct args *args, struct args *to_append);
100 void args_insert(struct args *dest, int index, struct args *src, bool replace);
101 void args_pop(struct args *args, int n);
102 void args_set(struct args *args, int index, const char *value);
103 void args_strip(struct args *args, const char *prefix);
104 void args_remove_first(struct args *args);
105 char *args_to_string(struct args *args);
106 bool args_equal(struct args *args1, struct args *args2);
108 // ----------------------------------------------------------------------------
111 void hash_start(struct mdfour *md);
112 void hash_buffer(struct mdfour *md, const void *s, size_t len);
113 char *hash_result(struct mdfour *md);
114 void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
115 bool hash_equal(struct mdfour *md1, struct mdfour *md2);
116 void hash_delimiter(struct mdfour *md, const char *type);
117 void hash_string(struct mdfour *md, const char *s);
118 void hash_string_length(struct mdfour *md, const char *s, int length);
119 void hash_int(struct mdfour *md, int x);
120 bool hash_fd(struct mdfour *md, int fd);
121 bool hash_file(struct mdfour *md, const char *fname);
123 // ----------------------------------------------------------------------------
126 void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
127 void cc_bulklog(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
128 void cc_log_argv(const char *prefix, char **argv);
129 void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2) ATTR_NORETURN;
130 void warn(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
132 void copy_fd(int fd_in, int fd_out);
133 int copy_file(const char *src, const char *dest, int compress_level);
134 int move_file(const char *src, const char *dest, int compress_level);
135 int move_uncompressed_file(const char *src, const char *dest,
137 bool file_is_compressed(const char *filename);
138 int create_dir(const char *dir);
139 int create_parent_dirs(const char *path);
140 const char *get_hostname(void);
141 const char *tmp_string(void);
142 char *format_hash_as_string(const unsigned char *hash, int size);
143 int create_cachedirtag(const char *dir);
144 char *format(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
145 void reformat(char **ptr, const char *format, ...) ATTR_FORMAT(printf, 2, 3);
146 char *x_strdup(const char *s);
147 char *x_strndup(const char *s, size_t n);
148 void *x_malloc(size_t size);
149 void *x_calloc(size_t nmemb, size_t size);
150 void *x_realloc(void *ptr, size_t size);
151 void x_unsetenv(const char *name);
152 int x_fstat(int fd, struct stat *buf);
153 int x_lstat(const char *pathname, struct stat *buf);
154 int x_stat(const char *pathname, struct stat *buf);
155 void traverse(const char *dir, void (*fn)(const char *, struct stat *));
156 char *basename(const char *path);
157 char *dirname(const char *path);
158 const char *get_extension(const char *path);
159 char *remove_extension(const char *path);
160 size_t file_size(struct stat *st);
161 char *format_human_readable_size(uint64_t size);
162 char *format_parsable_size_with_suffix(uint64_t size);
163 bool parse_size_with_suffix(const char *str, uint64_t *size);
164 char *x_realpath(const char *path);
165 char *gnu_getcwd(void);
166 #ifndef HAVE_STRTOK_R
167 char *strtok_r(char *str, const char *delim, char **saveptr);
169 int create_tmp_fd(char **fname);
170 FILE *create_tmp_file(char **fname, const char *mode);
171 const char *get_home_directory(void);
173 bool same_executable_name(const char *s1, const char *s2);
174 size_t common_dir_prefix_length(const char *s1, const char *s2);
175 char *get_relative_path(const char *from, const char *to);
176 bool is_absolute_path(const char *path);
177 bool is_full_path(const char *path);
178 bool is_symlink(const char *path);
179 void update_mtime(const char *path);
180 void x_exit(int status) ATTR_NORETURN;
181 int x_rename(const char *oldpath, const char *newpath);
182 int tmp_unlink(const char *path);
183 int x_unlink(const char *path);
185 char *x_readlink(const char *path);
187 bool read_file(const char *path, size_t size_hint, char **data, size_t *size);
188 char *read_text_file(const char *path, size_t size_hint);
189 char *subst_env_in_string(const char *str, char **errmsg);
190 void set_cloexec_flag(int fd);
192 // ----------------------------------------------------------------------------
195 void stats_update(enum stats stat);
196 void stats_flush(void);
197 unsigned stats_get_pending(enum stats stat);
198 void stats_zero(void);
199 void stats_summary(struct conf *conf);
200 void stats_update_size(int64_t size, int files);
201 void stats_get_obsolete_limits(const char *dir, unsigned *maxfiles,
203 void stats_set_sizes(const char *dir, unsigned num_files, uint64_t total_size);
204 void stats_add_cleanup(const char *dir, unsigned count);
205 void stats_timestamp(time_t time, struct counters *counters);
206 void stats_read(const char *path, struct counters *counters);
207 void stats_write(const char *path, struct counters *counters);
209 // ----------------------------------------------------------------------------
212 int unify_hash(struct mdfour *hash, const char *fname, bool print);
214 // ----------------------------------------------------------------------------
217 void exitfn_init(void);
218 void exitfn_add_nullary(void (*function)(void));
219 void exitfn_add(void (*function)(void *), void *context);
220 void exitfn_call(void);
222 // ----------------------------------------------------------------------------
225 void clean_up_dir(struct conf *conf, const char *dir, float limit_multiple);
226 void clean_up_all(struct conf *conf);
227 void wipe_all(struct conf *conf);
229 // ----------------------------------------------------------------------------
232 int execute(char **argv, int fd_out, int fd_err, pid_t *pid);
233 char *find_executable(const char *name, const char *exclude_name);
234 void print_command(FILE *fp, char **argv);
236 // ----------------------------------------------------------------------------
239 bool lockfile_acquire(const char *path, unsigned staleness_limit);
240 void lockfile_release(const char *path);
242 // ----------------------------------------------------------------------------
245 extern time_t time_of_compilation;
246 extern bool output_is_precompiled_header;
247 void block_signals(void);
248 void unblock_signals(void);
249 bool cc_process_args(struct args *args, struct args **preprocessor_args,
250 struct args **compiler_args);
252 bool is_precompiled_header(const char *path);
254 // ----------------------------------------------------------------------------
257 #define COMPAR_FN_T __compar_fn_t
259 typedef int (*COMPAR_FN_T)(const void *, const void *);
262 // Work with silly DOS binary open.
267 // mkstemp() on some versions of cygwin don't handle binary files, so override.
273 char *win32argvtos(char *prefix, char **argv);
274 char *win32getshell(char *path);
275 int win32execute(char *path, char **argv, int doreturn,
276 int fd_stdout, int fd_stderr);
277 void add_exe_ext_if_no_to_fullpath(char *full_path_win_ext, size_t max_size,
278 const char *ext, const char *path);
279 # ifndef _WIN32_WINNT
280 # define _WIN32_WINNT 0x0501
282 # include <windows.h>
283 # define mkdir(a,b) mkdir(a)
284 # define link(src,dst) (CreateHardLink(dst,src,NULL) ? 0 : -1)
285 # define lstat(a,b) stat(a,b)
286 # define execv(a,b) win32execute(a,b,0,-1,-1)
287 # define execute(a,b,c,d) win32execute(*(a),a,1,b,c)
288 # define DIR_DELIM_CH '\\'
289 # define PATH_DELIM ";"
293 # define DIR_DELIM_CH '/'
294 # define PATH_DELIM ":"
298 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
301 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
304 #endif // ifndef CCACHE_H