2009-11-14 15:14:55 +00:00
|
|
|
#ifndef CCACHE_H
|
|
|
|
#define CCACHE_H
|
|
|
|
|
2002-03-31 09:02:21 +00:00
|
|
|
#include "config.h"
|
2010-02-17 19:53:05 +00:00
|
|
|
#include "mdfour.h"
|
2002-03-26 14:46:43 +00:00
|
|
|
|
2010-02-26 21:15:26 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2005-07-25 07:05:46 +00:00
|
|
|
#include <sys/file.h>
|
2010-02-26 21:15:26 +00:00
|
|
|
#include <unistd.h>
|
2010-02-26 21:34:56 +00:00
|
|
|
#include <stdarg.h>
|
2010-05-09 20:19:22 +00:00
|
|
|
#include <stdio.h>
|
2009-11-01 18:39:58 +00:00
|
|
|
|
2009-11-02 17:11:35 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define ATTR_FORMAT(x, y, z) __attribute__((format (x, y, z)))
|
|
|
|
#else
|
|
|
|
#define ATTR_FORMAT(x, y, z)
|
|
|
|
#endif
|
|
|
|
|
2010-01-20 18:29:59 +00:00
|
|
|
#ifndef MYNAME
|
2002-03-30 00:24:23 +00:00
|
|
|
#define MYNAME "ccache"
|
2010-01-20 18:29:59 +00:00
|
|
|
#endif
|
2002-03-30 00:24:23 +00:00
|
|
|
|
2010-06-09 19:10:03 +00:00
|
|
|
extern const char CCACHE_VERSION[];
|
|
|
|
|
2009-11-14 15:14:55 +00:00
|
|
|
/* statistics fields in storage order */
|
2002-03-30 10:43:26 +00:00
|
|
|
enum stats {
|
|
|
|
STATS_NONE=0,
|
|
|
|
STATS_STDOUT,
|
|
|
|
STATS_STATUS,
|
|
|
|
STATS_ERROR,
|
|
|
|
STATS_TOCACHE,
|
|
|
|
STATS_PREPROCESSOR,
|
|
|
|
STATS_COMPILER,
|
|
|
|
STATS_MISSING,
|
2009-11-14 15:14:55 +00:00
|
|
|
STATS_CACHEHIT_CPP,
|
2002-03-30 10:43:26 +00:00
|
|
|
STATS_ARGS,
|
|
|
|
STATS_LINK,
|
|
|
|
STATS_NUMFILES,
|
|
|
|
STATS_TOTALSIZE,
|
|
|
|
STATS_MAXFILES,
|
|
|
|
STATS_MAXSIZE,
|
2010-06-03 20:07:39 +00:00
|
|
|
STATS_SOURCELANG,
|
2002-04-01 02:59:06 +00:00
|
|
|
STATS_DEVICE,
|
|
|
|
STATS_NOINPUT,
|
2002-04-08 00:43:58 +00:00
|
|
|
STATS_MULTIPLE,
|
2002-04-10 07:52:52 +00:00
|
|
|
STATS_CONFTEST,
|
2002-04-24 12:07:37 +00:00
|
|
|
STATS_UNSUPPORTED,
|
2003-01-07 05:06:07 +00:00
|
|
|
STATS_OUTSTDOUT,
|
2009-11-14 15:14:55 +00:00
|
|
|
STATS_CACHEHIT_DIR,
|
2010-02-22 07:36:40 +00:00
|
|
|
STATS_NOOUTPUT,
|
|
|
|
STATS_EMPTYOUTPUT,
|
2010-04-28 20:30:55 +00:00
|
|
|
STATS_BADEXTRAFILE,
|
2002-03-30 10:43:26 +00:00
|
|
|
|
|
|
|
STATS_END
|
|
|
|
};
|
|
|
|
|
2010-05-17 20:29:42 +00:00
|
|
|
#define SLOPPY_INCLUDE_FILE_MTIME 1
|
|
|
|
#define SLOPPY_FILE_MACRO 2
|
|
|
|
#define SLOPPY_TIME_MACROS 4
|
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* hash.c */
|
|
|
|
|
2009-11-08 19:13:27 +00:00
|
|
|
void hash_start(struct mdfour *md);
|
2010-05-05 20:16:28 +00:00
|
|
|
void hash_delimiter(struct mdfour *md, const char* type);
|
2009-11-08 19:13:27 +00:00
|
|
|
void hash_string(struct mdfour *md, const char *s);
|
|
|
|
void hash_int(struct mdfour *md, int x);
|
2009-11-14 15:14:55 +00:00
|
|
|
int hash_fd(struct mdfour *md, int fd);
|
|
|
|
int hash_file(struct mdfour *md, const char *fname);
|
2009-11-08 19:13:27 +00:00
|
|
|
char *hash_result(struct mdfour *md);
|
2009-11-14 15:14:55 +00:00
|
|
|
void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
|
2010-04-27 06:18:16 +00:00
|
|
|
void hash_buffer(struct mdfour *md, const void *s, size_t len);
|
2002-03-26 14:46:43 +00:00
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* util.c */
|
|
|
|
|
2010-05-10 16:30:17 +00:00
|
|
|
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
|
|
|
void cc_log_executed_command(char **argv);
|
2009-11-12 18:58:09 +00:00
|
|
|
void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
2002-03-26 14:46:43 +00:00
|
|
|
|
|
|
|
void copy_fd(int fd_in, int fd_out);
|
2009-12-06 15:14:45 +00:00
|
|
|
int copy_file(const char *src, const char *dest, int compress_dest);
|
|
|
|
int move_file(const char *src, const char *dest, int compress_dest);
|
2010-05-09 15:50:20 +00:00
|
|
|
int move_uncompressed_file(const char *src, const char *dest,
|
2010-07-18 09:03:17 +00:00
|
|
|
int compress_dest);
|
2009-11-01 18:39:58 +00:00
|
|
|
int test_if_compressed(const char *filename);
|
2002-03-26 14:46:43 +00:00
|
|
|
|
2002-03-26 22:25:14 +00:00
|
|
|
int create_dir(const char *dir);
|
2010-05-09 11:12:32 +00:00
|
|
|
const char *get_hostname(void);
|
2009-11-14 15:14:55 +00:00
|
|
|
const char *tmp_string(void);
|
2010-03-18 11:59:24 +00:00
|
|
|
char *format_hash_as_string(const unsigned char *hash, unsigned size);
|
2009-11-14 15:14:55 +00:00
|
|
|
int create_hash_dir(char **dir, const char *hash, const char *cache_dir);
|
2009-11-01 18:39:58 +00:00
|
|
|
int create_cachedirtag(const char *dir);
|
2010-07-17 20:51:29 +00:00
|
|
|
char *format(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
2002-03-27 01:38:55 +00:00
|
|
|
char *x_strdup(const char *s);
|
2009-11-14 15:14:55 +00:00
|
|
|
char *x_strndup(const char *s, size_t n);
|
2002-03-28 05:37:27 +00:00
|
|
|
void *x_realloc(void *ptr, size_t size);
|
|
|
|
void *x_malloc(size_t size);
|
|
|
|
void traverse(const char *dir, void (*fn)(const char *, struct stat *));
|
2010-02-28 15:30:08 +00:00
|
|
|
char *basename(const char *s);
|
2002-03-30 10:43:26 +00:00
|
|
|
char *dirname(char *s);
|
2010-02-28 17:23:07 +00:00
|
|
|
const char *get_extension(const char *path);
|
2010-02-28 15:22:51 +00:00
|
|
|
char *remove_extension(const char *path);
|
2009-11-14 15:14:55 +00:00
|
|
|
int read_lock_fd(int fd);
|
|
|
|
int write_lock_fd(int fd);
|
2002-03-30 10:43:26 +00:00
|
|
|
size_t file_size(struct stat *st);
|
|
|
|
int safe_open(const char *fname);
|
2002-03-31 05:01:05 +00:00
|
|
|
char *x_realpath(const char *path);
|
2003-01-07 05:39:37 +00:00
|
|
|
char *gnu_getcwd(void);
|
2003-09-25 05:41:17 +00:00
|
|
|
int create_empty_file(const char *fname);
|
2004-09-06 12:59:12 +00:00
|
|
|
const char *get_home_directory(void);
|
2009-11-26 22:36:19 +00:00
|
|
|
char *get_cwd();
|
2010-07-15 18:18:34 +00:00
|
|
|
int compare_executable_name(const char *s1, const char *s2);
|
2009-11-26 22:36:19 +00:00
|
|
|
size_t common_dir_prefix_length(const char *s1, const char *s2);
|
|
|
|
char *get_relative_path(const char *from, const char *to);
|
2010-07-15 18:05:22 +00:00
|
|
|
int is_absolute_path(const char *path);
|
2010-07-16 19:54:14 +00:00
|
|
|
int is_full_path(const char *path);
|
2010-02-17 19:08:13 +00:00
|
|
|
void update_mtime(const char *path);
|
2010-07-15 17:38:13 +00:00
|
|
|
void *x_fmmap(const char *fname, off_t *size, const char *errstr);
|
|
|
|
int x_munmap(void *addr, size_t length);
|
2002-03-30 10:43:26 +00:00
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* stats.c */
|
|
|
|
|
2002-03-30 10:43:26 +00:00
|
|
|
void stats_update(enum stats stat);
|
2010-07-14 13:57:57 +00:00
|
|
|
void stats_flush(void);
|
2010-07-15 14:57:12 +00:00
|
|
|
unsigned stats_get_pending(enum stats stat);
|
2002-03-30 10:43:26 +00:00
|
|
|
void stats_zero(void);
|
|
|
|
void stats_summary(void);
|
2010-06-08 21:12:24 +00:00
|
|
|
void stats_update_size(enum stats stat, size_t size, unsigned files);
|
2002-03-30 10:43:26 +00:00
|
|
|
void stats_read(const char *stats_file, unsigned counters[STATS_END]);
|
2009-11-01 18:39:58 +00:00
|
|
|
int stats_set_limits(long maxfiles, long maxsize);
|
2002-03-30 10:43:26 +00:00
|
|
|
size_t value_units(const char *s);
|
2010-02-27 13:01:14 +00:00
|
|
|
char *format_size(size_t v);
|
2002-03-30 10:43:26 +00:00
|
|
|
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
|
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* unify.c */
|
|
|
|
|
2009-11-08 19:13:27 +00:00
|
|
|
int unify_hash(struct mdfour *hash, const char *fname);
|
2002-04-01 00:23:31 +00:00
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* exitfn.c */
|
|
|
|
|
2010-07-14 16:13:23 +00:00
|
|
|
void exitfn_init(void);
|
|
|
|
void exitfn_add_nullary(void (*function)(void));
|
|
|
|
void exitfn_add(void (*function)(void *), void *context);
|
|
|
|
void exitfn_call(void);
|
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* snprintf.c */
|
|
|
|
|
2002-04-06 06:48:28 +00:00
|
|
|
#ifndef HAVE_VASPRINTF
|
2009-11-02 17:11:35 +00:00
|
|
|
int vasprintf(char **, const char *, va_list) ATTR_FORMAT(printf, 2, 0);
|
2002-04-06 06:48:28 +00:00
|
|
|
#endif
|
2003-09-25 06:11:28 +00:00
|
|
|
#ifndef HAVE_ASPRINTF
|
2009-11-02 17:11:35 +00:00
|
|
|
int asprintf(char **ptr, const char *, ...) ATTR_FORMAT(printf, 2, 3);
|
2003-09-25 06:11:28 +00:00
|
|
|
#endif
|
2002-03-31 14:26:49 +00:00
|
|
|
|
2002-04-06 06:48:28 +00:00
|
|
|
#ifndef HAVE_SNPRINTF
|
2009-11-02 17:11:35 +00:00
|
|
|
int snprintf(char *, size_t, const char *, ...) ATTR_FORMAT(printf, 3, 4);
|
2002-04-06 06:48:28 +00:00
|
|
|
#endif
|
2002-03-30 10:43:26 +00:00
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* cleanup.c */
|
|
|
|
|
2002-03-30 10:43:26 +00:00
|
|
|
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize);
|
|
|
|
void cleanup_all(const char *dir);
|
2002-06-03 03:22:17 +00:00
|
|
|
void wipe_all(const char *dir);
|
2002-03-26 22:25:14 +00:00
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* execute.c */
|
|
|
|
|
2009-11-07 08:09:39 +00:00
|
|
|
int execute(char **argv,
|
2010-07-18 09:03:17 +00:00
|
|
|
const char *path_stdout,
|
|
|
|
const char *path_stderr);
|
2003-02-16 02:28:35 +00:00
|
|
|
char *find_executable(const char *name, const char *exclude_name);
|
2010-05-09 20:19:22 +00:00
|
|
|
void print_command(FILE *fp, char **argv);
|
|
|
|
void print_executed_command(FILE *fp, char **argv);
|
2002-03-26 14:46:43 +00:00
|
|
|
|
2010-07-17 14:58:55 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
2010-07-18 09:03:17 +00:00
|
|
|
/* args.c */
|
2010-07-17 14:58:55 +00:00
|
|
|
|
|
|
|
struct args {
|
2002-03-26 14:46:43 +00:00
|
|
|
char **argv;
|
|
|
|
int argc;
|
2010-07-17 14:58:55 +00:00
|
|
|
};
|
2002-03-26 14:46:43 +00:00
|
|
|
|
2010-07-17 14:58:55 +00:00
|
|
|
struct args *args_init(int, char **);
|
|
|
|
struct args *args_init_from_string(const char *);
|
|
|
|
struct args *args_copy(struct args *args);
|
|
|
|
void args_free(struct args *args);
|
|
|
|
void args_add(struct args *args, const char *s);
|
|
|
|
void args_add_prefix(struct args *args, const char *s);
|
2010-07-17 16:49:12 +00:00
|
|
|
void args_extend(struct args *args, struct args *to_append);
|
2010-07-17 14:58:55 +00:00
|
|
|
void args_pop(struct args *args, int n);
|
|
|
|
void args_strip(struct args *args, const char *prefix);
|
|
|
|
void args_remove_first(struct args *args);
|
|
|
|
char *args_to_string(struct args *args);
|
|
|
|
int args_equal(struct args *args1, struct args *args2);
|
2002-03-26 14:46:43 +00:00
|
|
|
|
2010-07-17 14:58:55 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
2010-07-18 09:03:17 +00:00
|
|
|
/* ccache.c */
|
2002-03-27 08:40:13 +00:00
|
|
|
|
2010-07-18 09:03:17 +00:00
|
|
|
int cc_process_args(struct args *orig_args, struct args **preprocessor_args,
|
|
|
|
struct args **compiler_args);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2010-07-14 08:59:27 +00:00
|
|
|
|
2002-04-06 06:45:31 +00:00
|
|
|
#if HAVE_COMPAR_FN_T
|
|
|
|
#define COMPAR_FN_T __compar_fn_t
|
|
|
|
#else
|
|
|
|
typedef int (*COMPAR_FN_T)(const void *, const void *);
|
|
|
|
#endif
|
2004-09-06 12:24:05 +00:00
|
|
|
|
|
|
|
/* work with silly DOS binary open */
|
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* mkstemp() on some versions of cygwin don't handle binary files, so
|
|
|
|
override */
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
#undef HAVE_MKSTEMP
|
|
|
|
#endif
|
2009-11-14 15:14:55 +00:00
|
|
|
|
2010-07-16 19:56:43 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
int win32execute(char *path, char **argv, int doreturn,
|
|
|
|
const char *path_stdout, const char *path_stderr);
|
|
|
|
# ifndef _WIN32_WINNT
|
|
|
|
# define _WIN32_WINNT 0x0501
|
|
|
|
# endif
|
|
|
|
# include <windows.h>
|
|
|
|
# define mkdir(a,b) mkdir(a)
|
|
|
|
# define link(src,dst) (CreateHardLink(dst,src,NULL) ? 0 : -1)
|
|
|
|
# define lstat(a,b) stat(a,b)
|
|
|
|
# define execv(a,b) win32execute(a,b,0,NULL,NULL)
|
|
|
|
# define execute(a,b,c) win32execute(*(a),a,1,b,c)
|
|
|
|
# define PATH_DELIM ";"
|
|
|
|
# define F_RDLCK 0
|
|
|
|
# define F_WRLCK 0
|
|
|
|
#else
|
|
|
|
# define PATH_DELIM ":"
|
|
|
|
#endif
|
2010-07-15 18:48:10 +00:00
|
|
|
|
2009-11-14 15:14:55 +00:00
|
|
|
#endif /* ifndef CCACHE_H */
|