From: Joel Rosdahl Date: Tue, 2 Oct 2018 19:33:27 +0000 (+0200) Subject: Merge remote-tracking branch 'afbjorklund/everything' X-Git-Tag: v3.5~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d8e9896c088d2e5889404f9131dbdbe0ec5b1db;p=thirdparty%2Fccache.git Merge remote-tracking branch 'afbjorklund/everything' * afbjorklund/everything: Make configure work with older clang versions Add option for enabling more compiler warnings Add configure support for detecting clang Avoid bad function cast by using temporary Proper use of const qualifier char* strings Removed locally shadowed global variables Don't use undefined macros, use ifdef instead Add noreturn to functions that don't return Add missing extern prototypes, or make static Don't use reserved id macros in the headers Only compile getopt_long.c when needed Address issues found by lgtm.com alerts --- 5d8e9896c088d2e5889404f9131dbdbe0ec5b1db diff --cc src/ccache.c index a5d04cf2d,5d893d93e..6634554b4 --- a/src/ccache.c +++ b/src/ccache.c @@@ -33,41 -33,53 +33,53 @@@ #define STRINGIFY(x) #x #define TO_STRING(x) STRINGIFY(x) + extern struct conf *conf; + extern char *primary_config_path; + extern char *secondary_config_path; + extern char *current_working_dir; + extern char *stats_file; + extern unsigned lock_staleness_limit; + + static void failed(void) ATTR_NORETURN; + static void ccache(int argc, char *argv[]) ATTR_NORETURN; + + int ccache_main(int argc, char *argv[]); + static const char VERSION_TEXT[] = - MYNAME " version %s\n" - "\n" - "Copyright (C) 2002-2007 Andrew Tridgell\n" - "Copyright (C) 2009-2018 Joel Rosdahl\n" - "\n" - "This program is free software; you can redistribute it and/or modify it under\n" - "the terms of the GNU General Public License as published by the Free Software\n" - "Foundation; either version 3 of the License, or (at your option) any later\n" - "version.\n"; + MYNAME " version %s\n" + "\n" + "Copyright (C) 2002-2007 Andrew Tridgell\n" + "Copyright (C) 2009-2018 Joel Rosdahl\n" + "\n" + "This program is free software; you can redistribute it and/or modify it under\n" + "the terms of the GNU General Public License as published by the Free Software\n" + "Foundation; either version 3 of the License, or (at your option) any later\n" + "version.\n"; static const char USAGE_TEXT[] = - "Usage:\n" - " " MYNAME " [options]\n" - " " MYNAME " compiler [compiler options]\n" - " compiler [compiler options] (via symbolic link)\n" - "\n" - "Options:\n" - " -c, --cleanup delete old files and recalculate size counters\n" - " (normally not needed as this is done automatically)\n" - " -C, --clear clear the cache completely (except configuration)\n" - " -F, --max-files=N set maximum number of files in cache to N (use 0 for\n" - " no limit)\n" - " -M, --max-size=SIZE set maximum size of cache to SIZE (use 0 for no\n" - " limit); available suffixes: k, M, G, T (decimal) and\n" - " Ki, Mi, Gi, Ti (binary); default suffix: G\n" - " -o, --set-config=K=V set configuration key K to value V\n" - " -p, --print-config print current configuration options\n" - " -s, --show-stats show statistics summary\n" - " -z, --zero-stats zero statistics counters\n" - "\n" - " -h, --help print this help text\n" - " -V, --version print version and copyright information\n" - "\n" - "See also .\n"; + "Usage:\n" + " " MYNAME " [options]\n" + " " MYNAME " compiler [compiler options]\n" + " compiler [compiler options] (via symbolic link)\n" + "\n" + "Options:\n" + " -c, --cleanup delete old files and recalculate size counters\n" + " (normally not needed as this is done automatically)\n" + " -C, --clear clear the cache completely (except configuration)\n" + " -F, --max-files=N set maximum number of files in cache to N (use 0 for\n" + " no limit)\n" + " -M, --max-size=SIZE set maximum size of cache to SIZE (use 0 for no\n" + " limit); available suffixes: k, M, G, T (decimal) and\n" + " Ki, Mi, Gi, Ti (binary); default suffix: G\n" + " -o, --set-config=K=V set configuration key K to value V\n" + " -p, --print-config print current configuration options\n" + " -s, --show-stats show statistics summary\n" + " -z, --zero-stats zero statistics counters\n" + "\n" + " -h, --help print this help text\n" + " -V, --version print version and copyright information\n" + "\n" + "See also .\n"; // Global configuration data. struct conf *conf = NULL; diff --cc src/hash.c index f58d8f6b7,fec5f7065..0205143f7 --- a/src/hash.c +++ b/src/hash.c @@@ -18,68 -18,6 +18,68 @@@ #include "ccache.h" #define HASH_DELIMITER "\000cCaChE" +#define HASH_DEBUG_DELIMITER "### " + +// binary input, for hashing +static char *debug_hash_bin; + +// text input, for debugging +static char *debug_hash_txt; + +// char mapping to open files +static FILE **debug_hash_file; + +void hash_debug_init(const char *bin, const char *txt) +{ + debug_hash_file = x_calloc(256, sizeof(FILE *)); + static char *hash_types = "cdp"; // common, direct, cpp + if (bin) { + debug_hash_bin = x_strdup(bin); + assert(debug_hash_bin[strlen(debug_hash_bin)-1] == 'X'); + for (char *p = hash_types; *p != '\0'; p++) { + debug_hash_bin[strlen(debug_hash_bin)-1] = *p; + debug_hash_file[(int) *p] = fopen(debug_hash_bin, "wb"); + } + debug_hash_bin[strlen(debug_hash_bin)-1] = 'X'; + } + if (txt) { + debug_hash_txt = x_strdup(txt); + debug_hash_file[(int) 't'] = fopen(debug_hash_txt, "w"); + } +} + +void hash_debug_end() +{ + for (int i = 0; i < 256; i++) { + if (debug_hash_file[i] != NULL) { + fclose(debug_hash_file[i]); + } + } +} + +static void +hash_binary_buffer(struct mdfour *md, const void *s, size_t len) +{ - mdfour_update(md, (unsigned char *)s, len); ++ mdfour_update(md, (const unsigned char *)s, len); + if (!md->identifier || len == 0) { + return; + } + if (debug_hash_bin) { + // log to different files, for the different hash types + fwrite(s, 1, len, debug_hash_file[md->identifier]); + } +} + +static void +hash_debug_buffer(struct mdfour *md, const void *s, size_t len) +{ + if (!md->identifier || len == 0) { + return; + } + if (debug_hash_txt) { + fwrite(s, 1, len, debug_hash_file['t']); + } +} void hash_start(struct mdfour *md) diff --cc src/util.c index cac8415cf,52d162513..6b87b9437 --- a/src/util.c +++ b/src/util.c @@@ -632,11 -580,11 +634,11 @@@ format_hash_as_string(const unsigned ch return ret; } - char const CACHEDIR_TAG[] = + static char const CACHEDIR_TAG[] = - "Signature: 8a477f597d28d172789f06886806bc55\n" - "# This file is a cache directory tag created by ccache.\n" - "# For information about cache directory tags, see:\n" - "#\thttp://www.brynosaurus.com/cachedir/\n"; + "Signature: 8a477f597d28d172789f06886806bc55\n" + "# This file is a cache directory tag created by ccache.\n" + "# For information about cache directory tags, see:\n" + "#\thttp://www.brynosaurus.com/cachedir/\n"; int create_cachedirtag(const char *dir) diff --cc unittest/main.c index d3edd49e7,e2da341dd..e3299b00e --- a/unittest/main.c +++ b/unittest/main.c @@@ -27,13 -27,13 +27,13 @@@ #undef SUITE // *INDENT-ON* enable uncrustify - const char USAGE_TEXT[] = + static const char USAGE_TEXT[] = - "Usage:\n" - " test [options]\n" - "\n" - "Options:\n" - " -h, --help print this help text\n" - " -v, --verbose enable verbose logging of tests\n"; + "Usage:\n" + " test [options]\n" + "\n" + "Options:\n" + " -h, --help print this help text\n" + " -v, --verbose enable verbose logging of tests\n"; int main(int argc, char **argv) diff --cc unittest/test_conf.c index 802331536,bb3f95ce5..2028ddc8c --- a/unittest/test_conf.c +++ b/unittest/test_conf.c @@@ -18,10 -18,10 +18,10 @@@ #include "framework.h" #include "util.h" -#define N_CONFIG_ITEMS 32 +#define N_CONFIG_ITEMS 33 static struct { char *descr; - const char *origin; + char *origin; } received_conf_items[N_CONFIG_ITEMS]; static size_t n_received_conf_items = 0;