ccache/ccache.h

183 lines
4.2 KiB
C
Raw Normal View History

2004-09-08 03:31:57 +00:00
#define CCACHE_VERSION "2.4"
2002-03-26 14:46:43 +00:00
2002-03-31 09:02:21 +00:00
#include "config.h"
2002-03-26 14:46:43 +00:00
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
2005-07-25 07:05:46 +00:00
#include <sys/stat.h>
2002-03-26 14:46:43 +00:00
#include <sys/wait.h>
#include <sys/mman.h>
2002-03-26 14:46:43 +00:00
#include <fcntl.h>
2002-03-27 09:46:40 +00:00
#include <time.h>
2002-03-26 14:46:43 +00:00
#include <string.h>
#include <ctype.h>
#include <utime.h>
2002-03-26 14:46:43 +00:00
#include <stdarg.h>
2002-03-27 09:46:40 +00:00
#include <dirent.h>
#include <limits.h>
2005-07-25 07:05:46 +00:00
#include <sys/file.h>
2004-09-06 12:59:12 +00:00
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
2002-03-26 14:46:43 +00:00
#ifdef ENABLE_ZLIB
#include <zlib.h>
#endif
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
2002-03-26 14:46:43 +00:00
#define STATUS_NOTFOUND 3
#define STATUS_FATAL 4
#define STATUS_NOCACHE 5
#define MYNAME "ccache"
#define LIMIT_MULTIPLE 0.8
2003-01-07 03:45:39 +00:00
/* default maximum cache size */
#ifndef DEFAULT_MAXSIZE
#define DEFAULT_MAXSIZE (1000*1000)
#endif
/* file copy mode */
#ifdef ENABLE_ZLIB
#define COPY_UNCOMPRESSED 0
#define COPY_FROM_CACHE 1
#define COPY_TO_CACHE 2
#endif
enum stats {
STATS_NONE=0,
STATS_STDOUT,
STATS_STATUS,
STATS_ERROR,
STATS_TOCACHE,
STATS_PREPROCESSOR,
STATS_COMPILER,
STATS_MISSING,
STATS_CACHED,
STATS_ARGS,
STATS_LINK,
STATS_NUMFILES,
STATS_TOTALSIZE,
STATS_MAXFILES,
STATS_MAXSIZE,
STATS_NOTC,
STATS_DEVICE,
STATS_NOINPUT,
STATS_MULTIPLE,
STATS_CONFTEST,
2002-04-24 12:07:37 +00:00
STATS_UNSUPPORTED,
2003-01-07 05:06:07 +00:00
STATS_OUTSTDOUT,
STATS_END
};
2002-03-26 14:46:43 +00:00
typedef unsigned uint32;
#include "mdfour.h"
void hash_start(struct mdfour *md);
void hash_string(struct mdfour *md, const char *s);
void hash_int(struct mdfour *md, int x);
void hash_file(struct mdfour *md, const char *fname);
char *hash_result(struct mdfour *md);
void hash_buffer(struct mdfour *md, const char *s, int len);
2002-03-26 14:46:43 +00:00
2009-11-02 17:11:35 +00:00
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
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);
int copy_file(const char *src, const char *dest);
int move_file(const char *src, const char *dest);
int test_if_compressed(const char *filename);
2002-03-26 14:46:43 +00:00
int create_dir(const char *dir);
int create_cachedirtag(const char *dir);
2009-11-02 17:11:35 +00:00
void x_asprintf(char **ptr, const char *format, ...) ATTR_FORMAT(printf, 2, 3);
char *x_strdup(const char *s);
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 *));
char *str_basename(const char *s);
char *dirname(char *s);
int lock_fd(int fd);
size_t file_size(struct stat *st);
int safe_open(const char *fname);
char *x_realpath(const char *path);
char *gnu_getcwd(void);
int create_empty_file(const char *fname);
2004-09-06 12:59:12 +00:00
const char *get_home_directory(void);
void stats_update(enum stats stat);
void stats_zero(void);
void stats_summary(void);
void stats_tocache(size_t size);
void stats_read(const char *stats_file, unsigned counters[STATS_END]);
int stats_set_limits(long maxfiles, long maxsize);
size_t value_units(const char *s);
2002-04-01 00:50:03 +00:00
void display_size(unsigned v);
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
int unify_hash(struct mdfour *hash, const char *fname);
2002-04-01 00:23:31 +00:00
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
#ifndef HAVE_ASPRINTF
2009-11-02 17:11:35 +00:00
int asprintf(char **ptr, const char *, ...) ATTR_FORMAT(printf, 2, 3);
#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
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);
2009-11-07 08:09:39 +00:00
int execute(char **argv,
2002-03-27 00:39:06 +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);
2002-03-26 14:46:43 +00:00
typedef struct {
char **argv;
int argc;
} ARGS;
2003-02-16 02:28:35 +00:00
ARGS *args_init(int , char **);
2002-03-26 14:46:43 +00:00
void args_add(ARGS *args, const char *s);
2003-02-16 02:28:35 +00:00
void args_add_prefix(ARGS *args, const char *s);
void args_pop(ARGS *args, int n);
void args_strip(ARGS *args, const char *prefix);
2003-02-16 02:28:35 +00:00
void args_remove_first(ARGS *args);
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
/* 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