/* ------------------------------------------------------------------------- */
/* util.c */
+void cc_vlog(const char *format, va_list ap);
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
+void cc_bulklog(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void cc_log_argv(const char *prefix, char **argv);
- void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
+ void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2) ATTR_NORETURN;
+
void copy_fd(int fd_in, int fd_out);
-int copy_file(const char *src, const char *dest, int compress_dest);
-int move_file(const char *src, const char *dest, int compress_dest);
+int copy_file(const char *src, const char *dest, int compress_level);
+int move_file(const char *src, const char *dest, int compress_level);
int move_uncompressed_file(const char *src, const char *dest,
- int compress_dest);
+ int compress_level);
bool file_is_compressed(const char *filename);
-
int create_dir(const char *dir);
+int create_parent_dirs(const char *path);
const char *get_hostname(void);
const char *tmp_string(void);
-char *format_hash_as_string(const unsigned char *hash, unsigned size);
-int create_hash_dir(char **dir, const char *hash, const char *cache_dir);
+char *format_hash_as_string(const unsigned char *hash, int size);
int create_cachedirtag(const char *dir);
char *format(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
+void reformat(char **ptr, const char *format, ...) ATTR_FORMAT(printf, 2, 3);
char *x_strdup(const char *s);
char *x_strndup(const char *s, size_t n);
-void *x_realloc(void *ptr, size_t size);
void *x_malloc(size_t size);
void *x_calloc(size_t nmemb, size_t size);
+void *x_realloc(void *ptr, size_t size);
+void x_unsetenv(const char *name);
void traverse(const char *dir, void (*fn)(const char *, struct stat *));
-char *basename(const char *s);
-char *dirname(char *s);
+char *basename(const char *path);
+char *dirname(const char *path);
const char *get_extension(const char *path);
char *remove_extension(const char *path);
size_t file_size(struct stat *st);
*/
static const uint32_t MAGIC = 0x63436d46U;
-static const uint8_t VERSION = 0;
static const uint32_t MAX_MANIFEST_ENTRIES = 100;
+ static const uint32_t MAX_MANIFEST_FILE_INFO_ENTRIES = 10000;
#define ccache_static_assert(e) \
- do { enum { ccache_static_assert__ = 1/(e) }; } while (0)
+ do { enum { ccache_static_assert__ = 1/(e) }; } while (false)
struct file_info {
/* Index to n_files. */
read_manifest(gzFile f)
{
struct manifest *mf;
- uint16_t i, j;
+ uint32_t i, j;
uint32_t magic;
- uint8_t version;
- uint16_t dummy;
mf = create_empty_manifest();
static int
write_manifest(gzFile f, const struct manifest *mf)
{
- uint16_t i, j;
+ uint32_t i, j;
WRITE_INT(4, MAGIC);
- WRITE_INT(1, VERSION);
+ WRITE_INT(1, MANIFEST_VERSION);
WRITE_INT(1, 16);
WRITE_INT(2, 0);
/*
++<<<<<<< HEAD
+ * Copyright (C) 2010-2013 Joel Rosdahl
++=======
+ * Copyright (C) 2010, 2012-2014 Joel Rosdahl
++>>>>>>> maint
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
TEST(common_dir_prefix_length)
{
- CHECK_UNS_EQ(0, common_dir_prefix_length("", ""));
- CHECK_UNS_EQ(0, common_dir_prefix_length("/", "/"));
- CHECK_UNS_EQ(0, common_dir_prefix_length("/", "/b"));
- CHECK_UNS_EQ(0, common_dir_prefix_length("/a", "/b"));
- CHECK_UNS_EQ(2, common_dir_prefix_length("/a", "/a"));
- CHECK_UNS_EQ(2, common_dir_prefix_length("/a", "/a/b"));
- CHECK_UNS_EQ(2, common_dir_prefix_length("/a/b", "/a/c"));
- CHECK_UNS_EQ(4, common_dir_prefix_length("/a/b", "/a/b"));
+ CHECK_INT_EQ(0, common_dir_prefix_length("", ""));
+ CHECK_INT_EQ(0, common_dir_prefix_length("/", "/"));
+ CHECK_INT_EQ(0, common_dir_prefix_length("/", "/b"));
+ CHECK_INT_EQ(0, common_dir_prefix_length("/a", "/b"));
+ CHECK_INT_EQ(2, common_dir_prefix_length("/a", "/a"));
+ CHECK_INT_EQ(2, common_dir_prefix_length("/a", "/a/b"));
+ CHECK_INT_EQ(2, common_dir_prefix_length("/a/b", "/a/c"));
+ CHECK_INT_EQ(4, common_dir_prefix_length("/a/b", "/a/b"));
+ CHECK_INT_EQ(2, common_dir_prefix_length("/a/bc", "/a/b"));
+ CHECK_INT_EQ(2, common_dir_prefix_length("/a/b", "/a/bc"));
}
TEST(get_relative_path)
#endif
/*
- * Copy src to dest, decompressing src if needed. compress_dest decides whether
- * dest will be compressed.
+ * Copy src to dest, decompressing src if needed. compress_level > 0 decides
+ * whether dest will be compressed, and with which compression level.
*/
int
-copy_file(const char *src, const char *dest, int compress_dest)
+copy_file(const char *src, const char *dest, int compress_level)
{
- int fd_in = -1, fd_out = -1;
+ int fd_in, fd_out;
gzFile gz_in = NULL, gz_out = NULL;
char buf[10240];
int n, written;