diff options
-rw-r--r-- | HACKING.txt | 1 | ||||
-rw-r--r-- | args.c | 10 | ||||
-rw-r--r-- | ccache.c | 148 | ||||
-rw-r--r-- | ccache.h | 24 | ||||
-rw-r--r-- | counters.c | 4 | ||||
-rw-r--r-- | hash.c | 20 | ||||
-rw-r--r-- | hashutil.c | 17 | ||||
-rw-r--r-- | hashutil.h | 8 | ||||
-rw-r--r-- | language.c | 4 | ||||
-rw-r--r-- | language.h | 4 | ||||
-rw-r--r-- | lockfile.c | 14 | ||||
-rw-r--r-- | manifest.c | 4 | ||||
-rw-r--r-- | manifest.h | 4 | ||||
-rw-r--r-- | stats.c | 10 | ||||
-rw-r--r-- | test/util.c | 5 | ||||
-rw-r--r-- | test/util.h | 4 | ||||
-rw-r--r-- | unify.c | 4 | ||||
-rw-r--r-- | util.c | 40 |
18 files changed, 165 insertions, 160 deletions
diff --git a/HACKING.txt b/HACKING.txt index c8ce5b03..e0fbe768 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -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 ----- @@ -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; } @@ -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); @@ -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); /* ------------------------------------------------------------------------- */ @@ -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])); @@ -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); @@ -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; } @@ -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 @@ -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)); @@ -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 */ @@ -28,13 +28,13 @@ * 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; } /* @@ -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) { @@ -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 @@ -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) { diff --git a/test/util.c b/test/util.c index f7140322..9196d621 100644 --- a/test/util.c +++ b/test/util.c @@ -17,15 +17,16 @@ */ #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; diff --git a/test/util.h b/test/util.h index d4afb115..dd942d45 100644 --- a/test/util.h +++ b/test/util.h @@ -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 @@ -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++) { @@ -35,22 +35,22 @@ 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; } /* |