* ccache -- a fast C/C++ compiler cache
*
* Copyright (C) 2002-2007 Andrew Tridgell
- * Copyright (C) 2009-2015 Joel Rosdahl
+ * Copyright (C) 2009-2016 Joel Rosdahl
*
* 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
static char *
make_relative_path(char *path)
{
- char *relpath, *canon_path, *path_suffix = NULL;
+ char *canon_path, *path_suffix = NULL;
struct stat st;
if (str_eq(conf->base_dir, "") || !str_startswith(path, conf->base_dir)) {
canon_path = x_realpath(path);
if (canon_path) {
+ char *relpath;
free(path);
relpath = get_relative_path(get_current_working_dir(), canon_path);
free(canon_path);
static void
to_cache(struct args *args)
{
- char *tmp_stdout, *tmp_stderr, *tmp_aux, *tmp_cov;
+ char *tmp_stdout, *tmp_stderr, *tmp_cov;
char *tmp_dwo = NULL;
struct stat st;
int status, tmp_stdout_fd, tmp_stderr_fd;
- FILE *f;
tmp_stdout = format("%s.tmp.stdout", cached_obj);
tmp_stdout_fd = create_tmp_fd(&tmp_stdout);
tmp_stderr_fd = create_tmp_fd(&tmp_stderr);
if (generating_coverage) {
+ char *tmp_aux;
/* gcc has some funny rule about max extension length */
if (strlen(get_extension(output_obj)) < 6) {
tmp_aux = remove_extension(output_obj);
if (generating_coverage) {
/* gcc won't generate notes if there is no code */
if (stat(tmp_cov, &st) != 0 && errno == ENOENT) {
+ FILE *f = fopen(cached_cov, "wb");
cc_log("Creating placeholder: %s", cached_cov);
-
- f = fopen(cached_cov, "wb");
if (!f) {
cc_log("Failed to create %s: %s", cached_cov, strerror(errno));
stats_update(STATS_ERROR);
{
struct stat st;
char *p;
- const char *full_path = args->argv[0];
+ const char *full_path;
#ifdef _WIN32
const char *ext;
char full_path_win_ext[MAX_PATH + 1] = {0};
add_exe_ext_if_no_to_fullpath(full_path_win_ext, MAX_PATH, ext,
args->argv[0]);
full_path = full_path_win_ext;
+#else
+ full_path = args->argv[0];
#endif
if (x_stat(full_path, &st) != 0) {
/* Possibly hash the coverage data file path. */
if (generating_coverage && profile_arcs) {
- char *gcda_path;
char *dir = dirname(output_obj);
if (profile_dir) {
dir = x_strdup(profile_dir);
dir = real_dir;
}
if (dir) {
+ char *gcda_path;
char *base_name = basename(output_obj);
p = remove_extension(base_name);
free(base_name);
calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode)
{
int i;
- char *manifest_name;
struct stat st;
- int result;
struct file_hash *object_hash = NULL;
char *p;
}
if (direct_mode) {
+ char *manifest_name;
+ int result;
+
/* Hash environment variables that affect the preprocessor output. */
const char **p;
const char *envvars[] = {
#endif
int create_tmp_fd(char **fname);
FILE *create_tmp_file(char **fname, const char *mode);
-void create_empty_tmp_file(char **fname);
const char *get_home_directory(void);
char *get_cwd(void);
bool same_executable_name(const char *s1, const char *s2);
/*
* Copyright (C) 2002-2006 Andrew Tridgell
- * Copyright (C) 2009-2015 Joel Rosdahl
+ * Copyright (C) 2009-2016 Joel Rosdahl
*
* 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
sort_and_clean(void)
{
unsigned i;
- const char *ext;
char *last_base = x_strdup("");
if (num_files > 1) {
/* delete enough files to bring us below the threshold */
for (i = 0; i < num_files; i++) {
+ const char *ext;
+
if ((cache_size_threshold == 0
|| cache_size <= cache_size_threshold)
&& (files_in_cache_threshold == 0
/* cleanup in all cache subdirs */
void cleanup_all(struct conf *conf)
{
- char *dname;
int i;
for (i = 0; i <= 0xF; i++) {
- dname = format("%s/%1x", conf->cache_dir, i);
+ char *dname = format("%s/%1x", conf->cache_dir, i);
cleanup_dir(conf, dname);
free(dname);
}
/* wipe all cached files in all subdirs */
void wipe_all(struct conf *conf)
{
- char *dname;
int i;
for (i = 0; i <= 0xF; i++) {
- dname = format("%s/%1x", conf->cache_dir, i);
+ char *dname = format("%s/%1x", conf->cache_dir, i);
traverse(dname, wipe_fn);
free(dname);
}
/*
- * Copyright (C) 2010-2015 Joel Rosdahl
+ * Copyright (C) 2010-2016 Joel Rosdahl
*
* 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
return co && (co->type & TAKES_ARG);
}
-/* Determines if argument takes a concatentated argument by comparing prefixes.
- */
-bool
-compopt_takes_concat_arg(const char *option)
-{
- const struct compopt *co = find_prefix(option);
- return co && (co->type & TAKES_CONCAT_ARG);
-}
-
/* Determines if the prefix of the option matches any option and affects the
* preprocessor.
*/
bool compopt_too_hard_for_direct_mode(const char *option);
bool compopt_takes_path(const char *option);
bool compopt_takes_arg(const char *option);
-bool compopt_takes_concat_arg(const char *option);
bool compopt_prefix_affects_cpp(const char *option);
#endif /* CCACHE_COMPOPT_H */
*ptr++ = '\\';
*ptr++ = '"';
*ptr++ = ' ';
+ /* cppcheck-suppress unreadVariable */
} while ((arg = argv[i++]));
ptr[-1] = '\0';
/*
- * Copyright (C) 2010-2015 Joel Rosdahl
+ * Copyright (C) 2010-2016 Joel Rosdahl
*
* 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
void
exitfn_call(void)
{
- struct exit_function *p = exit_functions, *q;
+ struct exit_function *p = exit_functions;
exit_functions = NULL;
while (p) {
+ struct exit_function *q;
p->function(p->context);
q = p;
p = p->next;
/*
- * Copyright (C) 2010-2015 Joel Rosdahl
+ * Copyright (C) 2010-2016 Joel Rosdahl
*
* 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
}
free(content);
content = x_readlink(lockfile);
+ /* cppcheck-suppress nullPointer - false positive */
if (!content) {
if (errno == ENOENT) {
/*
/*
- * Copyright (C) 2009-2015 Joel Rosdahl
+ * Copyright (C) 2009-2016 Joel Rosdahl
*
* 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
struct hashtable *stated_files, struct hashtable *hashed_files)
{
uint32_t i;
- struct file_info *fi;
struct file_hash *actual;
- struct file_stats *st;
struct mdfour hash;
int result;
- char *path;
for (i = 0; i < obj->n_file_info_indexes; i++) {
- fi = &mf->file_infos[obj->file_info_indexes[i]];
- path = mf->files[fi->index];
- st = hashtable_search(hashed_files, path);
+ struct file_info *fi = &mf->file_infos[obj->file_info_indexes[i]];
+ char *path = mf->files[fi->index];
+ struct file_stats *st = hashtable_search(hashed_files, path);
if (!st) {
struct stat file_stat;
if (x_stat(path, &file_stat) != 0) {
{
struct hashtable_itr *iter;
uint32_t i;
- char *path;
- struct file_hash *file_hash;
struct hashtable *mf_files; /* path --> index */
struct hashtable *mf_file_infos; /* struct file_info --> index */
iter = hashtable_iterator(included_files);
i = 0;
do {
- path = hashtable_iterator_key(iter);
- file_hash = hashtable_iterator_value(iter);
+ char *path = hashtable_iterator_key(iter);
+ struct file_hash *file_hash = hashtable_iterator_value(iter);
indexes[i] = get_file_hash_index(mf, path, file_hash, mf_files,
mf_file_infos);
i++;
/*
* Copyright (C) 2002-2004 Andrew Tridgell
- * Copyright (C) 2009-2015 Joel Rosdahl
+ * Copyright (C) 2009-2016 Joel Rosdahl
*
* 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
size_t i = 0;
const char *p;
char *p2;
- long val;
p = buf;
while (true) {
- val = strtol(p, &p2, 10);
+ long val = strtol(p, &p2, 10);
if (p2 == p) {
break;
}
/*
* Copyright (C) 2002 Andrew Tridgell
- * Copyright (C) 2009-2015 Joel Rosdahl
+ * Copyright (C) 2009-2016 Joel Rosdahl
*
* 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
log_prefix(bool log_updated_time)
{
#ifdef HAVE_GETTIMEOFDAY
- char timestamp[100];
- struct timeval tv;
- struct tm *tm;
static char prefix[200];
if (log_updated_time) {
+ char timestamp[100];
+ struct tm *tm;
+ struct timeval tv;
gettimeofday(&tv, NULL);
#ifdef __MINGW64_VERSION_MAJOR
tm = localtime((time_t *)&tv.tv_sec);
}
while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
- ssize_t count, written = 0;
+ ssize_t written = 0;
do {
- count = write(fd_out, buf + written, n - written);
+ ssize_t count = write(fd_out, buf + written, n - written);
if (count == -1) {
if (errno != EAGAIN && errno != EINTR) {
fatal("Failed to copy fd");
if (compress_level > 0) {
written = gzwrite(gz_out, buf, n);
} else {
- ssize_t count;
written = 0;
do {
- count = write(fd_out, buf + written, n - written);
+ ssize_t count = write(fd_out, buf + written, n - written);
if (count == -1 && errno != EINTR) {
saved_errno = errno;
break;
sprintf(&ret[i*2], "%02x", (unsigned) hash[i]);
}
if (size >= 0) {
- sprintf(&ret[i*2], "-%u", size);
+ sprintf(&ret[i*2], "-%d", size);
}
return ret;
{
long maxlen = path_max(path);
char *ret, *p;
-#ifdef _WIN32
+#if !defined(HAVE_REALPATH) && defined(_WIN32)
HANDLE path_handle;
#endif
return file;
}
-/*
- * Create an empty temporary file. *fname will be reallocated and set to the
- * resulting filename.
- */
-void
-create_empty_tmp_file(char **fname)
-{
- close(create_tmp_fd(fname));
-}
-
/*
* Return current user's home directory, or NULL if it can't be determined.
*/
{
size_t common_prefix_len;
int i;
- const char *p;
char *result;
assert(from && is_absolute_path(from));
result = x_strdup("");
common_prefix_len = common_dir_prefix_length(from, to);
if (common_prefix_len > 0 || !str_eq(from, "/")) {
+ const char *p;
for (p = from + common_prefix_len; *p; p++) {
if (*p == '/') {
reformat(&result, "../%s", result);