]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Use bool, true and false for boolean values
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 29 Aug 2010 11:25:51 +0000 (13:25 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 29 Aug 2010 11:26:55 +0000 (13:26 +0200)
18 files changed:
HACKING.txt
args.c
ccache.c
ccache.h
counters.c
hash.c
hashutil.c
hashutil.h
language.c
language.h
lockfile.c
manifest.c
manifest.h
stats.c
test/util.c
test/util.h
unify.c
util.c

index c8ce5b03423f569b4db0092ce8d4718cd712826d..e0fbe7685b7ff81b6658d5a142a1c37cf5127380 100644 (file)
@@ -26,6 +26,7 @@ Idioms
   allocation failure explicitly.
 * Use str_eq() instead of strcmp() when testing for string (in)equality.
 * Consider using str_startswith() instead of strncmp().
+* Use bool, true and false for boolean values.
 
 Other
 -----
diff --git a/args.c b/args.c
index 234836be4af2f17cfcba4b87e2600567f56cb844..13a3d37c4d133aae402fad7210401b2fed532eaa 100644 (file)
--- a/args.c
+++ b/args.c
@@ -171,19 +171,19 @@ args_to_string(struct args *args)
        return result;
 }
 
-/* Returns 1 if args1 equals args2, else 0. */
-int
+/* Returns true if args1 equals args2, else false. */
+bool
 args_equal(struct args *args1, struct args *args2)
 {
        int i;
        if (args1->argc != args2->argc) {
-               return 0;
+               return false;
        }
        for (i = 0; i < args1->argc; i++) {
                if (!str_eq(args1->argv[i], args2->argv[i])) {
-                       return 0;
+                       return false;
                }
        }
-       return 1;
+       return true;
 }
 
index 9e1516130f8bc89e6fa85155c2cdc26c3fce9e9e..b50708d66993f6bcb8bfe69346f905d951e76587 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -138,7 +138,7 @@ unsigned sloppiness = 0;
 static struct hashtable *included_files;
 
 /* is gcc being asked to output dependencies? */
-static int generating_dependencies;
+static bool generating_dependencies;
 
 /* the extension of the file (without dot) after pre-processing */
 static const char *i_extension;
@@ -147,7 +147,7 @@ static const char *i_extension;
 static char *i_tmpfile;
 
 /* are we compiling a .i or .ii file directly? */
-static int direct_i_file;
+static bool direct_i_file;
 
 /* the name of the cpp stderr file */
 static char *cpp_stderr;
@@ -159,16 +159,16 @@ static char *cpp_stderr;
 char *stats_file = NULL;
 
 /* can we safely use the unification hashing backend? */
-static int enable_unify;
+static bool enable_unify;
 
 /* should we use the direct mode? */
-static int enable_direct = 1;
+static bool enable_direct = true;
 
 /*
  * Whether to enable compression of files stored in the cache. (Manifest files
  * are always compressed.)
  */
-static int enable_compression = 0;
+static bool enable_compression = false;
 
 /* number of levels (1 <= nlevels <= 8) */
 static int nlevels = 2;
@@ -177,10 +177,10 @@ static int nlevels = 2;
  * Whether we should use the optimization of passing the already existing
  * preprocessed source code to the compiler.
  */
-static int compile_preprocessed_source_code;
+static bool compile_preprocessed_source_code;
 
 /* Whether the output is a precompiled header */
-static int output_is_precompiled_header = 0;
+static bool output_is_precompiled_header = false;
 
 /* How long (in microseconds) to wait before breaking a stale lock. */
 unsigned lock_staleness_limit = 2000000;
@@ -348,7 +348,7 @@ remember_include_file(char *path, size_t path_len)
 
 failure:
        cc_log("Disabling direct mode");
-       enable_direct = 0;
+       enable_direct = false;
        /* Fall through. */
 ignore:
        free(path);
@@ -382,7 +382,7 @@ make_relative_path(char *path)
  * - Stores the paths and hashes of included files in the global variable
  *   included_files.
  */
-static int
+static bool
 process_preprocessed_file(struct mdfour *hash, const char *path)
 {
        char *data;
@@ -390,7 +390,7 @@ process_preprocessed_file(struct mdfour *hash, const char *path)
        size_t size;
 
        if (!read_file(path, 32768, &data, &size)) {
-               return 0;
+               return false;
        }
 
        if (enable_direct) {
@@ -439,7 +439,7 @@ process_preprocessed_file(struct mdfour *hash, const char *path)
                        if (q >= end) {
                                cc_log("Failed to parse included file path");
                                free(data);
-                               return 0;
+                               return false;
                        }
                        /* q points to the beginning of an include file path */
                        hash_buffer(hash, p, q - p);
@@ -464,7 +464,7 @@ process_preprocessed_file(struct mdfour *hash, const char *path)
 
        hash_buffer(hash, p, (end - p));
        free(data);
-       return 1;
+       return true;
 }
 
 /* run the real compiler and put the result in cache */
@@ -936,7 +936,7 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode)
                }
                if (result & HASH_SOURCE_CODE_FOUND_TIME) {
                        cc_log("Disabling direct mode");
-                       enable_direct = 0;
+                       enable_direct = false;
                        return NULL;
                }
                manifest_name = hash_result(hash);
@@ -965,12 +965,12 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode)
  * then this function exits with the correct status code, otherwise it returns.
  */
 static void
-from_cache(enum fromcache_call_mode mode, int put_object_in_manifest)
+from_cache(enum fromcache_call_mode mode, bool put_object_in_manifest)
 {
        int fd_stderr;
        int ret;
        struct stat st;
-       int produce_dep_file;
+       bool produce_dep_file;
 
        /* the user might be disabling cache hits */
        if (mode != FROMCACHE_COMPILED_MODE && getenv("CCACHE_RECACHE")) {
@@ -1146,7 +1146,7 @@ find_compiler(int argc, char **argv)
        base = basename(argv[0]);
 
        /* we might be being invoked like "ccache gcc -c foo.c" */
-       if (compare_executable_name(base, MYNAME)) {
+       if (same_executable_name(base, MYNAME)) {
                args_remove_first(orig_args);
                free(base);
                if (is_full_path(argv[1])) {
@@ -1175,7 +1175,7 @@ find_compiler(int argc, char **argv)
        orig_args->argv[0] = compiler;
 }
 
-int
+bool
 is_precompiled_header(const char *path)
 {
        return str_eq(get_extension(path), ".gch");
@@ -1184,30 +1184,30 @@ is_precompiled_header(const char *path)
 /*
  * Process the compiler options into options suitable for passing to the
  * preprocessor and the real compiler. The preprocessor options don't include
- * -E; this is added later. Returns 0 on failure, otherwise 1.
+ * -E; this is added later. Returns true on success, otherwise false.
  */
-int
+bool
 cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                 struct args **compiler_args)
 {
        int i;
-       int found_c_opt = 0;
-       int found_S_opt = 0;
-       int found_arch_opt = 0;
-       int found_pch = 0;
+       bool found_c_opt = false;
+       bool found_S_opt = false;
+       bool found_arch_opt = false;
+       bool found_pch = false;
        const char *explicit_language = NULL; /* As specified with -x. */
        const char *file_language;            /* As deduced from file extension. */
        const char *actual_language;          /* Language to actually use. */
        const char *input_charset = NULL;
        struct stat st;
        /* is the dependency makefile name overridden with -MF? */
-       int dependency_filename_specified = 0;
+       bool dependency_filename_specified = false;
        /* is the dependency makefile target name specified with -MT or -MQ? */
-       int dependency_target_specified = 0;
+       bool dependency_target_specified = false;
        struct args *stripped_args = NULL, *dep_args = NULL;
        int argc = orig_args->argc;
        char **argv = orig_args->argv;
-       int result = 1;
+       bool result = true;
 
        stripped_args = args_init(0, NULL);
        dep_args = args_init(0, NULL);
@@ -1219,7 +1219,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                if (str_eq(argv[i], "-E")) {
                        cc_log("Compiler option -E is unsupported");
                        stats_update(STATS_UNSUPPORTED);
-                       result = 0;
+                       result = false;
                        goto out;
                }
 
@@ -1237,7 +1237,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                    str_eq(argv[i], "-save-temps")) {
                        cc_log("Compiler option %s is unsupported", argv[i]);
                        stats_update(STATS_UNSUPPORTED);
-                       result = 0;
+                       result = false;
                        goto out;
                }
 
@@ -1245,7 +1245,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                if (enable_direct) {
                        if (str_eq(argv[i], "-Xpreprocessor")) {
                                cc_log("Unsupported compiler option for direct mode: %s", argv[i]);
-                               enable_direct = 0;
+                               enable_direct = false;
                        }
                }
 
@@ -1254,10 +1254,10 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                        if (found_arch_opt) {
                                cc_log("More than one -arch compiler option is unsupported");
                                stats_update(STATS_UNSUPPORTED);
-                               result = 0;
+                               result = false;
                                goto out;
                        } else {
-                               found_arch_opt = 1;
+                               found_arch_opt = true;
                        }
                }
 
@@ -1266,21 +1266,21 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                        cc_log("You have to specify \"time_macros\" sloppiness when using"
                               " -fpch-preprocess");
                        stats_update(STATS_UNSUPPORTED);
-                       result = 0;
+                       result = false;
                        goto out;
                }
 
                /* we must have -c */
                if (str_eq(argv[i], "-c")) {
                        args_add(stripped_args, argv[i]);
-                       found_c_opt = 1;
+                       found_c_opt = true;
                        continue;
                }
 
                /* -S changes the default extension */
                if (str_eq(argv[i], "-S")) {
                        args_add(stripped_args, argv[i]);
-                       found_S_opt = 1;
+                       found_S_opt = true;
                        continue;
                }
 
@@ -1292,7 +1292,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                        if (i == argc-1) {
                                cc_log("Missing argument to %s", argv[i]);
                                stats_update(STATS_ARGS);
-                               result = 0;
+                               result = false;
                                goto out;
                        }
                        if (!input_file) {
@@ -1313,7 +1313,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                        if (i == argc-1) {
                                cc_log("Missing argument to %s", argv[i]);
                                stats_update(STATS_ARGS);
-                               result = 0;
+                               result = false;
                                goto out;
                        }
                        output_obj = argv[i+1];
@@ -1334,7 +1334,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                        args_add(stripped_args, argv[i]);
                        if (enable_unify && !str_eq(argv[i], "-g0")) {
                                cc_log("%s used; disabling unify mode", argv[i]);
-                               enable_unify = 0;
+                               enable_unify = false;
                        }
                        if (str_eq(argv[i], "-g3")) {
                                /*
@@ -1342,7 +1342,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                                 * have non-zero lineno when using -g3").
                                 */
                                cc_log("%s used; not compiling preprocessed code", argv[i]);
-                               compile_preprocessed_source_code = 0;
+                               compile_preprocessed_source_code = false;
                        }
                        continue;
                }
@@ -1352,7 +1352,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                        i++;
                        if (i == argc) {
                                cc_log("--ccache-skip lacks an argument");
-                               result = 0;
+                               result = false;
                                goto out;
                        }
                        args_add(stripped_args, argv[i]);
@@ -1363,13 +1363,13 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                   behave differently with gcc -E, when the output
                   file is not specified. */
                if (str_eq(argv[i], "-MD") || str_eq(argv[i], "-MMD")) {
-                       generating_dependencies = 1;
+                       generating_dependencies = true;
                        args_add(dep_args, argv[i]);
                        continue;
                }
                if (i < argc - 1) {
                        if (str_eq(argv[i], "-MF")) {
-                               dependency_filename_specified = 1;
+                               dependency_filename_specified = true;
                                free(output_dep);
                                output_dep = make_relative_path(x_strdup(argv[i + 1]));
                                args_add(dep_args, argv[i]);
@@ -1377,7 +1377,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                                i++;
                                continue;
                        } else if (str_eq(argv[i], "-MQ") || str_eq(argv[i], "-MT")) {
-                               dependency_target_specified = 1;
+                               dependency_target_specified = true;
                                args_add(dep_args, argv[i]);
                                args_add(dep_args, argv[i + 1]);
                                i++;
@@ -1386,16 +1386,16 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                }
                if (str_startswith(argv[i], "-Wp,")) {
                        if (str_startswith(argv[i], "-Wp,-MD,") && !strchr(argv[i] + 8, ',')) {
-                               generating_dependencies = 1;
-                               dependency_filename_specified = 1;
+                               generating_dependencies = true;
+                               dependency_filename_specified = true;
                                free(output_dep);
                                output_dep = make_relative_path(x_strdup(argv[i] + 8));
                                args_add(dep_args, argv[i]);
                                continue;
                        } else if (str_startswith(argv[i], "-Wp,-MMD,")
                                   && !strchr(argv[i] + 9, ',')) {
-                               generating_dependencies = 1;
-                               dependency_filename_specified = 1;
+                               generating_dependencies = true;
+                               dependency_filename_specified = true;
                                free(output_dep);
                                output_dep = make_relative_path(x_strdup(argv[i] + 9));
                                args_add(dep_args, argv[i]);
@@ -1407,7 +1407,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                                 * mode.
                                 */
                                cc_log("Unsupported compiler option for direct mode: %s", argv[i]);
-                               enable_direct = 0;
+                               enable_direct = false;
                        }
                }
                if (str_eq(argv[i], "-MP")) {
@@ -1440,7 +1440,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                                        if (i == argc-1) {
                                                cc_log("Missing argument to %s", argv[i]);
                                                stats_update(STATS_ARGS);
-                                               result = 0;
+                                               result = false;
                                                goto out;
                                        }
 
@@ -1451,7 +1451,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                                        /* Try to be smart about detecting precompiled headers */
                                        pchpath = format("%s.gch", argv[i+1]);
                                        if (stat(pchpath, &st) == 0) {
-                                               found_pch = 1;
+                                               found_pch = true;
                                        }
 
                                        free(pchpath);
@@ -1515,7 +1515,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                                        if (i == argc-1) {
                                                cc_log("Missing argument to %s", argv[i]);
                                                stats_update(STATS_ARGS);
-                                               result = 0;
+                                               result = false;
                                                goto out;
                                        }
 
@@ -1559,7 +1559,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                                cc_log("Unsupported source extension: %s", argv[i]);
                                stats_update(STATS_SOURCELANG);
                        }
-                       result = 0;
+                       result = false;
                        goto out;
                }
 
@@ -1570,7 +1570,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
        if (!input_file) {
                cc_log("No input file found");
                stats_update(STATS_NOINPUT);
-               result = 0;
+               result = false;
                goto out;
        }
 
@@ -1582,7 +1582,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                if (!language_is_supported(explicit_language)) {
                        cc_log("Unsupported language: %s", explicit_language);
                        stats_update(STATS_SOURCELANG);
-                       result = 0;
+                       result = false;
                        goto out;
                }
                actual_language = explicit_language;
@@ -1602,14 +1602,14 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                } else {
                        stats_update(STATS_LINK);
                }
-               result = 0;
+               result = false;
                goto out;
        }
 
        if (!actual_language) {
                cc_log("Unsupported source extension: %s", input_file);
                stats_update(STATS_SOURCELANG);
-               result = 0;
+               result = false;
                goto out;
        }
 
@@ -1618,7 +1618,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
        if (output_is_precompiled_header) {
                /* It doesn't work to create the .gch from preprocessed source. */
                cc_log("Creating precompiled header; not compiling preprocessed code");
-               compile_preprocessed_source_code = 0;
+               compile_preprocessed_source_code = false;
        }
 
        i_extension = getenv("CCACHE_EXTENSION");
@@ -1631,7 +1631,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
        if (output_obj && str_eq(output_obj, "-")) {
                stats_update(STATS_OUTSTDOUT);
                cc_log("Output file is -");
-               result = 0;
+               result = false;
                goto out;
        }
 
@@ -1648,7 +1648,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                        if (!p || !p[1]) {
                                cc_log("Badly formed object filename");
                                stats_update(STATS_ARGS);
-                               result = 0;
+                               result = false;
                                goto out;
                        }
                        p[1] = found_S_opt ? 's' : 'o';
@@ -1662,7 +1662,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
            && !S_ISREG(st.st_mode)) {
                cc_log("Not a regular file: %s", output_obj);
                stats_update(STATS_DEVICE);
-               result = 0;
+               result = false;
                goto out;
        }
 
@@ -1754,21 +1754,21 @@ cc_reset(void)
        free(cached_dep); cached_dep = NULL;
        free(manifest_path); manifest_path = NULL;
        time_of_compilation = 0;
-       sloppiness = 0;
+       sloppiness = false;
        if (included_files) {
                hashtable_destroy(included_files, 1); included_files = NULL;
        }
-       generating_dependencies = 0;
+       generating_dependencies = false;
        i_extension = NULL;
        i_tmpfile = NULL;
-       direct_i_file = 0;
+       direct_i_file = false;
        free(cpp_stderr); cpp_stderr = NULL;
        free(stats_file); stats_file = NULL;
-       enable_unify = 0;
-       enable_direct = 1;
-       enable_compression = 0;
+       enable_unify = false;
+       enable_direct = true;
+       enable_compression = false;
        nlevels = 2;
-       compile_preprocessed_source_code = 0;
+       compile_preprocessed_source_code = false;
 }
 
 static unsigned
@@ -1805,7 +1805,7 @@ parse_sloppiness(char *p)
 static void
 ccache(int argc, char *argv[])
 {
-       int put_object_in_manifest = 0;
+       bool put_object_in_manifest = false;
        struct file_hash *object_hash;
        struct file_hash *object_hash_from_manifest = NULL;
        char *env;
@@ -1837,17 +1837,17 @@ ccache(int argc, char *argv[])
 
        if (getenv("CCACHE_UNIFY")) {
                cc_log("Unify mode disabled");
-               enable_unify = 1;
+               enable_unify = true;
        }
 
        if (getenv("CCACHE_NODIRECT") || enable_unify) {
                cc_log("Direct mode disabled");
-               enable_direct = 0;
+               enable_direct = false;
        }
 
        if (getenv("CCACHE_COMPRESS")) {
                cc_log("Compression enabled");
-               enable_compression = 1;
+               enable_compression = true;
        }
 
        if ((env = getenv("CCACHE_NLEVELS"))) {
@@ -1888,12 +1888,12 @@ ccache(int argc, char *argv[])
                         * However, the object was already found in manifest,
                         * so don't readd it later.
                         */
-                       put_object_in_manifest = 0;
+                       put_object_in_manifest = false;
 
                        object_hash_from_manifest = object_hash;
                } else {
                        /* Add object to manifest later. */
-                       put_object_in_manifest = 1;
+                       put_object_in_manifest = true;
                }
        }
 
@@ -1931,7 +1931,7 @@ ccache(int argc, char *argv[])
                cc_log("Removing manifest as a safety measure");
                unlink(manifest_path);
 
-               put_object_in_manifest = 1;
+               put_object_in_manifest = true;
        }
 
        /* if we can return from cache at this point then do */
@@ -2127,7 +2127,7 @@ ccache_main(int argc, char *argv[])
 
        /* check if we are being invoked as "ccache" */
        program_name = basename(argv[0]);
-       if (compare_executable_name(program_name, MYNAME)) {
+       if (same_executable_name(program_name, MYNAME)) {
                if (argc < 2) {
                        fputs(USAGE_TEXT, stderr);
                        exit(1);
index 1b0cde05a699e16d6bd0586eb7a7ba15727e1a77..a55afdaefd44703e3de5775610e5ae367b8ac5e4 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -77,7 +77,7 @@ void args_set(struct args *args, int index, const char *value);
 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);
+bool args_equal(struct args *args1, struct args *args2);
 
 /* ------------------------------------------------------------------------- */
 /* hash.c */
@@ -86,12 +86,12 @@ void hash_start(struct mdfour *md);
 void hash_buffer(struct mdfour *md, const void *s, size_t len);
 char *hash_result(struct mdfour *md);
 void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
-int hash_equal(struct mdfour *md1, struct mdfour *md2);
+bool hash_equal(struct mdfour *md1, struct mdfour *md2);
 void hash_delimiter(struct mdfour *md, const char* type);
 void hash_string(struct mdfour *md, const char *s);
 void hash_int(struct mdfour *md, int x);
-int hash_fd(struct mdfour *md, int fd);
-int hash_file(struct mdfour *md, const char *fname);
+bool hash_fd(struct mdfour *md, int fd);
+bool hash_file(struct mdfour *md, const char *fname);
 
 /* ------------------------------------------------------------------------- */
 /* util.c */
@@ -105,7 +105,7 @@ 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 move_uncompressed_file(const char *src, const char *dest,
                            int compress_dest);
-int test_if_compressed(const char *filename);
+bool test_if_compressed(const char *filename);
 
 int create_dir(const char *dir);
 const char *get_hostname(void);
@@ -131,16 +131,16 @@ char *gnu_getcwd(void);
 int create_empty_file(const char *fname);
 const char *get_home_directory(void);
 char *get_cwd();
-int compare_executable_name(const char *s1, const char *s2);
+bool same_executable_name(const char *s1, const char *s2);
 size_t common_dir_prefix_length(const char *s1, const char *s2);
 char *get_relative_path(const char *from, const char *to);
-int is_absolute_path(const char *path);
-int is_full_path(const char *path);
+bool is_absolute_path(const char *path);
+bool is_full_path(const char *path);
 void update_mtime(const char *path);
 int x_rename(const char *oldpath, const char *newpath);
 char *x_readlink(const char *path);
 char *read_text_file(const char *path);
-int read_file(const char *path, size_t size_hint, char **data, size_t *size);
+bool read_file(const char *path, size_t size_hint, char **data, size_t *size);
 
 /* ------------------------------------------------------------------------- */
 /* stats.c */
@@ -206,16 +206,16 @@ void print_executed_command(FILE *fp, char **argv);
 /* ------------------------------------------------------------------------- */
 /* lockfile.c */
 
-int lockfile_acquire(const char *path, unsigned staleness_limit);
+bool lockfile_acquire(const char *path, unsigned staleness_limit);
 void lockfile_release(const char *path);
 
 /* ------------------------------------------------------------------------- */
 /* ccache.c */
 
-int cc_process_args(struct args *orig_args, struct args **preprocessor_args,
+bool cc_process_args(struct args *orig_args, struct args **preprocessor_args,
                     struct args **compiler_args);
 void cc_reset(void);
-int is_precompiled_header(const char *path);
+bool is_precompiled_header(const char *path);
 
 /* ------------------------------------------------------------------------- */
 
index 91531626ac4967fc63e7eced5cec4a8d434d36ce..4e3036a77c1c926350003efb5b17a884c70e8b42 100644 (file)
@@ -53,11 +53,11 @@ counters_resize(struct counters *c, size_t new_size)
 {
        if (new_size > c->size) {
                size_t i;
-               int realloc = 0;
+               bool realloc = false;
 
                while (c->allocated < new_size) {
                        c->allocated += 32 + c->allocated;
-                       realloc = 1;
+                       realloc = true;
                }
                if (realloc) {
                        c->data = x_realloc(c->data, c->allocated * sizeof(c->data[0]));
diff --git a/hash.c b/hash.c
index f6a3dc2d1d4a4de5e3cb9b9da5320d32021381e0..337ed55be7898afe2c11d82360a6447a2aefc379 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -51,7 +51,7 @@ hash_result_as_bytes(struct mdfour *md, unsigned char *out)
        mdfour_result(md, out);
 }
 
-int
+bool
 hash_equal(struct mdfour *md1, struct mdfour *md2)
 {
        unsigned char sum1[16], sum2[16];
@@ -90,9 +90,10 @@ hash_int(struct mdfour *md, int x)
 }
 
 /*
- * Add contents of an open file to the hash. Returns 1 on success, otherwise 0.
+ * Add contents of an open file to the hash. Returns true on success, otherwise
+ * false.
  */
-int
+bool
 hash_fd(struct mdfour *md, int fd)
 {
        char buf[1024];
@@ -102,24 +103,25 @@ hash_fd(struct mdfour *md, int fd)
                hash_buffer(md, buf, n);
        }
        if (n == 0) {
-               return 1;
+               return true;
        } else {
-               return 0;
+               return false;
        }
 }
 
 /*
- * Add contents of a file to the hash. Returns 1 on success, otherwise 0.
+ * Add contents of a file to the hash. Returns true on success, otherwise
+ * false.
  */
-int
+bool
 hash_file(struct mdfour *md, const char *fname)
 {
        int fd;
-       int ret;
+       bool ret;
 
        fd = open(fname, O_RDONLY|O_BINARY);
        if (fd == -1) {
-               return 0;
+               return false;
        }
 
        ret = hash_fd(md, fd);
index fd753329dc4df03ac9fdb9477b70252d3e219b0a..d935c5f749f1ec159576f7833f3e11c35c5cce95 100644 (file)
@@ -219,7 +219,7 @@ hash_source_code_file(struct mdfour *hash, const char *path)
        }
 }
 
-int
+bool
 hash_command_output(struct mdfour *hash, const char *command,
                     const char *compiler)
 {
@@ -250,10 +250,11 @@ hash_command_output(struct mdfour *hash, const char *command,
                dup2(pipefd[1], 1);
                dup2(pipefd[1], 2);
                _exit(execvp(args->argv[0], args->argv));
-               return 0; /* Never reached. */
+               return false; /* Never reached. */
        } else {
                /* Parent. */
-               int status, ok;
+               int status;
+               bool ok;
                args_free(args);
                close(pipefd[1]);
                ok = hash_fd(hash, pipefd[0]);
@@ -264,29 +265,29 @@ hash_command_output(struct mdfour *hash, const char *command,
                close(pipefd[0]);
                if (waitpid(pid, &status, 0) != pid) {
                        cc_log("waitpid failed");
-                       return 0;
+                       return false;
                }
                if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
                        cc_log("Compiler check command returned %d", WEXITSTATUS(status));
                        stats_update(STATS_COMPCHECK);
-                       return 0;
+                       return false;
                }
                return ok;
        }
 }
 
-int
+bool
 hash_multicommand_output(struct mdfour *hash, const char *commands,
                          const char *compiler)
 {
        char *command_string, *command, *p, *saveptr = NULL;
-       int ok = 1;
+       bool ok = true;
 
        command_string = x_strdup(commands);
        p = command_string;
        while ((command = strtok_r(p, ";", &saveptr))) {
                if (!hash_command_output(hash, command, compiler)) {
-                       ok = 0;
+                       ok = false;
                }
                p = NULL;
        }
index 43453ee4ecc1a84b33664b784b5d3ae37994f60f..a897b3e12dff3a96c05fce9b17d9be92f048457c 100644 (file)
@@ -23,9 +23,9 @@ int file_hashes_equal(struct file_hash *fh1, struct file_hash *fh2);
 int hash_source_code_string(
        struct mdfour *hash, const char *str, size_t len, const char *path);
 int hash_source_code_file(struct mdfour *hash, const char *path);
-int hash_command_output(struct mdfour *hash, const char *command,
-                        const char *compiler);
-int hash_multicommand_output(struct mdfour *hash, const char *command,
-                             const char *compiler);
+bool hash_command_output(struct mdfour *hash, const char *command,
+                         const char *compiler);
+bool hash_multicommand_output(struct mdfour *hash, const char *command,
+                              const char *compiler);
 
 #endif
index fd3bb01923a763504fd7c14a74c31381390b8d12..acbeb89c39aa8454e3d22408fa1d60d6695ac0e8 100644 (file)
@@ -142,13 +142,13 @@ extension_for_language(const char *language)
        return NULL;
 }
 
-int
+bool
 language_is_supported(const char *language)
 {
        return p_language_for_language(language) != NULL;
 }
 
-int
+bool
 language_is_preprocessed(const char *language)
 {
        return str_eq(language, p_language_for_language(language));
index 8d6c6ba5a476dadcf817f24c1ba1758caf457e31..6f674d173cde797c5526031c9b62e4b22f96f781 100644 (file)
@@ -4,7 +4,7 @@
 const char *language_for_file(const char *fname);
 const char *p_language_for_language(const char *language);
 const char *extension_for_language(const char *language);
-int language_is_supported(const char *language);
-int language_is_preprocessed(const char *language);
+bool language_is_supported(const char *language);
+bool language_is_preprocessed(const char *language);
 
 #endif /* CCACHE_LANGUAGE_H */
index 73300f5c8671e15fbc0784488f8a95bef1fc001a..e62aac4be3d52d5e5a133b47e4dbf070070cc2c5 100644 (file)
  * probably be made with an atomic rename(2) to avoid corruption in the rare
  * case that the lock is broken by another process.
  */
-int
+bool
 lockfile_acquire(const char *path, unsigned staleness_limit)
 {
        char *lockfile = format("%s.lock", path);
        char *my_content = NULL, *content = NULL, *initial_content = NULL;
        const char *hostname = get_hostname();
-       int result = 0;
+       bool acquired = false;
 #ifdef _WIN32
        const size_t bufsize = 1024;
        int fd, len;
@@ -88,14 +88,14 @@ lockfile_acquire(const char *path, unsigned staleness_limit)
                                goto out;
                        }
                        close(fd);
-                       result = 1;
+                       acquired = true;
                        goto out;
                }
 #else
                ret = symlink(my_content, lockfile);
                if (ret == 0) {
                        /* We got the lock. */
-                       result = 1;
+                       acquired = true;
                        goto out;
                }
                cc_log("lockfile_acquire: symlink %s: %s", lockfile, strerror(errno));
@@ -123,7 +123,7 @@ lockfile_acquire(const char *path, unsigned staleness_limit)
                        /* Lost NFS reply? */
                        cc_log("lockfile_acquire: symlink %s failed but we got the lock anyway",
                               lockfile);
-                       result = 1;
+                       acquired = true;
                        goto out;
                }
                /*
@@ -157,7 +157,7 @@ lockfile_acquire(const char *path, unsigned staleness_limit)
        }
 
 out:
-       if (result == 1) {
+       if (acquired) {
                cc_log("Acquired lock %s", lockfile);
        } else {
                cc_log("Failed to acquire lock %s", lockfile);
@@ -166,7 +166,7 @@ out:
        free(my_content);
        free(initial_content);
        free(content);
-       return result;
+       return acquired;
 }
 
 /*
index b016fecd7014fd8d6c3a04bdda33ebdb89eebed5..bb809ba5736d292cdad9a5825708169b4970b4e8 100644 (file)
@@ -571,9 +571,9 @@ out:
 
 /*
  * Put the object name into a manifest file given a set of included files.
- * Returns 1 on success, otherwise 0.
+ * Returns true on success, otherwise false.
  */
-int
+bool
 manifest_put(const char *manifest_path, struct file_hash *object_hash,
              struct hashtable *included_files)
 {
index f6e9a4a6394d3653e940de645337862cd7068a6f..80333e7a2a8cbafedf72bbe6df834e05e2eba25c 100644 (file)
@@ -5,7 +5,7 @@
 #include "hashtable.h"
 
 struct file_hash *manifest_get(const char *manifest_path);
-int manifest_put(const char *manifest_path, struct file_hash *object_hash,
-                 struct hashtable *included_files);
+bool manifest_put(const char *manifest_path, struct file_hash *object_hash,
+                  struct hashtable *included_files);
 
 #endif
diff --git a/stats.c b/stats.c
index faa285ecfd2ff90dd7b52b82ab47497f30275508..351f7190c2f787722c64350533a6baf6d19017ed 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -193,8 +193,8 @@ void
 stats_flush(void)
 {
        struct counters *counters;
-       int need_cleanup = 0;
-       int should_flush = 0;
+       bool need_cleanup = false;
+       bool should_flush = false;
        int i;
 
        if (getenv("CCACHE_NOSTATS")) return;
@@ -203,7 +203,7 @@ stats_flush(void)
 
        for (i = 0; i < STATS_END; ++i) {
                if (counter_updates->data[i] > 0) {
-                       should_flush = 1;
+                       should_flush = true;
                        break;
                }
        }
@@ -236,11 +236,11 @@ stats_flush(void)
 
        if (counters->data[STATS_MAXFILES] != 0 &&
            counters->data[STATS_NUMFILES] > counters->data[STATS_MAXFILES]) {
-               need_cleanup = 1;
+               need_cleanup = true;
        }
        if (counters->data[STATS_MAXSIZE] != 0 &&
            counters->data[STATS_TOTALSIZE] > counters->data[STATS_MAXSIZE]) {
-               need_cleanup = 1;
+               need_cleanup = true;
        }
 
        if (need_cleanup) {
index f714032245c24b9c053e98ec3f5db5fb889ed3b6..9196d6214b0c79fc42f90d7e1956aed2f79b1074 100644 (file)
  */
 
 #include "system.h"
+#include "test/util.h"
 
-int
+bool
 path_exists(const char *path)
 {
        struct stat st;
        return lstat(path, &st) == 0;
 }
 
-int
+bool
 is_symlink(const char *path)
 {
        struct stat st;
index d4afb115a9779d55e976324c38218c2e2a46679b..dd942d453d89684c2b64fa837e24e7fae4845458 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef TEST_UTIL_H
 #define TEST_UTIL_H
 
-int path_exists(const char *path);
-int is_symlink(const char *path);
+bool path_exists(const char *path);
+bool is_symlink(const char *path);
 void create_file(const char *path, const char *content);
 
 #endif
diff --git a/unify.c b/unify.c
index 9364553e37ee925766d89bd652fdda7d3b46f0a7..b10b3f5d98b55f139944593aaa5ba66ea4b95a5a 100644 (file)
--- a/unify.c
+++ b/unify.c
@@ -62,10 +62,10 @@ build_table(void)
 {
        unsigned char c;
        int i;
-       static int done;
+       static bool done;
 
        if (done) return;
-       done = 1;
+       done = true;
 
        memset(tokens, 0, sizeof(tokens));
        for (c = 0; c < 128; c++) {
diff --git a/util.c b/util.c
index ddf0db0d6eaefd1c0de368c12d658804836040ca..bb3d909d9fa8943e780d1faf8b3e4374937c650c 100644 (file)
--- a/util.c
+++ b/util.c
 
 static FILE *logfile;
 
-static int
+static bool
 init_log(void)
 {
        extern char *cache_logfile;
 
        if (logfile) {
-               return 1;
+               return true;
        }
        if (!cache_logfile) {
-               return 0;
+               return false;
        }
        logfile = fopen(cache_logfile, "a");
        if (logfile) {
-               return 1;
+               return true;
        } else {
-               return 0;
+               return false;
        }
 }
 
@@ -332,25 +332,25 @@ move_uncompressed_file(const char *src, const char *dest, int compress_dest)
 }
 
 /* test if a file is zlib compressed */
-int
+bool
 test_if_compressed(const char *filename)
 {
        FILE *f;
 
        f = fopen(filename, "rb");
        if (!f) {
-               return 0;
+               return false;
        }
 
        /* test if file starts with 1F8B, which is zlib's
         * magic number */
        if ((fgetc(f) != 0x1f) || (fgetc(f) != 0x8b)) {
                fclose(f);
-               return 0;
+               return false;
        }
 
        fclose(f);
-       return 1;
+       return true;
 }
 
 /* make sure a directory exists */
@@ -907,11 +907,11 @@ get_cwd(void)
 /*
  * Check whether s1 and s2 have the same executable name.
  */
-int
-compare_executable_name(const char *s1, const char *s2)
+bool
+same_executable_name(const char *s1, const char *s2)
 {
 #ifdef _WIN32
-       int eq = strcasecmp(s1, s2) == 0;
+       bool eq = strcasecmp(s1, s2) == 0;
        if (!eq) {
                char *tmp = format("%s.exe", s2);
                eq = strcasecmp(s1, tmp) == 0;
@@ -988,7 +988,7 @@ get_relative_path(const char *from, const char *to)
 /*
  * Return whether path is absolute.
  */
-int
+bool
 is_absolute_path(const char *path)
 {
 #ifdef _WIN32
@@ -1001,7 +1001,7 @@ is_absolute_path(const char *path)
 /*
  * Return whether the argument is a full path.
  */
-int
+bool
 is_full_path(const char *path)
 {
        if (strchr(path, '/'))
@@ -1069,10 +1069,10 @@ x_readlink(const char *path)
 #endif
 
 /*
- * Reads the content of a file. Size hint 0 means no hint. Returns 0 on
- * failure, otherwise 1.
+ * Reads the content of a file. Size hint 0 means no hint. Returns true on
+ * success, otherwise false.
  */
-int
+bool
 read_file(const char *path, size_t size_hint, char **data, size_t *size)
 {
        int fd, ret;
@@ -1080,7 +1080,7 @@ read_file(const char *path, size_t size_hint, char **data, size_t *size)
 
        fd = open(path, O_RDONLY);
        if (fd == -1) {
-               return 0;
+               return false;
        }
        *data = x_malloc(allocated);
        ret = 0;
@@ -1096,11 +1096,11 @@ read_file(const char *path, size_t size_hint, char **data, size_t *size)
                cc_log("Failed reading %s", path);
                free(*data);
                *data = NULL;
-               return 0;
+               return false;
        }
 
        *size = pos;
-       return 1;
+       return true;
 }
 
 /*