* Use only lowercase names for functions and variables.
* Use only uppercase names for enum items and (with some exceptions) macros.
* Don't use typedefs for structs and enums.
+* Use //-style comments.
Tip: Install the tool uncrustify <http://uncrustify.sourceforge.net> and then
run "make uncrustify" to fix up source code formatting.
-/*
- * Copyright (C) 2002 Andrew Tridgell
- *
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2002 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
char *pos, *argtext, *argpos, *argbuf;
char quoting;
- /* Used to track quoting state; if \0, we are not inside quotes. Otherwise
- * stores the quoting character that started it, for matching the end
- * quote */
+ // Used to track quoting state; if \0, we are not inside quotes. Otherwise
+ // stores the quoting character that started it, for matching the end quote.
quoting = '\0';
if (!(argtext = read_text_file(filename, 0))) {
if (quoting) {
break;
}
- /* Fall through */
+ // Fall through.
case '\0':
- /* end of token */
+ // End of token
*argpos = '\0';
if (argbuf[0] != '\0') {
args_add(args, argbuf);
return args_init(args->argc, args->argv);
}
-/* Insert all arguments in src into dest at position index.
- * If replace is true, the element at dest->argv[index] is replaced
- * with the contents of src and everything past it is shifted.
- * Otherwise, dest->argv[index] is also shifted.
- *
- * src is consumed by this operation and should not be freed or used
- * again by the caller */
+// Insert all arguments in src into dest at position index. If replace is true,
+// the element at dest->argv[index] is replaced with the contents of src and
+// everything past it is shifted. Otherwise, dest->argv[index] is also shifted.
+//
+// src is consumed by this operation and should not be freed or used again by
+// the caller.
void
args_insert(struct args *dest, int index, struct args *src, bool replace)
{
int offset;
int i;
- /* Adjustments made if we are replacing or shifting the element
- * currently at dest->argv[index] */
+ // Adjustments made if we are replacing or shifting the element currently at
+ // dest->argv[index].
offset = replace ? 1 : 0;
if (replace) {
if (src->argc == 0) {
if (replace) {
- /* Have to shift everything down by 1 since
- * we replaced with an empty list */
+ // Have to shift everything down by 1 since we replaced with an empty
+ // list.
for (i = index; i < dest->argc; i++) {
dest->argv[i] = dest->argv[i + 1];
}
}
if (src->argc == 1 && replace) {
- /* Trivial case; replace with 1 element */
+ // Trivial case; replace with 1 element.
dest->argv[index] = src->argv[0];
src->argc = 0;
args_free(src);
(src->argc + dest->argc + 1 - offset) *
sizeof(char *));
- /* Shift arguments over */
+ // Shift arguments over.
for (i = dest->argc; i >= index + offset; i--) {
dest->argv[i + src->argc - offset] = dest->argv[i];
}
- /* Copy the new arguments into place */
+ // Copy the new arguments into place.
for (i = 0; i < src->argc; i++) {
dest->argv[i + index] = src->argv[i];
}
args->argv[args->argc] = NULL;
}
-/* Add all arguments in to_append to args. */
+// Add all arguments in to_append to args.
void
args_extend(struct args *args, struct args *to_append)
{
}
}
-/* pop the last element off the args list */
+// Pop the last element off the args list.
void
args_pop(struct args *args, int n)
{
}
}
-/* set argument at given index */
+// Set argument at given index.
void
args_set(struct args *args, int index, const char *value)
{
args->argv[index] = x_strdup(value);
}
-/* remove the first element of the argument list */
+// Remove the first element of the argument list.
void
args_remove_first(struct args *args)
{
args->argc--;
}
-/* add an argument into the front of the argument list */
+// Add an argument into the front of the argument list.
void
args_add_prefix(struct args *args, const char *s)
{
args->argc++;
}
-/* strip any arguments beginning with the specified prefix */
+// Strip any arguments beginning with the specified prefix.
void
args_strip(struct args *args, const char *prefix)
{
}
}
-/*
- * Format args to a space-separated string. Does not quote spaces. Caller
- * frees.
- */
+// Format args to a space-separated string. Does not quote spaces. Caller
+// frees.
char *
args_to_string(struct args *args)
{
return result;
}
-/* Returns true if args1 equals args2, else false. */
+// Returns true if args1 equals args2, else false.
bool
args_equal(struct args *args1, struct args *args2)
{
}
return true;
}
-
-/*
- * ccache -- a fast C/C++ compiler cache
- *
- * Copyright (C) 2002-2007 Andrew Tridgell
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// ccache -- a fast C/C++ compiler cache
+//
+// Copyright (C) 2002-2007 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
#include "compopt.h"
"\n"
"See also <https://ccache.samba.org>.\n";
-/* Global configuration data. */
+// Global configuration data.
struct conf *conf = NULL;
-/* Where to write configuration changes. */
+// Where to write configuration changes.
char *primary_config_path = NULL;
-/* Secondary, read-only configuration file (if any). */
+// Secondary, read-only configuration file (if any).
char *secondary_config_path = NULL;
-/* current working directory taken from $PWD, or getcwd() if $PWD is bad */
+// Current working directory taken from $PWD, or getcwd() if $PWD is bad.
char *current_working_dir = NULL;
-/* the original argument list */
+// The original argument list.
static struct args *orig_args;
-/* the source file */
+// The source file.
static char *input_file;
-/* The output file being compiled to. */
+// The output file being compiled to.
static char *output_obj;
-/* The path to the dependency file (implicit or specified with -MF). */
+// The path to the dependency file (implicit or specified with -MF).
static char *output_dep;
-/* The path to the coverage file (implicit when using -ftest-coverage). */
+// The path to the coverage file (implicit when using -ftest-coverage).
static char *output_cov;
-/* Diagnostic generation information (clang). Contains pathname if not
- * NULL. */
+// Diagnostic generation information (clang). Contains pathname if not NULL.
static char *output_dia = NULL;
-/* -gsplit-dwarf support: Split dwarf information (GCC 4.8 and
- * up). Contains pathname if not NULL. */
+// Split dwarf information (GCC 4.8 andup). Contains pathname if not NULL.
static char *output_dwo = NULL;
-/* Array for storing -arch options. */
+// Array for storing -arch options.
#define MAX_ARCH_ARGS 10
static size_t arch_args_size = 0;
static char *arch_args[MAX_ARCH_ARGS] = {NULL};
-/*
- * Name (represented as a struct file_hash) of the file containing the cached
- * object code.
- */
+// Name (represented as a struct file_hash) of the file containing the cached
+// object code.
static struct file_hash *cached_obj_hash;
-/*
- * Full path to the file containing the cached object code
- * (cachedir/a/b/cdef[...]-size.o).
- */
+// Full path to the file containing the cached object code
+// (cachedir/a/b/cdef[...]-size.o).
static char *cached_obj;
-/*
- * Full path to the file containing the standard error output
- * (cachedir/a/b/cdef[...]-size.stderr).
- */
+// Full path to the file containing the standard error output
+// (cachedir/a/b/cdef[...]-size.stderr).
static char *cached_stderr;
-/*
- * Full path to the file containing the dependency information
- * (cachedir/a/b/cdef[...]-size.d).
- */
+// Full path to the file containing the dependency information
+// (cachedir/a/b/cdef[...]-size.d).
static char *cached_dep;
-/*
- * Full path to the file containing the coverage information
- * (cachedir/a/b/cdef[...]-size.gcno).
- */
+// Full path to the file containing the coverage information
+// (cachedir/a/b/cdef[...]-size.gcno).
static char *cached_cov;
-/*
- * Full path to the file containing the diagnostic information (for clang)
- * (cachedir/a/b/cdef[...]-size.dia).
- */
+// Full path to the file containing the diagnostic information (for clang)
+// (cachedir/a/b/cdef[...]-size.dia).
static char *cached_dia;
-/*
- * -gsplit-dwarf support:
- * Full path to the file containing the split dwarf (for GCC 4.8 and
- * above)
- * (cachedir/a/b/cdef[...]-size.dwo).
- *
- * contains NULL if -gsplit-dwarf is not given.
- */
+// Full path to the file containing the split dwarf (for GCC 4.8 and above)
+// (cachedir/a/b/cdef[...]-size.dwo).
+//
+// Contains NULL if -gsplit-dwarf is not given.
static char *cached_dwo;
-/*
- * -gsplit-dwarf support:
- * using_split_dwarf is true if "-gsplit-dwarf" is given to the
- * compiler (GCC 4.8 and up).
- */
+// using_split_dwarf is true if "-gsplit-dwarf" is given to the compiler (GCC
+// 4.8 and up).
bool using_split_dwarf = false;
-/*
- * Full path to the file containing the manifest
- * (cachedir/a/b/cdef[...]-size.manifest).
- */
+// Full path to the file containing the manifest
+// (cachedir/a/b/cdef[...]-size.manifest).
static char *manifest_path;
-/*
- * Time of compilation. Used to see if include files have changed after
- * compilation.
- */
+// Time of compilation. Used to see if include files have changed after
+// compilation.
time_t time_of_compilation;
-/*
- * Files included by the preprocessor and their hashes/sizes. Key: file path.
- * Value: struct file_hash.
- */
+// Files included by the preprocessor and their hashes/sizes. Key: file path.
+// Value: struct file_hash.
static struct hashtable *included_files = NULL;
-/* uses absolute path for some include files */
+// Uses absolute path for some include files.
static bool has_absolute_include_headers = false;
-/* List of headers to ignore */
+// List of headers to ignore.
static char **ignore_headers;
-/* Size of headers to ignore list */
+// Size of headers to ignore list.
static size_t ignore_headers_len;
-/* is gcc being asked to output debug info? */
+// Is the compiler being asked to output debug info?
static bool generating_debuginfo;
-/* is gcc being asked to output dependencies? */
+// Is the compiler being asked to output dependencies?
static bool generating_dependencies;
-/* is gcc being asked to output coverage? */
+// Is the compiler being asked to output coverage?
static bool generating_coverage;
-/* relocating debuginfo, in the format old=new */
+// Relocating debuginfo in the format old=new.
static char *debug_prefix_map = NULL;
-/* is gcc being asked to output coverage data (.gcda) at runtime? */
+// Is the compiler being asked to output coverage data (.gcda) at runtime?
static bool profile_arcs;
-/* name of the custom profile directory (default: object dirname) */
+// Name of the custom profile directory (default: object dirname).
static char *profile_dir;
-/* the name of the temporary pre-processor file */
+// The name of the temporary preprocessed file.
static char *i_tmpfile;
-/* are we compiling a .i or .ii file directly? */
+// Are we compiling a .i or .ii file directly?
static bool direct_i_file;
-/* the name of the cpp stderr file */
+// The name of the cpp stderr file.
static char *cpp_stderr;
-/*
- * Full path to the statistics file in the subdirectory where the cached result
- * belongs (<cache_dir>/<x>/stats).
- */
+// Full path to the statistics file in the subdirectory where the cached result
+// belongs (<cache_dir>/<x>/stats).
char *stats_file = NULL;
-/* Whether the output is a precompiled header */
+// Whether the output is a precompiled header.
static bool output_is_precompiled_header = false;
-/* Profile generation / usage information */
+// Profile generation / usage information.
static char *profile_dir = NULL;
static bool profile_use = false;
static bool profile_generate = false;
-/*
- * Whether we are using a precompiled header (either via -include, #include or
- * clang's -include-pch or -include-pth).
- */
+// Whether we are using a precompiled header (either via -include, #include or
+// clang's -include-pch or -include-pth).
static bool using_precompiled_header = false;
-/*
- * The .gch/.pch/.pth file used for compilation.
- */
+// The .gch/.pch/.pth file used for compilation.
static char *included_pch_file = NULL;
-/* How long (in microseconds) to wait before breaking a stale lock. */
+// How long (in microseconds) to wait before breaking a stale lock.
unsigned lock_staleness_limit = 2000000;
enum fromcache_call_mode {
struct pending_tmp_file *next;
};
-/* Temporary files to remove at program exit. */
+// Temporary files to remove at program exit.
static struct pending_tmp_file *pending_tmp_files = NULL;
#ifndef _WIN32
static sigset_t fatal_signal_set;
-/* PID of currently executing compiler that we have started, if any. 0 means no
- * ongoing compilation. */
+// PID of currently executing compiler that we have started, if any. 0 means no
+// ongoing compilation.
static pid_t compiler_pid = 0;
#endif
-/*
- * This is a string that identifies the current "version" of the hash sum
- * computed by ccache. If, for any reason, we want to force the hash sum to be
- * different for the same input in a new ccache version, we can just change
- * this string. A typical example would be if the format of one of the files
- * stored in the cache changes in a backwards-incompatible way.
- */
+// This is a string that identifies the current "version" of the hash sum
+// computed by ccache. If, for any reason, we want to force the hash sum to be
+// different for the same input in a new ccache version, we can just change
+// this string. A typical example would be if the format of one of the files
+// stored in the cache changes in a backwards-incompatible way.
static const char HASH_PREFIX[] = "3";
static void
args_free(prefix);
}
-/* Something went badly wrong - just execute the real compiler. */
+// Something went badly wrong - just execute the real compiler.
static void
failed(void)
{
{
static char *path = NULL;
if (path) {
- return path; /* Memoize */
+ return path; // Memoize
}
path = conf->temporary_dir;
if (str_eq(path, "")) {
{
struct pending_tmp_file *p = pending_tmp_files;
while (p) {
- /* Can't call tmp_unlink here since its cc_log calls aren't signal safe. */
+ // Can't call tmp_unlink here since its cc_log calls aren't signal safe.
unlink(p->path);
p = p->next;
- /* Leak p->path and p here because clean_up_pending_tmp_files needs to be
- * signal safe. */
+ // Leak p->path and p here because clean_up_pending_tmp_files needs to be
+ // signal safe.
}
}
static void
signal_handler(int signum)
{
- /* Unregister handler for this signal so that we can send the signal to
- * ourselves at the end of the handler. */
+ // Unregister handler for this signal so that we can send the signal to
+ // ourselves at the end of the handler.
signal(signum, SIG_DFL);
- /* If ccache was killed explicitly, then bring the compiler subprocess (if
- * any) with us as well. */
+ // If ccache was killed explicitly, then bring the compiler subprocess (if
+ // any) with us as well.
if (signum == SIGTERM
&& compiler_pid != 0
&& waitpid(compiler_pid, NULL, WNOHANG) == 0) {
do_clean_up_pending_tmp_files();
if (compiler_pid != 0) {
- /* Wait for compiler subprocess to exit before we snuff it. */
+ // Wait for compiler subprocess to exit before we snuff it.
waitpid(compiler_pid, NULL, 0);
}
- /* Resend signal to ourselves to exit properly after returning from the
- * handler. */
+ // Resend signal to ourselves to exit properly after returning from the
+ // handler.
kill(getpid(), signum);
}
register_signal_handler(SIGQUIT);
#endif
}
-#endif /* _WIN32 */
+#endif // _WIN32
static void
clean_up_internal_tempdir(void)
time_t now = time(NULL);
if (x_stat(conf->cache_dir, &st) != 0 || st.st_mtime + 3600 >= now) {
- /* No cleanup needed. */
+ // No cleanup needed.
return;
}
return current_working_dir;
}
-/*
- * Transform a name to a full path into the cache directory, creating needed
- * sublevels if needed. Caller frees.
- */
+// Transform a name to a full path into the cache directory, creating needed
+// sublevels if needed. Caller frees.
static char *
get_path_in_cache(const char *name, const char *suffix)
{
return result;
}
-/*
- * This function hashes an include file and stores the path and hash in the
- * global included_files variable. If the include file is a PCH, cpp_hash is
- * also updated. Takes over ownership of path.
- */
+// This function hashes an include file and stores the path and hash in the
+// global included_files variable. If the include file is a PCH, cpp_hash is
+// also updated. Takes over ownership of path.
static void
remember_include_file(char *path, struct mdfour *cpp_hash, bool system)
{
size_t i;
if (path_len >= 2 && (path[0] == '<' && path[path_len - 1] == '>')) {
- /* Typically <built-in> or <command-line>. */
+ // Typically <built-in> or <command-line>.
goto ignore;
}
if (str_eq(path, input_file)) {
- /* Don't remember the input file. */
+ // Don't remember the input file.
goto ignore;
}
if (system && (conf->sloppiness & SLOPPY_NO_SYSTEM_HEADERS)) {
- /* Don't remember this system header. */
+ // Don't remember this system header.
goto ignore;
}
if (hashtable_search(included_files, path)) {
- /* Already known include file. */
+ // Already known include file.
goto ignore;
}
#ifdef _WIN32
- /* stat fails on directories on win32 */
+ // stat fails on directories on win32.
attributes = GetFileAttributes(path);
if (attributes != INVALID_FILE_ATTRIBUTES &&
attributes & FILE_ATTRIBUTE_DIRECTORY) {
goto failure;
}
if (S_ISDIR(st.st_mode)) {
- /* Ignore directory, typically $PWD. */
+ // Ignore directory, typically $PWD.
goto ignore;
}
if (!S_ISREG(st.st_mode)) {
- /* Device, pipe, socket or other strange creature. */
+ // Device, pipe, socket or other strange creature.
cc_log("Non-regular include file %s", path);
goto failure;
}
- /* canonicalize path for comparison, clang uses ./header.h */
+ // Canonicalize path for comparison; clang uses ./header.h.
canonical = path;
canonical_len = path_len;
if (canonical[0] == '.' && canonical[1] == '/') {
}
}
- /* Let's hash the include file. */
+ // Let's hash the include file.
if (!(conf->sloppiness & SLOPPY_INCLUDE_FILE_MTIME)
&& st.st_mtime >= time_of_compilation) {
cc_log("Include file %s too new", path);
if (conf->direct_mode) {
struct file_hash *h;
- if (!is_pch) { /* else: the file has already been hashed. */
+ if (!is_pch) { // else: the file has already been hashed.
int result;
if (st.st_size > 0) {
cc_log("Disabling direct mode");
conf->direct_mode = false;
}
- /* Fall through. */
+ // Fall through.
ignore:
free(path);
free(source);
}
-/*
- * Make a relative path from current working directory to path if path is under
- * the base directory. Takes over ownership of path. Caller frees.
- */
+// Make a relative path from current working directory to path if path is under
+// the base directory. Takes over ownership of path. Caller frees.
static char *
make_relative_path(char *path)
{
#ifdef _WIN32
if (path[0] == '/') {
- path++; /* skip leading slash */
+ path++; // Skip leading slash.
}
#endif
- /* x_realpath only works for existing paths, so if path doesn't exist, try
- * dirname(path) and assemble the path afterwards. We only bother to try
- * canonicalizing one of these two paths since a compiler path argument
- * typically only makes sense if path or dirname(path) exists. */
+ // x_realpath only works for existing paths, so if path doesn't exist, try
+ // dirname(path) and assemble the path afterwards. We only bother to try
+ // canonicalizing one of these two paths since a compiler path argument
+ // typically only makes sense if path or dirname(path) exists.
if (stat(path, &st) != 0) {
- /* path doesn't exist. */
+ // path doesn't exist.
char *dir, *p;
dir = dirname(path);
if (stat(dir, &st) != 0) {
- /* And neither does its parent directory, so no action to take. */
+ // And neither does its parent directory, so no action to take.
free(dir);
return path;
}
return relpath;
}
} else {
- /* path doesn't exist, so leave it as it is. */
+ // path doesn't exist, so leave it as it is.
free(path_suffix);
return path;
}
}
-/*
- * This function reads and hashes a file. While doing this, it also does these
- * things:
- *
- * - Makes include file paths for which the base directory is a prefix relative
- * when computing the hash sum.
- * - Stores the paths and hashes of included files in the global variable
- * included_files.
- */
+// This function reads and hashes a file. While doing this, it also does these
+// things:
+//
+// - Makes include file paths for which the base directory is a prefix relative
+// when computing the hash sum.
+// - Stores the paths and hashes of included files in the global variable
+// included_files.
static bool
process_preprocessed_file(struct mdfour *hash, const char *path)
{
included_files = create_hashtable(1000, hash_from_string, strings_equal);
}
- /* Bytes between p and q are pending to be hashed. */
+ // Bytes between p and q are pending to be hashed.
end = data + size;
p = data;
q = data;
- /* There must be at least 7 characters (# 1 "x") left to potentially find an
- * include file path. */
+ // There must be at least 7 characters (# 1 "x") left to potentially find an
+ // include file path.
while (q < end - 7) {
- /*
- * Check if we look at a line containing the file name of an included file.
- * At least the following formats exist (where N is a positive integer):
- *
- * GCC:
- *
- * # N "file"
- * # N "file" N
- * #pragma GCC pch_preprocess "file"
- *
- * HP's compiler:
- *
- * #line N "file"
- *
- * AIX's compiler:
- *
- * #line N "file"
- * #line N
- *
- * Note that there may be other lines starting with '#' left after
- * preprocessing as well, for instance "# pragma".
- */
+ // Check if we look at a line containing the file name of an included file.
+ // At least the following formats exist (where N is a positive integer):
+ //
+ // GCC:
+ //
+ // # N "file"
+ // # N "file" N
+ // #pragma GCC pch_preprocess "file"
+ //
+ // HP's compiler:
+ //
+ // #line N "file"
+ //
+ // AIX's compiler:
+ //
+ // #line N "file"
+ // #line N
+ //
+ // Note that there may be other lines starting with '#' left after
+ // preprocessing as well, for instance "# pragma".
if (q[0] == '#'
- /* GCC: */
+ // GCC:
&& ((q[1] == ' ' && q[2] >= '0' && q[2] <= '9')
- /* GCC precompiled header: */
+ // GCC precompiled header:
|| (q[1] == 'p'
&& str_startswith(&q[2], "ragma GCC pch_preprocess "))
- /* HP/AIX: */
+ // HP/AIX:
|| (q[1] == 'l' && q[2] == 'i' && q[3] == 'n' && q[4] == 'e'
&& q[5] == ' '))
&& (q == data || q[-1] == '\n')) {
char *path;
bool system;
- /* Workarounds for preprocessor linemarker bugs in GCC version 6 */
+ // Workarounds for preprocessor linemarker bugs in GCC version 6.
if (q[2] == '3') {
if (str_startswith(q, "# 31 \"<command-line>\"\n")) {
- /* Bogus extra line with #31, after the regular #1:
- Ignore the whole line, and continue parsing */
+ // Bogus extra line with #31, after the regular #1: Ignore the whole
+ // line, and continue parsing.
hash_buffer(hash, p, q - p);
while (q < end && *q != '\n') {
q++;
p = q;
continue;
} else if (str_startswith(q, "# 32 \"<command-line>\" 2\n")) {
- /* Bogus wrong line with #32, instead of regular #1:
- Replace the line number with the usual one */
+ // Bogus wrong line with #32, instead of regular #1: Replace the line
+ // number with the usual one.
hash_buffer(hash, p, q - p);
q += 1;
q[0] = '#';
q++;
}
if (q < end && *q == '\n') {
- /* A newline before the quotation mark -> no match. */
+ // A newline before the quotation mark -> no match.
continue;
}
q++;
free(data);
return false;
}
- /* q points to the beginning of an include file path */
+ // q points to the beginning of an include file path
hash_buffer(hash, p, q - p);
p = q;
while (q < end && *q != '"') {
q++;
}
- /* look for preprocessor flags, after the "filename" */
+ // Look for preprocessor flags, after the "filename".
system = false;
r = q + 1;
while (r < end && *r != '\n') {
- if (*r == '3') { /* system header */
+ if (*r == '3') { // system header
system = true;
}
r++;
}
- /* p and q span the include file path */
+ // p and q span the include file path.
path = x_strndup(p, q - p);
if (!has_absolute_include_headers) {
has_absolute_include_headers = is_absolute_path(path);
hash_buffer(hash, p, (end - p));
free(data);
- /* Explicitly check the .gch/.pch/.pth file, Clang does not include any
- * mention of it in the preprocessed output. */
+ // Explicitly check the .gch/.pch/.pth file, Clang does not include any
+ // mention of it in the preprocessed output.
if (included_pch_file) {
char *path = x_strdup(included_pch_file);
path = make_relative_path(path);
return true;
}
-/*
- * Replace absolute paths with relative paths in the provided dependency file.
- */
+// Replace absolute paths with relative paths in the provided dependency file.
static void
use_relative_paths_in_depfile(const char *depfile)
{
if (str_eq(conf->base_dir, "")) {
cc_log("Base dir not set, skip using relative paths");
- return; /* nothing to do */
+ return; // nothing to do
}
if (!has_absolute_include_headers) {
cc_log("No absolute path for included files found, skip using relative"
" paths");
- return; /* nothing to do */
+ return; // nothing to do
}
f = fopen(depfile, "r");
} else {
relpath = token;
}
- if (token != buf) { /* this is a dependency file */
+ if (token != buf) { // this is a dependency file
fputc(' ', tmpf);
}
fputs(relpath, tmpf);
free(tmp_file);
}
-/* Copy or link a file to the cache. */
+// Copy or link a file to the cache.
static void
put_file_in_cache(const char *source, const char *dest)
{
stats_update_size(file_size(&st), 1);
}
-/* Copy or link a file from the cache. */
+// Copy or link a file from the cache.
static void
get_file_from_cache(const char *source, const char *dest)
{
if (ret == -1) {
if (errno == ENOENT || errno == ESTALE) {
- /* Someone removed the file just before we began copying? */
+ // Someone removed the file just before we began copying?
cc_log("Cache file %s just disappeared from cache", source);
stats_update(STATS_MISSING);
} else {
stats_update(STATS_ERROR);
}
- /* If there was trouble getting a file from the cached result, wipe the
- * whole cached result for consistency. */
+ // If there was trouble getting a file from the cached result, wipe the
+ // whole cached result for consistency.
x_unlink(cached_stderr);
x_unlink(cached_obj);
x_unlink(cached_dep);
cc_log("Created from cache: %s -> %s", source, dest);
}
-/* Send cached stderr, if any, to stderr. */
+// Send cached stderr, if any, to stderr.
static void
send_cached_stderr(void)
{
}
}
-/* Create or update the manifest file. */
+// Create or update the manifest file.
void update_manifest_file(void)
{
struct stat st;
- size_t old_size = 0; /* in bytes */
+ size_t old_size = 0; // in bytes
if (!conf->direct_mode
|| !included_files
}
}
-/* run the real compiler and put the result in cache */
+// Run the real compiler and put the result in cache.
static void
to_cache(struct args *args)
{
if (generating_coverage) {
char *tmp_aux;
- /* gcc has some funny rule about max extension length */
+ // GCC has some funny rule about max extension length.
if (strlen(get_extension(output_obj)) < 6) {
tmp_aux = remove_extension(output_obj);
} else {
tmp_cov = NULL;
}
- /* GCC (at least 4.8 and 4.9) forms the .dwo file name by removing everything
- * after (and including) the last "." from the object file name and then
- * appending ".dwo".
- */
+ // GCC (at least 4.8 and 4.9) forms the .dwo file name by removing everything
+ // after (and including) the last "." from the object file name and then
+ // appending ".dwo".
if (using_split_dwarf) {
char *base_name = remove_extension(output_obj);
tmp_dwo = format("%s.dwo", base_name);
args_add(args, output_dia);
}
- /* Turn off DEPENDENCIES_OUTPUT when running cc1, because
- * otherwise it will emit a line like
- *
- * tmp.stdout.vexed.732.o: /home/mbp/.ccache/tmp.stdout.vexed.732.i
- */
+ // Turn off DEPENDENCIES_OUTPUT when running cc1, because otherwise it will
+ // emit a line like this:
+ //
+ // tmp.stdout.vexed.732.o: /home/mbp/.ccache/tmp.stdout.vexed.732.i
x_unsetenv("DEPENDENCIES_OUTPUT");
if (conf->run_second_cpp) {
args_pop(args, 3);
if (x_stat(tmp_stdout, &st) != 0) {
- /* The stdout file was removed - cleanup in progress? Better bail out. */
+ // The stdout file was removed - cleanup in progress? Better bail out.
stats_update(STATS_MISSING);
tmp_unlink(tmp_stdout);
tmp_unlink(tmp_stderr);
}
tmp_unlink(tmp_stdout);
- /*
- * Merge stderr from the preprocessor (if any) and stderr from the real
- * compiler into tmp_stderr.
- */
+ // Merge stderr from the preprocessor (if any) and stderr from the real
+ // compiler into tmp_stderr.
if (cpp_stderr) {
int fd_cpp_stderr;
int fd_real_stderr;
fd = open(tmp_stderr, O_RDONLY | O_BINARY);
if (fd != -1) {
- /* We can output stderr immediately instead of rerunning the compiler. */
+ // We can output stderr immediately instead of rerunning the compiler.
copy_fd(fd, 2);
close(fd);
tmp_unlink(tmp_stderr);
}
cc_log("Stored in cache: %s", cached_stderr);
if (!conf->compression
- /* If the file was compressed, obtain the size again: */
+ // If the file was compressed, obtain the size again:
|| x_stat(cached_stderr, &st) == 0) {
stats_update_size(file_size(&st), 1);
}
} else {
tmp_unlink(tmp_stderr);
if (conf->recache) {
- /* If recaching, we need to remove any previous .stderr. */
+ // If recaching, we need to remove any previous .stderr.
x_unlink(cached_stderr);
}
}
if (generating_coverage) {
- /* gcc won't generate notes if there is no code */
+ // 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);
}
stats_update(STATS_TOCACHE);
- /* Make sure we have a CACHEDIR.TAG in the cache part of cache_dir. This can
- * be done almost anywhere, but we might as well do it near the end as we
- * save the stat call if we exit early.
- */
+ // Make sure we have a CACHEDIR.TAG in the cache part of cache_dir. This can
+ // be done almost anywhere, but we might as well do it near the end as we
+ // save the stat call if we exit early.
{
char *first_level_dir = dirname(stats_file);
if (create_cachedirtag(first_level_dir) != 0) {
}
free(first_level_dir);
- /* Remove any CACHEDIR.TAG on the cache_dir level where it was located in
- * previous ccache versions. */
+ // Remove any CACHEDIR.TAG on the cache_dir level where it was located in
+ // previous ccache versions.
if (getpid() % 1000 == 0) {
char *path = format("%s/CACHEDIR.TAG", conf->cache_dir);
x_unlink(path);
}
}
- /* Everything OK. */
+ // Everything OK.
send_cached_stderr();
update_manifest_file();
free(tmp_dwo);
}
-/*
- * Find the object file name by running the compiler in preprocessor mode.
- * Returns the hash as a heap-allocated hex string.
- */
+// Find the object file name by running the compiler in preprocessor mode.
+// Returns the hash as a heap-allocated hex string.
static struct file_hash *
get_object_name_from_cpp(struct args *args, struct mdfour *hash)
{
int status, path_stderr_fd;
struct file_hash *result;
- /* ~/hello.c -> tmp.hello.123.i
- * limit the basename to 10
- * characters in order to cope with filesystem with small
- * maximum filename length limits */
+ // Limit the basename to 10 characters in order to cope with filesystem with
+ // small maximum filename length limits.
input_base = basename(input_file);
tmp = strchr(input_base, '.');
if (tmp) {
time_of_compilation = time(NULL);
if (direct_i_file) {
- /* We are compiling a .i or .ii file - that means we can skip the cpp stage
- * and directly form the correct i_tmpfile. */
+ // We are compiling a .i or .ii file - that means we can skip the cpp stage
+ // and directly form the correct i_tmpfile.
path_stdout = input_file;
status = 0;
} else {
- /* Run cpp on the input file to obtain the .i. */
+ // Run cpp on the input file to obtain the .i.
int path_stdout_fd;
path_stdout = format("%s/%s.stdout", temp_dir(), input_base);
path_stdout_fd = create_tmp_fd(&path_stdout);
}
if (conf->unify) {
- /* When we are doing the unifying tricks we need to include the input file
- * name in the hash to get the warnings right. */
+ // When we are doing the unifying tricks we need to include the input file
+ // name in the hash to get the warnings right.
hash_delimiter(hash, "unifyfilename");
hash_string(hash, input_file);
if (direct_i_file) {
i_tmpfile = input_file;
} else {
- /* i_tmpfile needs the proper cpp_extension for the compiler to do its
- * thing correctly. */
+ // i_tmpfile needs the proper cpp_extension for the compiler to do its
+ // thing correctly
i_tmpfile = format("%s.%s", path_stdout, conf->cpp_extension);
x_rename(path_stdout, i_tmpfile);
add_pending_tmp_file(i_tmpfile);
if (conf->run_second_cpp) {
free(path_stderr);
} else {
- /*
- * If we are using the CPP trick, we need to remember this
- * stderr data and output it just before the main stderr from
- * the compiler pass.
- */
+ // If we are using the CPP trick, we need to remember this stderr data and
+ // output it just before the main stderr from the compiler pass.
cpp_stderr = path_stderr;
hash_delimiter(hash, "runsecondcpp");
hash_string(hash, "false");
free(object_name);
}
-/*
- * Hash mtime or content of a file, or the output of a command, according to
- * the CCACHE_COMPILERCHECK setting.
- */
+// Hash mtime or content of a file, or the output of a command, according to
+// the CCACHE_COMPILERCHECK setting.
static void
hash_compiler(struct mdfour *hash, struct stat *st, const char *path,
bool allow_command)
{
if (str_eq(conf->compiler_check, "none")) {
- /* Do nothing. */
+ // Do nothing.
} else if (str_eq(conf->compiler_check, "mtime")) {
hash_delimiter(hash, "cc_mtime");
hash_int(hash, st->st_size);
} else if (str_eq(conf->compiler_check, "content") || !allow_command) {
hash_delimiter(hash, "cc_content");
hash_file(hash, path);
- } else { /* command string */
+ } else { // command string
if (!hash_multicommand_output(
hash, conf->compiler_check, orig_args->argv[0])) {
fatal("Failure running compiler check command: %s", conf->compiler_check);
}
}
-/*
- * Note that these compiler checks are unreliable, so nothing should
- * hard-depend on them.
- */
+// Note that these compiler checks are unreliable, so nothing should
+// hard-depend on them.
static bool
compiler_is_clang(struct args *args)
return is;
}
-/*
- * Update a hash sum with information common for the direct and preprocessor
- * modes.
- */
+// Update a hash sum with information common for the direct and preprocessor
+// modes.
static void
calculate_common_hash(struct args *args, struct mdfour *hash)
{
hash_string(hash, HASH_PREFIX);
- /*
- * We have to hash the extension, as a .i file isn't treated the same
- * by the compiler as a .ii file.
- */
+ // We have to hash the extension, as a .i file isn't treated the same by the
+ // compiler as a .ii file.
hash_delimiter(hash, "ext");
hash_string(hash, conf->cpp_extension);
failed();
}
- /*
- * Hash information about the compiler.
- */
+ // Hash information about the compiler.
hash_compiler(hash, &st, args->argv[0], true);
- /*
- * Also hash the compiler name as some compilers use hard links and
- * behave differently depending on the real name.
- */
+ // Also hash the compiler name as some compilers use hard links and behave
+ // differently depending on the real name.
hash_delimiter(hash, "cc_name");
p = basename(args->argv[0]);
hash_string(hash, p);
free(p);
- /* Possibly hash the current working directory. */
+ // Possibly hash the current working directory.
if (generating_debuginfo && conf->hash_dir) {
char *cwd = gnu_getcwd();
if (debug_prefix_map) {
}
}
- /* Possibly hash the coverage data file path. */
+ // Possibly hash the coverage data file path.
if (generating_coverage && profile_arcs) {
char *dir = dirname(output_obj);
if (profile_dir) {
free(p);
}
- /* Possibly hash GCC_COLORS (for color diagnostics). */
+ // Possibly hash GCC_COLORS (for color diagnostics).
if (compiler_is_gcc(args)) {
const char *gcc_colors = getenv("GCC_COLORS");
if (gcc_colors) {
}
}
-/*
- * Update a hash sum with information specific to the direct and preprocessor
- * modes and calculate the object hash. Returns the object hash on success,
- * otherwise NULL. Caller frees.
- */
+// Update a hash sum with information specific to the direct and preprocessor
+// modes and calculate the object hash. Returns the object hash on success,
+// otherwise NULL. Caller frees.
static struct file_hash *
calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode)
{
hash_int(hash, MANIFEST_VERSION);
}
- /* first the arguments */
+ // First the arguments.
for (i = 1; i < args->argc; i++) {
- /* -L doesn't affect compilation. */
+ // -L doesn't affect compilation.
if (i < args->argc-1 && str_eq(args->argv[i], "-L")) {
i++;
continue;
continue;
}
- /* -Wl,... doesn't affect compilation. */
+ // -Wl,... doesn't affect compilation.
if (str_startswith(args->argv[i], "-Wl,")) {
continue;
}
- /* The -fdebug-prefix-map option may be used in combination with
- * CCACHE_BASEDIR to reuse results across different directories. Skip it
- * from hashing. */
+ // The -fdebug-prefix-map option may be used in combination with
+ // CCACHE_BASEDIR to reuse results across different directories. Skip it
+ // from hashing.
if (str_startswith(args->argv[i], "-fdebug-prefix-map=")) {
continue;
}
- /* When using the preprocessor, some arguments don't contribute
- * to the hash. The theory is that these arguments will change
- * the output of -E if they are going to have any effect at
- * all. For precompiled headers this might not be the case. */
+ // When using the preprocessor, some arguments don't contribute to the
+ // hash. The theory is that these arguments will change the output of -E if
+ // they are going to have any effect at all. For precompiled headers this
+ // might not be the case.
if (!direct_mode && !output_is_precompiled_header
&& !using_precompiled_header) {
if (compopt_affects_cpp(args->argv[i])) {
}
}
- /* If we're generating dependencies, we make sure to skip the
- * filename of the dependency file, since it doesn't impact the
- * output.
- */
+ // If we're generating dependencies, we make sure to skip the filename of
+ // the dependency file, since it doesn't impact the output.
if (generating_dependencies) {
if (str_startswith(args->argv[i], "-Wp,")) {
if (str_startswith(args->argv[i], "-Wp,-MD,")
} else if (str_startswith(args->argv[i], "-MF")) {
bool separate_argument = (strlen(args->argv[i]) == 3);
- /* In either case, hash the "-MF" part. */
+ // In either case, hash the "-MF" part.
hash_string_length(hash, args->argv[i], 3);
if (separate_argument) {
- /* Next argument is dependency name, so
- * skip it. */
+ // Next argument is dependency name, so skip it.
i++;
}
continue;
p = args->argv[i] + 8;
}
if (p && x_stat(p, &st) == 0) {
- /* If given an explicit specs file, then hash that file,
- * but don't include the path to it in the hash. */
+ // If given an explicit specs file, then hash that file, but don't
+ // include the path to it in the hash.
hash_delimiter(hash, "specs");
hash_compiler(hash, &st, p, false);
continue;
continue;
}
- /* All other arguments are included in the hash. */
+ // All other arguments are included in the hash.
hash_delimiter(hash, "arg");
hash_string(hash, args->argv[i]);
if (i + 1 < args->argc && compopt_takes_arg(args->argv[i])) {
}
}
- /*
- * For profile generation (-fprofile-arcs, -fprofile-generate):
- * - hash profile directory
- * - output to the real file first
- *
- * For profile usage (-fprofile-use):
- * - hash profile data
- *
- * -fbranch-probabilities and -fvpt usage is covered by
- * -fprofile-generate/-fprofile-use.
- *
- * The profile directory can be specified as an argument to
- * -fprofile-generate=, -fprofile-use=, or -fprofile-dir=.
- */
-
- /*
- * We need to output to the real object first here, otherwise runtime
- * artifacts will be produced in the wrong place.
- */
+ // For profile generation (-fprofile-arcs, -fprofile-generate):
+ // - hash profile directory
+ // - output to the real file first
+ //
+ // For profile usage (-fprofile-use):
+ // - hash profile data
+ //
+ // -fbranch-probabilities and -fvpt usage is covered by
+ // -fprofile-generate/-fprofile-use.
+ //
+ // The profile directory can be specified as an argument to
+ // -fprofile-generate=, -fprofile-use=, or -fprofile-dir=.
+
+ // We need to output to the real object first here, otherwise runtime
+ // artifacts will be produced in the wrong place.
if (profile_generate) {
if (!profile_dir) {
profile_dir = get_cwd();
}
if (profile_use) {
- /* Calculate gcda name */
+ // Calculate gcda name.
char *gcda_name;
char *base_name;
base_name = remove_extension(output_obj);
}
gcda_name = format("%s/%s.gcda", profile_dir, base_name);
cc_log("Adding profile data %s to our hash", gcda_name);
- /* Add the gcda to our hash */
+ // Add the gcda to our hash.
hash_delimiter(hash, "-fprofile-use");
hash_file(hash, gcda_name);
free(base_name);
char *manifest_name;
int result;
- /* Hash environment variables that affect the preprocessor output. */
+ // Hash environment variables that affect the preprocessor output.
const char **p;
const char *envvars[] = {
"CPATH",
"C_INCLUDE_PATH",
"CPLUS_INCLUDE_PATH",
"OBJC_INCLUDE_PATH",
- "OBJCPLUS_INCLUDE_PATH", /* clang */
+ "OBJCPLUS_INCLUDE_PATH", // clang
NULL
};
for (p = envvars; *p; ++p) {
}
if (!(conf->sloppiness & SLOPPY_FILE_MACRO)) {
- /*
- * The source code file or an include file may contain
- * __FILE__, so make sure that the hash is unique for
- * the file name.
- */
+ // The source code file or an include file may contain __FILE__, so make
+ // sure that the hash is unique for the file name.
hash_delimiter(hash, "inputfile");
hash_string(hash, input_file);
}
return object_hash;
}
-/*
- * Try to return the compile result from cache. If we can return from cache
- * then this function exits with the correct status code, otherwise it returns.
- */
+// Try to return the compile result from cache. If we can return from cache
+// then this function exits with the correct status code, otherwise it returns.
static void
from_cache(enum fromcache_call_mode mode, bool put_object_in_manifest)
{
struct stat st;
bool produce_dep_file = false;
- /* the user might be disabling cache hits */
+ // The user might be disabling cache hits.
if (conf->recache) {
return;
}
return;
}
- /* Check if the diagnostic file is there. */
+ // Check if the diagnostic file is there.
if (output_dia && stat(cached_dia, &st) != 0) {
cc_log("Diagnostic file %s not in cache", cached_dia);
return;
}
- /*
- * Occasionally, e.g. on hard reset, our cache ends up as just filesystem
- * meta-data with no content. Catch an easy case of this.
- */
+ // Occasionally, e.g. on hard reset, our cache ends up as just filesystem
+ // meta-data with no content. Catch an easy case of this.
if (st.st_size == 0) {
cc_log("Invalid (empty) object file %s in cache", cached_obj);
x_unlink(cached_obj);
if (st.st_size == 0) {
cc_log("Invalid (empty) dwo file %s in cache", cached_dwo);
x_unlink(cached_dwo);
- x_unlink(cached_obj); /* to really invalidate */
+ x_unlink(cached_obj); // To really invalidate.
return;
}
}
- /*
- * (If mode != FROMCACHE_DIRECT_MODE, the dependency file is created by
- * gcc.)
- */
+ // (If mode != FROMCACHE_DIRECT_MODE, the dependency file is created by gcc.)
produce_dep_file = generating_dependencies && mode == FROMCACHE_DIRECT_MODE;
- /* If the dependency file should be in the cache, check that it is. */
+ // If the dependency file should be in the cache, check that it is.
if (produce_dep_file && stat(cached_dep, &st) != 0) {
cc_log("Dependency file %s missing in cache", cached_dep);
return;
}
- /*
- * Copy object file from cache. Do so also for FissionDwarf file, cached_dwo,
- * when -gsplit-dwarf is specified.
- */
+ // Copy object file from cache. Do so also for FissionDwarf file, cached_dwo,
+ // when -gsplit-dwarf is specified.
if (!str_eq(output_obj, "/dev/null")) {
get_file_from_cache(cached_obj, output_obj);
if (using_split_dwarf) {
get_file_from_cache(cached_dep, output_dep);
}
if (generating_coverage && stat(cached_cov, &st) == 0 && st.st_size > 0) {
- /* gcc won't generate notes if there is no code */
+ // The compiler won't generate notes if there is no code
get_file_from_cache(cached_cov, output_cov);
}
if (output_dia) {
get_file_from_cache(cached_dia, output_dia);
}
- /* Update modification timestamps to save files from LRU cleanup.
- * Also gives files a sensible mtime when hard-linking. */
+ // Update modification timestamps to save files from LRU cleanup. Also gives
+ // files a sensible mtime when hard-linking.
update_mtime(cached_obj);
update_mtime(cached_stderr);
if (produce_dep_file) {
update_manifest_file();
}
- /* log the cache hit */
+ // Log the cache hit.
switch (mode) {
case FROMCACHE_DIRECT_MODE:
cc_log("Succeeded getting cached result");
break;
}
- /* and exit with the right status code */
+ // And exit with the right status code.
x_exit(0);
}
-/* find the real compiler. We just search the PATH to find an executable of the
- * same name that isn't a link to ourselves */
+// Find the real compiler. We just search the PATH to find an executable of the
+// same name that isn't a link to ourselves.
static void
find_compiler(char **argv)
{
base = basename(argv[0]);
- /* we might be being invoked like "ccache gcc -c foo.c" */
+ // We might be being invoked like "ccache gcc -c foo.c".
if (same_executable_name(base, MYNAME)) {
args_remove_first(orig_args);
free(base);
if (is_full_path(orig_args->argv[0])) {
- /* a full path was given */
+ // A full path was given.
return;
}
base = basename(orig_args->argv[0]);
}
- /* support user override of the compiler */
+ // Support user override of the compiler.
if (!str_eq(conf->compiler, "")) {
base = conf->compiler;
}
compiler = find_executable(base, MYNAME);
- /* can't find the compiler! */
+ // Can't find the compiler!
if (!compiler) {
stats_update(STATS_COMPILER);
fatal("Could not find compiler \"%s\" in PATH", base);
char *pch_file = NULL;
struct stat st;
- /* Try to be smart about detecting precompiled headers */
+ // Try to be smart about detecting precompiled headers.
if (str_eq(option, "-include-pch") || str_eq(option, "-include-pth")) {
if (stat(arg, &st) == 0) {
cc_log("Detected use of precompiled header: %s", arg);
cc_log("Detected use of precompiled header: %s", pchpath);
pch_file = x_strdup(pchpath);
} else {
- /* clang may use pretokenized headers */
+ // clang may use pretokenized headers.
char *pthpath = format("%s.pth", arg);
if (stat(pthpath, &st) == 0) {
cc_log("Detected use of pretokenized header: %s", pthpath);
return true;
}
-/*
- * 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 true on success, otherwise false.
- */
+// 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 true on success, otherwise false.
bool
cc_process_args(struct args *args, struct args **preprocessor_args,
struct args **compiler_args)
bool found_S_opt = false;
bool found_pch = false;
bool found_fpch_preprocess = 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 *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? */
+ // Is the dependency makefile name overridden with -MF?
bool dependency_filename_specified = false;
- /* Is the dependency makefile target name specified with -MT or -MQ? */
+ // Is the dependency makefile target name specified with -MT or -MQ?
bool dependency_target_specified = false;
- /* expanded_args is a copy of the original arguments given to the compiler
- but with arguments from @file and similar constructs expanded. It's only
- used as a temporary data structure to loop over. */
+ // expanded_args is a copy of the original arguments given to the compiler
+ // but with arguments from @file and similar constructs expanded. It's only
+ // used as a temporary data structure to loop over.
struct args *expanded_args;
- /* stripped_args essentially contains all original arguments except those
- that only should be passed to the preprocessor (if run_second_cpp is
- false) and except dependency options (like -MD and friends). */
+ // stripped_args essentially contains all original arguments except those
+ // that only should be passed to the preprocessor (if run_second_cpp is
+ // false) and except dependency options (like -MD and friends).
struct args *stripped_args;
- /* cpp_args contains arguments that were not added to stripped_args, i.e.
- those that should only be passed to the preprocessor if run_second_cpp is
- false. If run_second_cpp is true, they will be passed to the compiler as
- well. */
+ // cpp_args contains arguments that were not added to stripped_args, i.e.
+ // those that should only be passed to the preprocessor if run_second_cpp is
+ // false. If run_second_cpp is true, they will be passed to the compiler as
+ // well.
struct args *cpp_args;
- /* dep_args contains dependency options like -MD. They only passed to the
- preprocessor, never to the compiler. */
+ // dep_args contains dependency options like -MD. They only passed to the
+ // preprocessor, never to the compiler.
struct args *dep_args;
int argc;
char **argv;
args_add(stripped_args, argv[0]);
for (i = 1; i < argc; i++) {
- /* The user knows best: just swallow the next arg */
+ // The user knows best: just swallow the next arg.
if (str_eq(argv[i], "--ccache-skip")) {
i++;
if (i == argc) {
continue;
}
- /* Special case for -E. */
+ // Special case for -E.
if (str_eq(argv[i], "-E")) {
stats_update(STATS_PREPROCESSING);
result = false;
goto out;
}
- /* Handle "@file" argument. */
+ // Handle "@file" argument.
if (str_startswith(argv[i], "@") || str_startswith(argv[i], "-@")) {
char *argpath = argv[i] + 1;
struct args *file_args;
continue;
}
- /* Handle cuda "-optf" and "--options-file" argument. */
+ // Handle cuda "-optf" and "--options-file" argument.
if (str_eq(argv[i], "-optf") || str_eq(argv[i], "--options-file")) {
if (i > argc) {
cc_log("Expected argument after -optf/--options-file");
}
++i;
- /* Argument is a comma-separated list of files. */
+ // Argument is a comma-separated list of files.
char *str_start = argv[i];
char *str_end = strchr(str_start, ',');
int index = i + 1;
continue;
}
- /* These are always too hard. */
+ // These are always too hard.
if (compopt_too_hard(argv[i])
|| str_startswith(argv[i], "-fdump-")) {
cc_log("Compiler option %s is unsupported", argv[i]);
goto out;
}
- /* These are too hard in direct mode. */
+ // These are too hard in direct mode.
if (conf->direct_mode) {
if (compopt_too_hard_for_direct_mode(argv[i])) {
cc_log("Unsupported compiler option for direct mode: %s", argv[i]);
}
}
- /* -Xarch_* options are too hard. */
+ // -Xarch_* options are too hard.
if (str_startswith(argv[i], "-Xarch_")) {
cc_log("Unsupported compiler option :%s", argv[i]);
stats_update(STATS_UNSUPPORTED);
goto out;
}
- /* Handle -arch options. */
+ // Handle -arch options.
if (str_eq(argv[i], "-arch")) {
if (arch_args_size == MAX_ARCH_ARGS - 1) {
cc_log("Too many -arch compiler options; ccache supports at most %d",
}
++i;
- arch_args[arch_args_size] = x_strdup(argv[i]); /* it will leak */
+ arch_args[arch_args_size] = x_strdup(argv[i]); // It will leak.
++arch_args_size;
if (arch_args_size == 2) {
conf->run_second_cpp = true;
found_fpch_preprocess = true;
}
- /* we must have -c */
+ // We must have -c.
if (str_eq(argv[i], "-c")) {
found_c_opt = true;
continue;
}
- /* -S changes the default extension */
+ // -S changes the default extension.
if (str_eq(argv[i], "-S")) {
args_add(stripped_args, argv[i]);
found_S_opt = true;
continue;
}
- /*
- * Special handling for -x: remember the last specified language before the
- * input file and strip all -x options from the arguments.
- */
+ // Special handling for -x: remember the last specified language before the
+ // input file and strip all -x options from the arguments.
if (str_eq(argv[i], "-x")) {
if (i == argc-1) {
cc_log("Missing argument to %s", argv[i]);
continue;
}
- /* we need to work out where the output was meant to go */
+ // We need to work out where the output was meant to go.
if (str_eq(argv[i], "-o")) {
if (i == argc-1) {
cc_log("Missing argument to %s", argv[i]);
continue;
}
- /* alternate form of -o, with no space */
+ // Alternate form of -o with no space.
if (str_startswith(argv[i], "-o")) {
output_obj = make_relative_path(x_strdup(&argv[i][2]));
continue;
continue;
}
- /* Debugging is handled specially, so that we know if we can strip line
- * number info. */
+ // Debugging is handled specially, so that we know if we can strip line
+ // number info.
if (str_startswith(argv[i], "-g")) {
const char *pLevel = argv[i] + 2;
int foundlevel = -1;
pLevel = argv[i] + 5;
}
- /* Deduce level from argument, default is 2. */
+ // Deduce level from argument, default is 2.
if (pLevel[0] == '\0') {
foundlevel = 2;
} else if (pLevel[0] >= '0' && pLevel[0] <= '9') {
}
}
- /* These options require special handling, because they
- * behave differently with gcc -E, when the output
- * file is not specified. */
+ // These options require special handling, because they 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 = true;
args_add(dep_args, argv[i]);
dependency_filename_specified = true;
free(output_dep);
if (separate_argument) {
- /* -MF arg */
+ // -MF arg
if (i >= argc - 1) {
cc_log("Missing argument to %s", argv[i]);
stats_update(STATS_ARGS);
arg = argv[i + 1];
i++;
} else {
- /* -MFarg */
+ // -MFarg
arg = &argv[i][3];
}
output_dep = make_relative_path(x_strdup(arg));
- /* Keep the format of the args the same */
+ // Keep the format of the args the same.
if (separate_argument) {
args_add(dep_args, "-MF");
args_add(dep_args, output_dep);
char *relpath;
dependency_target_specified = true;
if (strlen(argv[i]) == 3) {
- /* -MQ arg or -MT arg */
+ // -MQ arg or -MT arg
if (i >= argc - 1) {
cc_log("Missing argument to %s", argv[i]);
stats_update(STATS_ARGS);
args_add(stripped_args, argv[i]);
continue;
}
- if (str_eq(argv[i], "--coverage")) { /* = -fprofile-arcs -ftest-coverage */
+ if (str_eq(argv[i], "--coverage")) { // = -fprofile-arcs -ftest-coverage
profile_arcs = true;
generating_coverage = true;
args_add(stripped_args, argv[i]);
}
if (str_startswith(argv[i], "-Wp,")) {
if (str_eq(argv[i], "-Wp,-P") || strstr(argv[i], ",-P,")) {
- /* -P removes preprocessor information in such a way that the object
- * file from compiling the preprocessed file will not be equal to the
- * object file produced when compiling without ccache. */
+ // -P removes preprocessor information in such a way that the object
+ // file from compiling the preprocessed file will not be equal to the
+ // object file produced when compiling without ccache.
cc_log("Too hard option -Wp,-P detected");
stats_update(STATS_UNSUPPORTED);
failed();
continue;
} else if (str_startswith(argv[i], "-Wp,-D")
&& !strchr(argv[i] + 6, ',')) {
- /* Treat it like -D */
+ // Treat it like -D.
args_add(dep_args, argv[i] + 4);
continue;
} else if (conf->direct_mode) {
- /*
- * -Wp, can be used to pass too hard options to
- * the preprocessor. Hence, disable direct
- * mode.
- */
+ // -Wp, can be used to pass too hard options to the preprocessor.
+ // Hence, disable direct mode.
cc_log("Unsupported compiler option for direct mode: %s", argv[i]);
conf->direct_mode = false;
}
continue;
}
- /* Input charset needs to be handled specially. */
+ // Input charset needs to be handled specially.
if (str_startswith(argv[i], "-finput-charset=")) {
input_charset = argv[i];
continue;
char *option = x_strndup(argv[i], arg_profile_dir - argv[i]);
char *dir;
- /* Convert to absolute path. */
+ // Convert to absolute path.
dir = x_realpath(arg_profile_dir + 1);
if (!dir) {
- /* Directory doesn't exist. */
+ // Directory doesn't exist.
dir = x_strdup(arg_profile_dir + 1);
}
- /* We can get a better hit rate by using the real path here. */
+ // We can get a better hit rate by using the real path here.
free(arg);
arg = format("%s=%s", option, dir);
cc_log("Rewriting %s to %s", argv[i], arg);
args_add(stripped_args, arg);
free(arg);
- /*
- * If the profile directory has already been set, give up... Hard to
- * know what the user means, and what the compiler will do.
- */
+ // If the profile directory has already been set, give up... Hard to
+ // know what the user means, and what the compiler will do.
if (arg_profile_dir && profile_dir) {
cc_log("Profile directory already set; giving up");
result = false;
}
if (str_eq(argv[i], "-fdiagnostics-color=auto")) {
if (color_output_possible()) {
- /* Output is redirected, so color output must be forced. */
+ // Output is redirected, so color output must be forced.
args_add(stripped_args, "-fdiagnostics-color=always");
cc_log("Automatically forcing colors");
} else {
continue;
}
- /*
- * Options taking an argument that we may want to rewrite to relative paths
- * to get better hit rate. A secondary effect is that paths in the standard
- * error output produced by the compiler will be normalized.
- */
+ // Options taking an argument that we may want to rewrite to relative paths
+ // to get better hit rate. A secondary effect is that paths in the standard
+ // error output produced by the compiler will be normalized.
if (compopt_takes_path(argv[i])) {
char *relpath;
if (i == argc-1) {
continue;
}
- /*
- * Same as above but options with concatenated argument beginning with a
- * slash.
- */
+ // Same as above but options with concatenated argument beginning with a
+ // slash.
if (argv[i][0] == '-') {
char *slash_pos = strchr(argv[i], '/');
if (slash_pos) {
}
}
- /* options that take an argument */
+ // Options that take an argument.
if (compopt_takes_arg(argv[i])) {
if (i == argc-1) {
cc_log("Missing argument to %s", argv[i]);
continue;
}
- /* other options */
+ // Other options.
if (argv[i][0] == '-') {
if (compopt_affects_cpp(argv[i])
|| compopt_prefix_affects_cpp(argv[i])) {
continue;
}
- /* if an argument isn't a plain file then assume its
- * an option, not an input file. This allows us to
- * cope better with unusual compiler options */
+ // If an argument isn't a plain file then assume its an option, not an
+ // input file. This allows us to cope better with unusual compiler options.
if (stat(argv[i], &st) != 0 || !S_ISREG(st.st_mode)) {
cc_log("%s is not a regular file, not considering as input file",
argv[i]);
goto out;
}
- /* The source code file path gets put into the notes */
+ // The source code file path gets put into the notes.
if (generating_coverage) {
input_file = x_strdup(argv[i]);
continue;
}
if (is_symlink(argv[i])) {
- /* Don't rewrite source file path if it's a symlink since
- make_relative_path resolves symlinks using realpath(3) and this leads
- to potentially choosing incorrect relative header files. See the
- "symlink to source file" test. */
+ // Don't rewrite source file path if it's a symlink since
+ // make_relative_path resolves symlinks using realpath(3) and this leads
+ // to potentially choosing incorrect relative header files. See the
+ // "symlink to source file" test.
input_file = x_strdup(argv[i]);
} else {
- /* Rewrite to relative to increase hit rate. */
+ // Rewrite to relative to increase hit rate.
input_file = make_relative_path(x_strdup(argv[i]));
}
- } /* for */
+ } // for
if (debug_level > 0) {
generating_debuginfo = true;
}
if (found_S_opt) {
- /* Even if -gsplit-dwarf is given, the .dwo file is not generated when -S
- * is also given.
- */
+ // Even if -gsplit-dwarf is given, the .dwo file is not generated when -S
+ // is also given.
using_split_dwarf = false;
cc_log("Disabling caching of dwarf files since -S is used");
}
args_add(stripped_args, "-c");
} else {
cc_log("No -c option found");
- /* I find that having a separate statistic for autoconf tests is useful,
- * as they are the dominant form of "called for link" in many cases */
+ // I find that having a separate statistic for autoconf tests is useful,
+ // as they are the dominant form of "called for link" in many cases.
if (strstr(input_file, "conftest.")) {
stats_update(STATS_CONFTEST);
} else {
direct_i_file = language_is_preprocessed(actual_language);
if (output_is_precompiled_header) {
- /* It doesn't work to create the .gch from preprocessed source. */
+ // It doesn't work to create the .gch from preprocessed source.
cc_log("Creating precompiled header; not compiling preprocessed code");
conf->run_second_cpp = true;
}
conf->cpp_extension = x_strdup(extension_for_language(p_language) + 1);
}
- /* don't try to second guess the compilers heuristics for stdout handling */
+ // Don't try to second guess the compilers heuristics for stdout handling.
if (output_obj && str_eq(output_obj, "-")) {
stats_update(STATS_OUTSTDOUT);
cc_log("Output file is -");
}
}
- /* cope with -o /dev/null */
+ // Cope with -o /dev/null.
if (!str_eq(output_obj, "/dev/null")
&& stat(output_obj, &st) == 0
&& !S_ISREG(st.st_mode)) {
goto out;
}
- /*
- * Some options shouldn't be passed to the real compiler when it compiles
- * preprocessed code:
- *
- * -finput-charset=XXX (otherwise conversion happens twice)
- * -x XXX (otherwise the wrong language is selected)
- */
+ // Some options shouldn't be passed to the real compiler when it compiles
+ // preprocessed code:
+ //
+ // -finput-charset=XXX (otherwise conversion happens twice)
+ // -x XXX (otherwise the wrong language is selected)
if (input_charset) {
args_add(cpp_args, input_charset);
}
args_add(cpp_args, explicit_language);
}
- /*
- * Since output is redirected, compilers will not color their output by
- * default, so force it explicitly if it would be otherwise done.
- */
+ // Since output is redirected, compilers will not color their output by
+ // default, so force it explicitly if it would be otherwise done.
if (!found_color_diagnostics && color_output_possible()) {
if (compiler_is_clang(args)) {
args_add(stripped_args, "-fcolor-diagnostics");
cc_log("Automatically enabling colors");
} else if (compiler_is_gcc(args)) {
- /*
- * GCC has it since 4.9, but that'd require detecting what GCC version is
- * used for the actual compile. However it requires also GCC_COLORS to be
- * set (and not empty), so use that for detecting if GCC would use
- * colors.
- */
+ // GCC has it since 4.9, but that'd require detecting what GCC version is
+ // used for the actual compile. However it requires also GCC_COLORS to be
+ // set (and not empty), so use that for detecting if GCC would use
+ // colors.
if (getenv("GCC_COLORS") && getenv("GCC_COLORS")[0] != '\0') {
args_add(stripped_args, "-fdiagnostics-color");
cc_log("Automatically enabling colors");
}
}
- /*
- * Add flags for dependency generation only to the preprocessor command line.
- */
+ // Add flags for dependency generation only to the preprocessor command line.
if (generating_dependencies) {
if (!dependency_filename_specified) {
char *default_depfile_name;
args_extend(*compiler_args, cpp_args);
} else {
if (explicit_language) {
- /*
- * Workaround for a bug in Apple's patched distcc -- it doesn't properly
- * reset the language specified with -x, so if -x is given, we have to
- * specify the preprocessed language explicitly.
- */
+ // Workaround for a bug in Apple's patched distcc -- it doesn't properly
+ // reset the language specified with -x, so if -x is given, we have to
+ // specify the preprocessed language explicitly.
args_add(*compiler_args, "-x");
args_add(*compiler_args, p_language_for_language(explicit_language));
}
args_add(*compiler_args, arch_args[j]);
}
- /*
- * Only pass dependency arguments to the preprocesor since Intel's C++
- * compiler doesn't produce a correct .d file when compiling preprocessed
- * source.
- */
+ // Only pass dependency arguments to the preprocesor since Intel's C++
+ // compiler doesn't produce a correct .d file when compiling preprocessed
+ // source.
args_extend(cpp_args, dep_args);
*preprocessor_args = args_copy(stripped_args);
stats_dir = format("%s/0", conf->cache_dir);
if (stat(stats_dir, &st) == 0) {
stats_get_obsolete_limits(stats_dir, &max_files, &max_size);
- /* STATS_MAXFILES and STATS_MAXSIZE was stored for each top directory. */
+ // STATS_MAXFILES and STATS_MAXSIZE was stored for each top directory.
max_files *= 16;
max_size *= 16;
} else {
fclose(f);
}
-/*
- * Read config file(s), populate variables, create configuration file in cache
- * directory if missing, etc.
- */
+// Read config file(s), populate variables, create configuration file in cache
+// directory if missing, etc.
static void
initialize(void)
{
if (stat(secondary_config_path, &st) == 0) {
fatal("%s", errmsg);
}
- /* Missing config file in SYSCONFDIR is OK. */
+ // Missing config file in SYSCONFDIR is OK.
free(errmsg);
}
}
}
-/* Reset the global state. Used by the test suite. */
+// Reset the global state. Used by the test suite.
void
cc_reset(void)
{
using_split_dwarf = false;
}
-/* Make a copy of stderr that will not be cached, so things like
- * distcc can send networking errors to it. */
+// Make a copy of stderr that will not be cached, so things like distcc can
+// send networking errors to it.
static void
setup_uncached_err(void)
{
failed();
}
- /* leak a pointer to the environment */
+ // Leak a pointer to the environment.
buf = format("UNCACHED_ERR_FD=%d", uncached_fd);
if (putenv(buf) == -1) {
cc_bulklog("Config: (%s) %s", origin, descr);
}
-/* the main ccache driver function */
+// The main ccache driver function.
static void
ccache(int argc, char *argv[])
{
struct mdfour direct_hash;
struct mdfour cpp_hash;
- /* Arguments (except -E) to send to the preprocessor. */
+ // Arguments (except -E) to send to the preprocessor.
struct args *preprocessor_args;
- /* Arguments to send to the real compiler. */
+ // Arguments to send to the real compiler.
struct args *compiler_args;
#ifndef _WIN32
hash_start(&common_hash);
calculate_common_hash(preprocessor_args, &common_hash);
- /* try to find the hash using the manifest */
+ // Try to find the hash using the manifest.
direct_hash = common_hash;
if (conf->direct_mode) {
cc_log("Trying direct lookup");
if (object_hash) {
update_cached_result_globals(object_hash);
- /*
- * If we can return from cache at this point then do
- * so.
- */
+ // If we can return from cache at this point then do so.
from_cache(FROMCACHE_DIRECT_MODE, 0);
- /*
- * Wasn't able to return from cache at this point.
- * However, the object was already found in manifest,
- * so don't readd it later.
- */
+ // Wasn't able to return from cache at this point. However, the object
+ // was already found in manifest, so don't readd it later.
put_object_in_manifest = false;
object_hash_from_manifest = object_hash;
} else {
- /* Add object to manifest later. */
+ // Add object to manifest later.
put_object_in_manifest = true;
}
}
failed();
}
- /*
- * Find the hash using the preprocessed output. Also updates
- * included_files.
- */
+ // Find the hash using the preprocessed output. Also updates included_files.
cpp_hash = common_hash;
object_hash = calculate_object_hash(preprocessor_args, &cpp_hash, 0);
if (!object_hash) {
if (object_hash_from_manifest
&& !file_hashes_equal(object_hash_from_manifest, object_hash)) {
- /*
- * The hash from manifest differs from the hash of the
- * preprocessor output. This could be because:
- *
- * - The preprocessor produces different output for the same
- * input (not likely).
- * - There's a bug in ccache (maybe incorrect handling of
- * compiler arguments).
- * - The user has used a different CCACHE_BASEDIR (most
- * likely).
- *
- * The best thing here would probably be to remove the hash
- * entry from the manifest. For now, we use a simpler method:
- * just remove the manifest file.
- */
+ // The hash from manifest differs from the hash of the preprocessor output.
+ // This could be because:
+ //
+ // - The preprocessor produces different output for the same input (not
+ // likely).
+ // - There's a bug in ccache (maybe incorrect handling of compiler
+ // arguments).
+ // - The user has used a different CCACHE_BASEDIR (most likely).
+ //
+ // The best thing here would probably be to remove the hash entry from the
+ // manifest. For now, we use a simpler method: just remove the manifest
+ // file.
cc_log("Hash from manifest doesn't match preprocessor output");
cc_log("Likely reason: different CCACHE_BASEDIRs used");
cc_log("Removing manifest as a safety measure");
put_object_in_manifest = true;
}
- /* if we can return from cache at this point then do */
+ // If we can return from cache at this point then do.
from_cache(FROMCACHE_CPP_MODE, put_object_in_manifest);
if (conf->read_only) {
add_prefix(compiler_args, conf->prefix_command);
- /* run real compiler, sending output to cache */
+ // Run real compiler, sending output to cache.
to_cache(compiler_args);
x_exit(0);
fprintf(context, "(%s) %s\n", origin, descr);
}
-/* the main program when not doing a compile */
+// The main program when not doing a compile.
static int
ccache_main_options(int argc, char *argv[])
{
manifest_dump(optarg, stdout);
break;
- case 'c': /* --cleanup */
+ case 'c': // --cleanup
initialize();
cleanup_all(conf);
printf("Cleaned cache\n");
break;
- case 'C': /* --clear */
+ case 'C': // --clear
initialize();
wipe_all(conf);
printf("Cleared cache\n");
break;
- case 'h': /* --help */
+ case 'h': // --help
fputs(USAGE_TEXT, stdout);
x_exit(0);
- case 'F': /* --max-files */
+ case 'F': // --max-files
{
unsigned files;
initialize();
}
break;
- case 'M': /* --max-size */
+ case 'M': // --max-size
{
uint64_t size;
initialize();
}
break;
- case 'o': /* --set-config */
+ case 'o': // --set-config
{
char *errmsg, *key, *value, *p;
initialize();
}
break;
- case 'p': /* --print-config */
+ case 'p': // --print-config
initialize();
conf_print_items(conf, configuration_printer, stdout);
break;
- case 's': /* --show-stats */
+ case 's': // --show-stats
initialize();
stats_summary(conf);
break;
- case 'V': /* --version */
+ case 'V': // --version
fprintf(stdout, VERSION_TEXT, CCACHE_VERSION);
x_exit(0);
- case 'z': /* --zero-stats */
+ case 'z': // --zero-stats
initialize();
stats_zero();
printf("Statistics cleared\n");
int
ccache_main(int argc, char *argv[])
{
- /* check if we are being invoked as "ccache" */
+ // Check if we are being invoked as "ccache".
char *program_name = basename(argv[0]);
if (same_executable_name(program_name, MYNAME)) {
if (argc < 2) {
fputs(USAGE_TEXT, stderr);
x_exit(1);
}
- /* if the first argument isn't an option, then assume we are
- * being passed a compiler name and options */
+ // If the first argument isn't an option, then assume we are being passed a
+ // compiler name and options.
if (argv[1][0] == '-') {
return ccache_main_options(argc, argv);
}
extern const char CCACHE_VERSION[];
-/* statistics fields in storage order */
+// Statistics fields in storage order.
enum stats {
STATS_NONE = 0,
STATS_STDOUT = 1,
#define SLOPPY_FILE_MACRO 4
#define SLOPPY_TIME_MACROS 8
#define SLOPPY_PCH_DEFINES 16
-/*
- * Allow us to match files based on their stats (size, mtime, ctime), without
- * looking at their contents.
- */
+// Allow us to match files based on their stats (size, mtime, ctime), without
+// looking at their contents.
#define SLOPPY_FILE_STAT_MATCHES 32
-/*
- * Allow us to not include any system headers in the manifest include files,
- * similar to -MM versus -M for dependencies.
- */
+// Allow us to not include any system headers in the manifest include files,
+// similar to -MM versus -M for dependencies.
#define SLOPPY_NO_SYSTEM_HEADERS 64
#define str_eq(s1, s2) (strcmp((s1), (s2)) == 0)
#define str_startswith(s, p) (strncmp((s), (p), strlen((p))) == 0)
-/* ------------------------------------------------------------------------- */
-/* args.c */
+// ----------------------------------------------------------------------------
+// args.c
struct args {
char **argv;
char *args_to_string(struct args *args);
bool args_equal(struct args *args1, struct args *args2);
-/* ------------------------------------------------------------------------- */
-/* hash.c */
+// ----------------------------------------------------------------------------
+// hash.c
void hash_start(struct mdfour *md);
void hash_buffer(struct mdfour *md, const void *s, size_t len);
bool hash_fd(struct mdfour *md, int fd);
bool hash_file(struct mdfour *md, const char *fname);
-/* ------------------------------------------------------------------------- */
-/* util.c */
+// ----------------------------------------------------------------------------
+// util.c
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void cc_bulklog(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
char *read_text_file(const char *path, size_t size_hint);
char *subst_env_in_string(const char *str, char **errmsg);
-/* ------------------------------------------------------------------------- */
-/* stats.c */
+// ----------------------------------------------------------------------------
+// stats.c
void stats_update(enum stats stat);
void stats_flush(void);
void stats_read(const char *path, struct counters *counters);
void stats_write(const char *path, struct counters *counters);
-/* ------------------------------------------------------------------------- */
-/* unify.c */
+// ----------------------------------------------------------------------------
+// unify.c
int unify_hash(struct mdfour *hash, const char *fname);
-/* ------------------------------------------------------------------------- */
-/* exitfn.c */
+// ----------------------------------------------------------------------------
+// exitfn.c
void exitfn_init(void);
void exitfn_add_nullary(void (*function)(void));
void exitfn_add(void (*function)(void *), void *context);
void exitfn_call(void);
-/* ------------------------------------------------------------------------- */
-/* cleanup.c */
+// ----------------------------------------------------------------------------
+// cleanup.c
void cleanup_dir(struct conf *conf, const char *dir);
void cleanup_all(struct conf *conf);
void wipe_all(struct conf *conf);
-/* ------------------------------------------------------------------------- */
-/* execute.c */
+// ----------------------------------------------------------------------------
+// execute.c
int execute(char **argv, int fd_out, int fd_err, pid_t *pid);
char *find_executable(const char *name, const char *exclude_name);
void print_command(FILE *fp, char **argv);
-/* ------------------------------------------------------------------------- */
-/* lockfile.c */
+// ----------------------------------------------------------------------------
+// lockfile.c
bool lockfile_acquire(const char *path, unsigned staleness_limit);
void lockfile_release(const char *path);
-/* ------------------------------------------------------------------------- */
-/* ccache.c */
+// ----------------------------------------------------------------------------
+// ccache.c
extern time_t time_of_compilation;
void block_signals(void);
void cc_reset(void);
bool is_precompiled_header(const char *path);
-/* ------------------------------------------------------------------------- */
+// ----------------------------------------------------------------------------
#if HAVE_COMPAR_FN_T
#define COMPAR_FN_T __compar_fn_t
typedef int (*COMPAR_FN_T)(const void *, const void *);
#endif
-/* work with silly DOS binary open */
+// Work with silly DOS binary open.
#ifndef O_BINARY
#define O_BINARY 0
#endif
-/* mkstemp() on some versions of cygwin don't handle binary files, so
- override */
+// mkstemp() on some versions of cygwin don't handle binary files, so override.
#ifdef __CYGWIN__
#undef HAVE_MKSTEMP
#endif
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
-#endif /* ifndef CCACHE_H */
+#endif // ifndef CCACHE_H
-/*
- * Copyright (C) 2002-2006 Andrew Tridgell
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2002-2006 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
-/*
- * When "max files" or "max cache size" is reached, one of the 16 cache
- * subdirectories is cleaned up. When doing so, files are deleted (in LRU
- * order) until the levels are below LIMIT_MULTIPLE.
- */
+// When "max files" or "max cache size" is reached, one of the 16 cache
+// subdirectories is cleaned up. When doing so, files are deleted (in LRU
+// order) until the levels are below LIMIT_MULTIPLE.
#define LIMIT_MULTIPLE 0.8
static struct files {
time_t mtime;
uint64_t size;
} **files;
-static unsigned allocated; /* Size of the files array. */
-static unsigned num_files; /* Number of used entries in the files array. */
+static unsigned allocated; // Size of the files array.
+static unsigned num_files; // Number of used entries in the files array.
static uint64_t cache_size;
static size_t files_in_cache;
static uint64_t cache_size_threshold;
static size_t files_in_cache_threshold;
-/* File comparison function that orders files in mtime order, oldest first. */
+// File comparison function that orders files in mtime order, oldest first.
static int
files_compare(struct files **f1, struct files **f2)
{
return 1;
}
-/* this builds the list of files in the cache */
+// This builds the list of files in the cache.
static void
traverse_fn(const char *fname, struct stat *st)
{
}
if (str_startswith(p, ".nfs")) {
- /* Ignore temporary NFS files that may be left for open but deleted
- * files. */
+ // Ignore temporary NFS files that may be left for open but deleted files.
goto out;
}
if (strstr(p, ".tmp.")) {
- /* delete any tmp files older than 1 hour */
+ // Delete any tmp files older than 1 hour.
if (st->st_mtime + 3600 < time(NULL)) {
x_unlink(fname);
goto out;
free(path);
}
-/* sort the files we've found and delete the oldest ones until we are
- below the thresholds */
+// Sort the files we've found and delete the oldest ones until we are below the
+// thresholds.
static bool
sort_and_clean(void)
{
bool cleaned = false;
if (num_files > 1) {
- /* Sort in ascending mtime order. */
+ // Sort in ascending mtime order.
qsort(files, num_files, sizeof(struct files *), (COMPAR_FN_T)files_compare);
}
- /* delete enough files to bring us below the threshold */
+ // Delete enough files to bring us below the threshold.
for (i = 0; i < num_files; i++) {
const char *ext;
|| str_eq(ext, ".stderr")
|| str_eq(ext, "")) {
char *base = remove_extension(files[i]->fname);
- if (!str_eq(base, last_base)) { /* Avoid redundant unlinks. */
- /*
- * Make sure that all sibling files are deleted so that a cached result
- * is removed completely. Note the order of deletions -- the stderr
- * file must be deleted last because if the ccache process gets killed
- * after deleting the .stderr but before deleting the .o, the cached
- * result would be inconsistent.
- */
+ if (!str_eq(base, last_base)) { // Avoid redundant unlinks.
+ // Make sure that all sibling files are deleted so that a cached result
+ // is removed completely. Note the order of deletions -- the stderr
+ // file must be deleted last because if the ccache process gets killed
+ // after deleting the .stderr but before deleting the .o, the cached
+ // result would be inconsistent.
delete_sibling_file(base, ".o");
delete_sibling_file(base, ".d");
delete_sibling_file(base, ".gcno");
delete_sibling_file(base, ".dia");
delete_sibling_file(base, ".stderr");
- delete_sibling_file(base, ""); /* Object file from ccache 2.4. */
+ delete_sibling_file(base, ""); // Object file from ccache 2.4.
}
free(last_base);
last_base = base;
} else {
- /* .manifest or unknown file. */
+ // .manifest or unknown file.
delete_file(files[i]->fname, files[i]->size);
}
cleaned = true;
return cleaned;
}
-/* cleanup in one cache subdir */
+// Clean up one cache subdirectory.
void
cleanup_dir(struct conf *conf, const char *dir)
{
cache_size = 0;
files_in_cache = 0;
- /* build a list of files */
+ // Build a list of files.
traverse(dir, traverse_fn);
- /* cleaned the cache */
+ // Clean the cache.
cleaned = sort_and_clean();
if (cleaned) {
stats_set_sizes(dir, files_in_cache, cache_size);
- /* free it up */
+ // Free it up.
for (i = 0; i < num_files; i++) {
free(files[i]->fname);
free(files[i]);
files_in_cache = 0;
}
-/* cleanup in all cache subdirs */
+// Clean up all cache subdirectories.
void cleanup_all(struct conf *conf)
{
int i;
}
}
-/* traverse function for wiping files */
+// Traverse function for wiping files.
static void wipe_fn(const char *fname, struct stat *st)
{
char *p;
x_unlink(fname);
}
-/* wipe in one cache subdir */
+// Wipe one cache subdirectory.
void
wipe_dir(struct conf *conf, const char *dir)
{
files_in_cache = 0;
}
-/* wipe all cached files in all subdirs */
+// Wipe all cached files in all subdirectories.
void wipe_all(struct conf *conf)
{
int i;
free(dname);
}
- /* and fix the counters */
+ // Fix the counters.
cleanup_all(conf);
}
-/*
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
#include "compopt.h"
{"-b", TAKES_ARG},
{"-fmodules", TOO_HARD},
{"-fno-working-directory", AFFECTS_CPP},
- {"-fplugin=libcc1plugin", TOO_HARD}, /* interaction with GDB */
+ {"-fplugin=libcc1plugin", TOO_HARD}, // interaction with GDB
{"-frepo", TOO_HARD},
{"-fstack-usage", TOO_HARD},
{"-fworking-directory", AFFECTS_CPP},
{"-imultilib", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
{"-include", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
{"-include-pch", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
- {"-install_name", TAKES_ARG}, /* Darwin linker option */
+ {"-install_name", TAKES_ARG}, // Darwin linker option
{"-iprefix", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
{"-iquote", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
{"-isysroot", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
sizeof(compopts[0]), compare_prefix_compopts);
}
-/* Runs fn on the first two characters of option. */
+// Runs fn on the first two characters of option.
bool
compopt_short(bool (*fn)(const char *), const char *option)
{
return retval;
}
-/* For test purposes. */
+// For test purposes.
bool
compopt_verify_sortedness(void)
{
return co && (co->type & TAKES_CONCAT_ARG);
}
-/* Determines if the prefix of the option matches any option and affects the
- * preprocessor.
- */
+// Determines if the prefix of the option matches any option and affects the
+// preprocessor.
bool
compopt_prefix_affects_cpp(const char *option)
{
- /* prefix options have to take concatentated args */
+ // Prefix options have to take concatentated args.
const struct compopt *co = find_prefix(option);
return co && (co->type & TAKES_CONCAT_ARG) && (co->type & AFFECTS_CPP);
}
bool compopt_takes_concat_arg(const char *option);
bool compopt_prefix_affects_cpp(const char *option);
-#endif /* CCACHE_COMPOPT_H */
+#endif // CCACHE_COMPOPT_H
-/*
- * Copyright (C) 2011-2015 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2011-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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "conf.h"
#include "ccache.h"
char **path = (char **)value;
assert(*path);
if (str_eq(*path, "")) {
- /* The empty string means "disable" in this case. */
+ // The empty string means "disable" in this case.
return true;
} else if (is_absolute_path(*path)) {
return true;
}
if (from_env_variable && item->parser == parse_bool) {
- /*
- * Special rule for boolean settings from the environment: any value means
- * true.
- */
+ // Special rule for boolean settings from the environment: any value means
+ // true.
bool *value = (bool *)((char *)conf + item->offset);
*value = !negate_boolean;
goto out;
}
++p;
- /* Skip leading whitespace. */
+ // Skip leading whitespace.
SKIP_WS(p);
q = p;
while (*q) {
++q;
}
- /* Skip trailing whitespace. */
+ // Skip trailing whitespace.
while (isspace(q[-1])) {
--q;
}
#undef SKIP_WS
}
-/* Create a conf struct with default values. */
+// Create a conf struct with default values.
struct conf *
conf_create(void)
{
conf->sloppiness = 0;
conf->stats = true;
conf->temporary_dir = x_strdup("");
- conf->umask = UINT_MAX; /* default: don't set umask */
+ conf->umask = UINT_MAX; // Default: don't set umask.
conf->unify = false;
conf->item_origins = x_malloc(CONFITEMS_TOTAL_KEYWORDS * sizeof(char *));
for (i = 0; i < CONFITEMS_TOTAL_KEYWORDS; ++i) {
free(conf);
}
-/* Note: The path pointer is stored in conf, so path must outlive conf. */
+// Note: The path pointer is stored in conf, so path must outlive conf.
bool
conf_read(struct conf *conf, const char *path, char **errmsg)
{
bool ok;
++line_number;
ok = parse_line(buf, &key, &value, &errmsg2);
- if (ok && key) { /* key == NULL if comment or blank line */
+ if (ok && key) { // key == NULL if comment or blank line.
ok = handle_conf_setting(conf, key, value, &errmsg2, false, false, path);
}
free(key);
}
key = x_strndup(*p + key_start, q - *p - key_start);
- ++q; /* Now points to the value. */
+ ++q; // Now points to the value.
env_to_conf_item = find_env_to_conf(key);
if (!env_to_conf_item) {
reformat(&s, "%sno_system_headers, ", s);
}
if (conf->sloppiness) {
- /* Strip last ", ". */
+ // Strip last ", ".
s[strlen(s) - 2] = '\0';
}
printer(s, conf->item_origins[find_conf("sloppiness")->number], context);
-/*
- * Copyright (C) 2010 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-/* A simple array of unsigned integers used for the statistics counters. */
+// A simple array of unsigned integers used for the statistics counters.
#include "ccache.h"
-/*
- * Allocate and initialize a struct counters. Data entries up to the size are
- * set to 0.
- */
+// Allocate and initialize a struct counters. Data entries up to the size are
+// set to 0.
struct counters *
counters_init(size_t initial_size)
{
return c;
}
-/*
- * Free a struct counters.
- */
+// Free a counters struct.
void
counters_free(struct counters *c)
{
free(c);
}
-/*
- * Set a new size. New data entries are set to 0.
- */
+// Set a new size. New data entries are set to 0.
void
counters_resize(struct counters *c, size_t new_size)
{
-/*
- * Copyright (C) 2010 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef COUNTERS_H
#define COUNTERS_H
#include <stddef.h>
struct counters {
- unsigned *data; /* counter value */
- size_t size; /* logical array size */
- size_t allocated; /* allocated size */
+ unsigned *data; // counter value
+ size_t size; // logical array size
+ size_t allocated; // allocated size
};
struct counters *counters_init(size_t initial_size);
-/*
- * Copyright (C) Andrew Tridgell 2002
- * Copyright (C) Joel Rosdahl 2011
- *
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2002 Andrew Tridgell
+// Copyright (C) 2011-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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
find_executable_in_path(const char *name, const char *exclude_name, char *path);
#ifdef _WIN32
-/*
- * Re-create a win32 command line string based on **argv.
- * http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
- */
+// Re-create a win32 command line string based on **argv.
+// http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
char *
win32argvtos(char *prefix, char **argv)
{
}
*ptr++ = '"';
*ptr++ = ' ';
- /* cppcheck-suppress unreadVariable */
+ // cppcheck-suppress unreadVariable
} while ((arg = argv[i++]));
ptr[-1] = '\0';
sh = find_executable_in_path("sh.exe", NULL, path_env);
}
if (!sh && getenv("CCACHE_DETECT_SHEBANG")) {
- /* Detect shebang. */
+ // Detect shebang.
FILE *fp;
fp = fopen(path, "r");
if (fp) {
return -1;
}
} else {
- /* redirect subprocess stdout, stderr into current process */
+ // Redirect subprocess stdout, stderr into current process.
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
#else
-/* Execute a compiler backend, capturing all output to the given paths the full
- * path to the compiler to run is in argv[0]. */
+// Execute a compiler backend, capturing all output to the given paths the full
+// path to the compiler to run is in argv[0].
int
execute(char **argv, int fd_out, int fd_err, pid_t *pid)
{
}
if (*pid == 0) {
- /* Child. */
+ // Child.
dup2(fd_out, 1);
close(fd_out);
dup2(fd_err, 2);
}
#endif
-
-/*
- * Find an executable by name in $PATH. Exclude any that are links to
- * exclude_name.
- */
+// Find an executable by name in $PATH. Exclude any that are links to
+// exclude_name.
char *
find_executable(const char *name, const char *exclude_name)
{
path = x_strdup(path);
- /* search the path looking for the first compiler of the right name
- that isn't us */
+ // Search the path looking for the first compiler of the right name that
+ // isn't us.
for (tok = strtok_r(path, PATH_DELIM, &saveptr);
tok;
tok = strtok_r(NULL, PATH_DELIM, &saveptr)) {
#else
struct stat st1, st2;
char *fname = format("%s/%s", tok, name);
- /* look for a normal executable file */
+ // Look for a normal executable file.
if (access(fname, X_OK) == 0 &&
lstat(fname, &st1) == 0 &&
stat(fname, &st2) == 0 &&
if (buf) {
char *p = basename(buf);
if (str_eq(p, exclude_name)) {
- /* It's a link to "ccache"! */
+ // It's a link to "ccache"!
free(p);
free(buf);
continue;
}
}
- /* Found it! */
+ // Found it!
free(path);
return fname;
}
-/*
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
free(p);
}
-/*
- * Initialize exit functions. Must be called once before exitfn_add* are used.
- */
+// Initialize exit functions. Must be called once before exitfn_add* are used.
void
exitfn_init(void)
{
}
}
-/*
- * Add a nullary function to be called when ccache exits. Functions are called
- * in reverse order.
- */
+// Add a nullary function to be called when ccache exits. Functions are called
+// in reverse order.
void
exitfn_add_nullary(void (*function)(void))
{
exitfn_add(call_nullary_exit_function, p);
}
-/*
- * Add a function to be called with a context parameter when ccache exits.
- * Functions are called in reverse order.
- */
+// Add a function to be called with a context parameter when ccache exits.
+// Functions are called in reverse order.
void
exitfn_add(void (*function)(void *), void *context)
{
exit_functions = p;
}
-/*
- * Call added functions.
- */
+// Call added functions.
void
exitfn_call(void)
{
-/*
- * Copyright (C) 2002 Andrew Tridgell
- * Copyright (C) 2010 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2002 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
mdfour_update(md, (unsigned char *)s, len);
}
-/* Return the hash result as a hex string. Caller frees. */
+// Return the hash result as a hex string. Caller frees.
char *
hash_result(struct mdfour *md)
{
return format_hash_as_string(sum, (unsigned) md->totalN);
}
-/* return the hash result as 16 binary bytes */
+// Return the hash result as 16 binary bytes.
void
hash_result_as_bytes(struct mdfour *md, unsigned char *out)
{
return memcmp(sum1, sum2, sizeof(sum1)) == 0;
}
-/*
- * Hash some data that is unlikely to occur in the input. The idea is twofold:
- *
- * - Delimit things like arguments from each other (e.g., so that -I -O2 and
- * -I-O2 hash differently).
- * - Tag different types of hashed information so that it's possible to do
- * conditional hashing of information in a safe way (e.g., if we want to hash
- * information X if CCACHE_A is set and information Y if CCACHE_B is set,
- * there should never be a hash collision risk).
- */
+// Hash some data that is unlikely to occur in the input. The idea is twofold:
+//
+// - Delimit things like arguments from each other (e.g., so that -I -O2 and
+// -I-O2 hash differently).
+// - Tag different types of hashed information so that it's possible to do
+// conditional hashing of information in a safe way (e.g., if we want to hash
+// information X if CCACHE_A is set and information Y if CCACHE_B is set,
+// there should never be a hash collision risk).
void
hash_delimiter(struct mdfour *md, const char *type)
{
hash_buffer(md, HASH_DELIMITER, sizeof(HASH_DELIMITER));
- hash_buffer(md, type, strlen(type) + 1); /* Include NUL. */
+ hash_buffer(md, type, strlen(type) + 1); // Include NUL.
}
void
hash_buffer(md, (char *)&x, sizeof(x));
}
-/*
- * Add contents of an open file to the hash. Returns true on success, otherwise
- * false.
- */
+// Add contents of an open file to the hash. Returns true on success, otherwise
+// false.
bool
hash_fd(struct mdfour *md, int fd)
{
return n == 0;
}
-/*
- * Add contents of a file to the hash. Returns true on success, otherwise
- * false.
- */
+// Add contents of a file to the hash. Returns true on success, otherwise
+// false.
bool
hash_file(struct mdfour *md, const char *fname)
{
-/*
- * Copyright (C) 2009-2015 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
#include "hashutil.h"
&& fh1->size == fh2->size;
}
-/*
- * Search for the strings "__DATE__" and "__TIME__" in str.
- *
- * Returns a bitmask with HASH_SOURCE_CODE_FOUND_DATE and
- * HASH_SOURCE_CODE_FOUND_TIME set appropriately.
- */
+// Search for the strings "__DATE__" and "__TIME__" in str.
+//
+// Returns a bitmask with HASH_SOURCE_CODE_FOUND_DATE and
+// HASH_SOURCE_CODE_FOUND_TIME set appropriately.
int
check_for_temporal_macros(const char *str, size_t len)
{
int result = 0;
- /*
- * We're using the Boyer-Moore-Horspool algorithm, which searches starting
- * from the *end* of the needle. Our needles are 8 characters long, so i
- * starts at 7.
- */
+ // We're using the Boyer-Moore-Horspool algorithm, which searches starting
+ // from the *end* of the needle. Our needles are 8 characters long, so i
+ // starts at 7.
size_t i = 7;
while (i < len) {
- /*
- * Check whether the substring ending at str[i] has the form "__...E__". On
- * the assumption that 'E' is less common in source than '_', we check
- * str[i-2] first.
- */
+ // Check whether the substring ending at str[i] has the form "__...E__". On
+ // the assumption that 'E' is less common in source than '_', we check
+ // str[i-2] first.
if (str[i - 2] == 'E' &&
str[i - 0] == '_' &&
str[i - 7] == '_' &&
str[i - 1] == '_' &&
str[i - 6] == '_') {
- /*
- * Check the remaining characters to see if the substring is "__DATE__"
- * or "__TIME__".
- */
+ // Check the remaining characters to see if the substring is "__DATE__"
+ // or "__TIME__".
if (str[i - 5] == 'D' && str[i - 4] == 'A' &&
str[i - 3] == 'T') {
result |= HASH_SOURCE_CODE_FOUND_DATE;
}
}
- /*
- * macro_skip tells us how far we can skip forward upon seeing str[i] at
- * the end of a substring.
- */
+ // macro_skip tells us how far we can skip forward upon seeing str[i] at
+ // the end of a substring.
i += macro_skip[(uint8_t)str[i]];
}
return result;
}
-/*
- * Hash a string. Returns a bitmask of HASH_SOURCE_CODE_* results.
- */
+// Hash a string. Returns a bitmask of HASH_SOURCE_CODE_* results.
int
hash_source_code_string(
struct conf *conf, struct mdfour *hash, const char *str, size_t len,
{
int result = HASH_SOURCE_CODE_OK;
- /*
- * Check for __DATE__ and __TIME__ if the sloppiness configuration tells us
- * we should.
- */
+ // Check for __DATE__ and __TIME__ if the sloppiness configuration tells us
+ // we should.
if (!(conf->sloppiness & SLOPPY_TIME_MACROS)) {
result |= check_for_temporal_macros(str, len);
}
- /*
- * Hash the source string.
- */
+ // Hash the source string.
hash_buffer(hash, str, len);
if (result & HASH_SOURCE_CODE_FOUND_DATE) {
- /*
- * Make sure that the hash sum changes if the (potential) expansion of
- * __DATE__ changes.
- */
+ // Make sure that the hash sum changes if the (potential) expansion of
+ // __DATE__ changes.
time_t t = time(NULL);
struct tm *now = localtime(&t);
cc_log("Found __DATE__ in %s", path);
hash_buffer(hash, &now->tm_mday, sizeof(now->tm_mday));
}
if (result & HASH_SOURCE_CODE_FOUND_TIME) {
- /*
- * We don't know for sure that the program actually uses the __TIME__
- * macro, but we have to assume it anyway and hash the time stamp. However,
- * that's not very useful since the chance that we get a cache hit later
- * the same second should be quite slim... So, just signal back to the
- * caller that __TIME__ has been found so that the direct mode can be
- * disabled.
- */
+ // We don't know for sure that the program actually uses the __TIME__
+ // macro, but we have to assume it anyway and hash the time stamp. However,
+ // that's not very useful since the chance that we get a cache hit later
+ // the same second should be quite slim... So, just signal back to the
+ // caller that __TIME__ has been found so that the direct mode can be
+ // disabled.
cc_log("Found __TIME__ in %s", path);
}
return result;
}
-/*
- * Hash a file ignoring comments. Returns a bitmask of HASH_SOURCE_CODE_*
- * results.
- */
+// Hash a file ignoring comments. Returns a bitmask of HASH_SOURCE_CODE_*
+// results.
int
hash_source_code_file(struct conf *conf, struct mdfour *hash, const char *path)
{
#endif
#ifdef _WIN32
- /* trim leading space */
+ // Trim leading space.
while (isspace(*command)) {
command++;
}
- /* add "echo" command */
+ // Add "echo" command.
if (str_startswith(command, "echo")) {
command = format("cmd.exe /c \"%s\"", command);
cmd = true;
if (!cmd) {
win32args = win32argvtos(sh, args->argv);
} else {
- win32args = (char *) command; /* quoted */
+ win32args = (char *)command; // quoted
}
ret = CreateProcess(path, win32args, NULL, NULL, 1, 0, NULL, NULL, &si, &pi);
CloseHandle(pipe_out[1]);
args_free(args);
free(win32args);
if (cmd) {
- free((char *) command); /* original argument was replaced above */
+ free((char *)command); // Original argument was replaced above.
}
if (ret == 0) {
stats_update(STATS_COMPCHECK);
}
if (pid == 0) {
- /* Child. */
+ // Child.
close(pipefd[0]);
close(0);
dup2(pipefd[1], 1);
dup2(pipefd[1], 2);
_exit(execvp(args->argv[0], args->argv));
- return false; /* Never reached. */
+ return false; // Never reached.
} else {
- /* Parent. */
+ // Parent.
int status;
bool ok;
args_free(args);
-/*
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
-/*
- * Supported file extensions and corresponding languages (as in parameter to
- * the -x option).
- */
+// Supported file extensions and corresponding languages (as in parameter to
+// the -x option).
static const struct {
const char *extension;
const char *language;
{".mm", "objective-c++"},
{".sx", "assembler-with-cpp"},
{".S", "assembler-with-cpp"},
- /* Preprocessed: */
+ // Preprocessed:
{".i", "cpp-output"},
{".ii", "c++-cpp-output"},
{".mi", "objective-c-cpp-output"},
{".mii", "objective-c++-cpp-output"},
{".s", "assembler"},
- /* Header file (for precompilation): */
+ // Header file (for precompilation):
{".h", "c-header"},
{".H", "c++-header"},
{".h++", "c++-header"},
{".TCC", "c++-header"},
{".cu", "cuda"},
{".ic", "cuda-output"},
- /* Fixed form Fortran without preprocessing: */
+ // Fixed form Fortran without preprocessing:
{".f", "f77"},
{".for", "f77"},
{".ftn", "f77"},
- /* Fixed form Fortran with traditional preprocessing: */
+ // Fixed form Fortran with traditional preprocessing:
{".F", "f77-cpp-input"},
{".FOR", "f77-cpp-input"},
{".fpp", "f77-cpp-input"},
{".FPP", "f77-cpp-input"},
{".FTN", "f77-cpp-input"},
- /* Free form Fortran without preprocessing: */
-#if 0 /* Could generate modules, ignore for now! */
+ // Free form Fortran without preprocessing:
+#if 0 // Could generate modules, ignore for now!
{".f90", "f95"},
{".f95", "f95"},
{".f03", "f95"},
{".f08", "f95"},
#endif
- /* Free form Fortran with traditional preprocessing: */
-#if 0 /* Could generate modules, ignore for now! */
+ // Free form Fortran with traditional preprocessing:
+#if 0 // Could generate modules, ignore for now!
{".F90", "f95-cpp-input"},
{".F95", "f95-cpp-input"},
{".F03", "f95-cpp-input"},
{NULL, NULL}
};
-/*
- * Supported languages and corresponding preprocessed languages.
- */
+// Supported languages and corresponding preprocessed languages.
static const struct {
const char *language;
const char *p_language;
{"assembler", "assembler"},
{"f77-cpp-input", "f77"},
{"f77", "f77"},
-#if 0 /* Could generate module files, ignore for now! */
+#if 0 // Could generate module files, ignore for now!
{"f95-cpp-input", "f95"},
{"f95", "f95"},
#endif
{NULL, NULL}
};
-/*
- * Guess the language of a file based on its extension. Returns NULL if the
- * extension is unknown.
- */
+// Guess the language of a file based on its extension. Returns NULL if the
+// extension is unknown.
const char *
language_for_file(const char *fname)
{
return NULL;
}
-/*
- * Return the preprocessed language for a given language, or NULL if unknown.
- */
+// Return the preprocessed language for a given language, or NULL if unknown.
const char *
p_language_for_language(const char *language)
{
return NULL;
}
-/*
- * Return the default file extension (including dot) for a language, or NULL if
- * unknown.
- */
+// Return the default file extension (including dot) for a language, or NULL if
+// unknown.
const char *
extension_for_language(const char *language)
{
bool language_is_supported(const char *language);
bool language_is_preprocessed(const char *language);
-#endif /* CCACHE_LANGUAGE_H */
+#endif // CCACHE_LANGUAGE_H
-/*
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
-/*
- * This function acquires a lockfile for the given path. Returns true if the
- * lock was acquired, otherwise false. If the lock has been considered stale
- * for the number of microseconds specified by staleness_limit, the function
- * will (if possible) break the lock and then try to acquire it again. The
- * staleness limit should be reasonably larger than the longest time the lock
- * can be expected to be held, and the updates of the locked path should
- * probably be made with an atomic rename(2) to avoid corruption in the rare
- * case that the lock is broken by another process.
- */
+// This function acquires a lockfile for the given path. Returns true if the
+// lock was acquired, otherwise false. If the lock has been considered stale
+// for the number of microseconds specified by staleness_limit, the function
+// will (if possible) break the lock and then try to acquire it again. The
+// staleness limit should be reasonably larger than the longest time the lock
+// can be expected to be held, and the updates of the locked path should
+// probably be made with an atomic rename(2) to avoid corruption in the rare
+// case that the lock is broken by another process.
bool
lockfile_acquire(const char *path, unsigned staleness_limit)
{
#else
int ret;
#endif
- unsigned to_sleep = 1000, slept = 0; /* Microseconds. */
+ unsigned to_sleep = 1000, slept = 0; // Microseconds.
while (true) {
free(my_content);
saved_errno = errno;
cc_log("lockfile_acquire: open WRONLY %s: %s", lockfile, strerror(errno));
if (saved_errno == ENOENT) {
- /* Directory doesn't exist? */
+ // Directory doesn't exist?
if (create_parent_dirs(lockfile) == 0) {
- /* OK. Retry. */
+ // OK. Retry.
continue;
}
}
if (saved_errno != EEXIST) {
- /* Directory doesn't exist or isn't writable? */
+ // Directory doesn't exist or isn't writable?
goto out;
}
- /* Someone else has the lock. */
+ // Someone else has the lock.
fd = open(lockfile, O_RDONLY|O_BINARY);
if (fd == -1) {
if (errno == ENOENT) {
- /*
- * The file was removed after the open() call above, so retry
- * acquiring it.
- */
+ // The file was removed after the open() call above, so retry
+ // acquiring it.
continue;
} else {
cc_log("lockfile_acquire: open RDONLY %s: %s",
close(fd);
content[len] = '\0';
} else {
- /* We got the lock. */
+ // We got the lock.
if (write(fd, my_content, strlen(my_content)) == -1) {
cc_log("lockfile_acquire: write %s: %s", lockfile, strerror(errno));
close(fd);
#else
ret = symlink(my_content, lockfile);
if (ret == 0) {
- /* We got the lock. */
+ // We got the lock.
acquired = true;
goto out;
}
saved_errno = errno;
cc_log("lockfile_acquire: symlink %s: %s", lockfile, strerror(saved_errno));
if (saved_errno == ENOENT) {
- /* Directory doesn't exist? */
+ // Directory doesn't exist?
if (create_parent_dirs(lockfile) == 0) {
- /* OK. Retry. */
+ // OK. Retry.
continue;
}
}
if (saved_errno == EPERM) {
- /*
- * The file system does not support symbolic links. We have no choice but
- * to grant the lock anyway.
- */
+ // The file system does not support symbolic links. We have no choice but
+ // to grant the lock anyway.
acquired = true;
goto out;
}
if (saved_errno != EEXIST) {
- /* Directory doesn't exist or isn't writable? */
+ // Directory doesn't exist or isn't writable?
goto out;
}
free(content);
content = x_readlink(lockfile);
- /* cppcheck-suppress nullPointer - false positive */
+ // cppcheck-suppress nullPointer - false positive
if (!content) {
if (errno == ENOENT) {
- /*
- * The symlink was removed after the symlink() call above, so retry
- * acquiring it.
- */
+ // The symlink was removed after the symlink() call above, so retry
+ // acquiring it.
continue;
} else {
cc_log("lockfile_acquire: readlink %s: %s", lockfile, strerror(errno));
#endif
if (str_eq(content, my_content)) {
- /* Lost NFS reply? */
+ // Lost NFS reply?
cc_log("lockfile_acquire: symlink %s failed but we got the lock anyway",
lockfile);
acquired = true;
goto out;
}
- /*
- * A possible improvement here would be to check if the process holding the
- * lock is still alive and break the lock early if it isn't.
- */
+ // A possible improvement here would be to check if the process holding the
+ // lock is still alive and break the lock early if it isn't.
cc_log("lockfile_acquire: lock info for %s: %s", lockfile, content);
if (!initial_content) {
initial_content = x_strdup(content);
}
if (slept > staleness_limit) {
if (str_eq(content, initial_content)) {
- /* The lock seems to be stale -- break it. */
+ // The lock seems to be stale -- break it.
cc_log("lockfile_acquire: breaking %s", lockfile);
if (lockfile_acquire(lockfile, staleness_limit)) {
lockfile_release(path);
return acquired;
}
-/*
- * Release the lockfile for the given path. Assumes that we are the legitimate
- * owner.
- */
+// Release the lockfile for the given path. Assumes that we are the legitimate
+// owner.
void
lockfile_release(const char *path)
{
#include <stdint.h>
-/*
- * A Boyer-Moore-Horspool skip table used for searching for the strings
- * "__TIME__" and "__DATE__".
- *
- * macro_skip[c] = 8 for all c not in "__TIME__" and "__DATE__".
- *
- * The other characters map as follows:
- *
- * _ -> 1
- * A -> 4
- * D -> 5
- * E -> 2
- * I -> 4
- * M -> 3
- * T -> 3
- *
- *
- * This was generated with the following Python script:
- *
- * m = {'_': 1,
- * 'A': 4,
- * 'D': 5,
- * 'E': 2,
- * 'I': 4,
- * 'M': 3,
- * 'T': 3}
- *
- * for i in range(0, 256):
- * if chr(i) in m:
- * num = m[chr(i)]
- * else:
- * num = 8
- * print ("%d, " % num),
- *
- * if i % 16 == 15:
- * print ""
- */
+// A Boyer-Moore-Horspool skip table used for searching for the strings
+// "__TIME__" and "__DATE__".
+//
+// macro_skip[c] = 8 for all c not in "__TIME__" and "__DATE__".
+//
+// The other characters map as follows:
+//
+// _ -> 1
+// A -> 4
+// D -> 5
+// E -> 2
+// I -> 4
+// M -> 3
+// T -> 3
+//
+//
+// This was generated with the following Python script:
+//
+// m = {'_': 1,
+// 'A': 4,
+// 'D': 5,
+// 'E': 2,
+// 'I': 4,
+// 'M': 3,
+// 'T': 3}
+//
+// for i in range(0, 256):
+// if chr(i) in m:
+// num = m[chr(i)]
+// else:
+// num = 8
+// print ("%d, " % num),
+//
+// if i % 16 == 15:
+// print ""
static const uint32_t macro_skip[] = {
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-/*
- * ccache -- a fast C/C++ compiler cache
- *
- * Copyright (C) 2010 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// ccache -- a fast C/C++ compiler cache
+//
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
int
ccache_main(int argc, char *argv[]);
-/*
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
#include "hashtable_itr.h"
#include <zlib.h>
-/*
- * Sketchy specification of the manifest disk format:
- *
- * <magic> magic number (4 bytes)
- * <version> file format version (1 byte unsigned int)
- * <hash_size> size of the hash fields (in bytes) (1 byte unsigned int)
- * <reserved> reserved for future use (2 bytes)
- * ----------------------------------------------------------------------------
- * <n> number of include file paths (4 bytes unsigned int)
- * <path_0> path to include file (NUL-terminated string,
- * ... at most 1024 bytes)
- * <path_n-1>
- * ----------------------------------------------------------------------------
- * <n> number of include file hash entries (4 bytes unsigned int)
- * <index[0]> index of include file path (4 bytes unsigned int)
- * <hash[0]> hash of include file (<hash_size> bytes)
- * <size[0]> size of include file (4 bytes unsigned int)
- * <mtime[0]> mtime of include file (8 bytes signed int)
- * <ctime[0]> ctime of include file (8 bytes signed int)
- * ...
- * <index[n-1]>
- * <hash[n-1]>
- * <size[n-1]>
- * <mtime[n-1]>
- * <ctime[n-1]>
- * ----------------------------------------------------------------------------
- * <n> number of object name entries (4 bytes unsigned int)
- * <m[0]> number of include file hash indexes (4 bytes unsigned int)
- * <index[0][0]> include file hash index (4 bytes unsigned int)
- * ...
- * <index[0][m[0]-1]>
- * <hash[0]> hash part of object name (<hash_size> bytes)
- * <size[0]> size part of object name (4 bytes unsigned int)
- * ...
- * <m[n-1]> number of include file hash indexes
- * <index[n-1][0]> include file hash index
- * ...
- * <index[n-1][m[n-1]]>
- * <hash[n-1]>
- * <size[n-1]>
- */
+// Sketchy specification of the manifest disk format:
+//
+// <magic> magic number (4 bytes)
+// <version> file format version (1 byte unsigned int)
+// <hash_size> size of the hash fields (in bytes) (1 byte unsigned int)
+// <reserved> reserved for future use (2 bytes)
+// ----------------------------------------------------------------------------
+// <n> number of include file paths (4 bytes unsigned int)
+// <path_0> path to include file (NUL-terminated string,
+// ... at most 1024 bytes)
+// <path_n-1>
+// ----------------------------------------------------------------------------
+// <n> number of include file hash entries (4 bytes unsigned int)
+// <index[0]> index of include file path (4 bytes unsigned int)
+// <hash[0]> hash of include file (<hash_size> bytes)
+// <size[0]> size of include file (4 bytes unsigned int)
+// <mtime[0]> mtime of include file (8 bytes signed int)
+// <ctime[0]> ctime of include file (8 bytes signed int)
+// ...
+// <index[n-1]>
+// <hash[n-1]>
+// <size[n-1]>
+// <mtime[n-1]>
+// <ctime[n-1]>
+// ----------------------------------------------------------------------------
+// <n> number of object name entries (4 bytes unsigned int)
+// <m[0]> number of include file hash indexes (4 bytes unsigned int)
+// <index[0][0]> include file hash index (4 bytes unsigned int)
+// ...
+// <index[0][m[0]-1]>
+// <hash[0]> hash part of object name (<hash_size> bytes)
+// <size[0]> size part of object name (4 bytes unsigned int)
+// ...
+// <m[n-1]> number of include file hash indexes
+// <index[n-1][0]> include file hash index
+// ...
+// <index[n-1][m[n-1]]>
+// <hash[n-1]>
+// <size[n-1]>
static const uint32_t MAGIC = 0x63436d46U;
static const uint32_t MAX_MANIFEST_ENTRIES = 100;
do { enum { ccache_static_assert__ = 1/(e) }; } while (false)
struct file_info {
- /* Index to n_files. */
+ // Index to n_files.
uint32_t index;
- /* Hash of referenced file. */
+ // Hash of referenced file.
uint8_t hash[16];
- /* Size of referenced file. */
+ // Size of referenced file.
uint32_t size;
- /* mtime of referenced file. */
+ // mtime of referenced file.
int64_t mtime;
- /* ctime of referenced file. */
+ // ctime of referenced file.
int64_t ctime;
};
struct object {
- /* Number of entries in file_info_indexes. */
+ // Number of entries in file_info_indexes.
uint32_t n_file_info_indexes;
- /* Indexes to file_infos. */
+ // Indexes to file_infos.
uint32_t *file_info_indexes;
- /* Hash of the object itself. */
+ // Hash of the object itself.
struct file_hash hash;
};
struct manifest {
- /* Version of decoded file. */
+ // Version of decoded file.
uint8_t version;
- /* Reserved for future use. */
+ // Reserved for future use.
uint16_t reserved;
- /* Size of hash fields (in bytes). */
+ // Size of hash fields (in bytes).
uint8_t hash_size;
- /* Referenced include files. */
+ // Referenced include files.
uint32_t n_files;
char **files;
- /* Information about referenced include files. */
+ // Information about referenced include files.
uint32_t n_file_infos;
struct file_info *file_infos;
- /* Object names plus references to include file hashes. */
+ // Object names plus references to include file hashes.
uint32_t n_objects;
struct object *objects;
};
static unsigned int
hash_from_file_info(void *key)
{
- ccache_static_assert(sizeof(struct file_info) == 40); /* No padding. */
+ ccache_static_assert(sizeof(struct file_info) == 40); // No padding.
return murmurhashneutral2(key, sizeof(struct file_info), 0);
}
READ_BYTE(mf->hash_size);
if (mf->hash_size != 16) {
- /* Temporary measure until we support different hash algorithms. */
+ // Temporary measure until we support different hash algorithms.
cc_log("Manifest file has unsupported hash size %u", mf->hash_size);
free_manifest(mf);
return NULL;
}
if (conf->sloppiness & SLOPPY_FILE_STAT_MATCHES) {
- /*
- * st->ctime is sometimes 0, so we can't check that both st->ctime and
- * st->mtime are greater than time_of_compilation. But it's sufficient to
- * check that either is.
- */
+ // st->ctime is sometimes 0, so we can't check that both st->ctime and
+ // st->mtime are greater than time_of_compilation. But it's sufficient to
+ // check that either is.
if (fi->size == st->size
&& fi->mtime == st->mtime
&& fi->ctime == st->ctime
memcpy(fi.hash, file_hash->hash, sizeof(fi.hash));
fi.size = file_hash->size;
- /*
- * file_stat.st_{m,c}time has a resolution of 1 second, so we can cache the
- * file's mtime and ctime only if they're at least one second older than
- * time_of_compilation.
- *
- * st->ctime may be 0, so we have to check time_of_compilation against
- * MAX(mtime, ctime).
- */
+ // file_stat.st_{m,c}time has a resolution of 1 second, so we can cache the
+ // file's mtime and ctime only if they're at least one second older than
+ // time_of_compilation.
+ //
+ // st->ctime may be 0, so we have to check time_of_compilation against
+ // MAX(mtime, ctime).
if (stat(path, &file_stat) != -1
&& time_of_compilation > MAX(file_stat.st_mtime, file_stat.st_ctime)) {
{
struct hashtable_itr *iter;
uint32_t i;
- struct hashtable *mf_files; /* path --> index */
- struct hashtable *mf_file_infos; /* struct file_info --> index */
+ struct hashtable *mf_files; // path --> index
+ struct hashtable *mf_file_infos; // struct file_info --> index
if (size == 0) {
return;
obj->hash.size = object_hash->size;
}
-/*
- * Try to get the object hash from a manifest file. Caller frees. Returns NULL
- * on failure.
- */
+// Try to get the object hash from a manifest file. Caller frees. Returns NULL
+// on failure.
struct file_hash *
manifest_get(struct conf *conf, const char *manifest_path)
{
int fd;
gzFile f = NULL;
struct manifest *mf = NULL;
- struct hashtable *hashed_files = NULL; /* path --> struct file_hash */
- struct hashtable *stated_files = NULL; /* path --> struct file_stats */
+ struct hashtable *hashed_files = NULL; // path --> struct file_hash
+ struct hashtable *stated_files = NULL; // path --> struct file_stats
uint32_t i;
struct file_hash *fh = NULL;
fd = open(manifest_path, O_RDONLY | O_BINARY);
if (fd == -1) {
- /* Cache miss. */
+ // Cache miss.
cc_log("No such manifest file");
goto out;
}
hashed_files = create_hashtable(1000, hash_from_string, strings_equal);
stated_files = create_hashtable(1000, hash_from_string, strings_equal);
- /* Check newest object first since it's a bit more likely to match. */
+ // Check newest object first since it's a bit more likely to match.
for (i = mf->n_objects; i > 0; i--) {
if (verify_object(conf, mf, &mf->objects[i - 1],
stated_files, hashed_files)) {
return fh;
}
-/*
- * Put the object name into a manifest file given a set of included files.
- * Returns true on success, otherwise false.
- */
+// Put the object name into a manifest file given a set of included files.
+// Returns true on success, otherwise false.
bool
manifest_put(const char *manifest_path, struct file_hash *object_hash,
struct hashtable *included_files)
struct manifest *mf = NULL;
char *tmp_file = NULL;
- /*
- * We don't bother to acquire a lock when writing the manifest to disk. A
- * race between two processes will only result in one lost entry, which is
- * not a big deal, and it's also very unlikely.
- */
+ // We don't bother to acquire a lock when writing the manifest to disk. A
+ // race between two processes will only result in one lost entry, which is
+ // not a big deal, and it's also very unlikely.
fd1 = open(manifest_path, O_RDONLY | O_BINARY);
if (fd1 == -1) {
- /* New file. */
+ // New file.
mf = create_empty_manifest();
} else {
gzFile f1 = gzdopen(fd1, "rb");
}
if (mf->n_objects > MAX_MANIFEST_ENTRIES) {
- /*
- * Normally, there shouldn't be many object entries in the manifest since
- * new entries are added only if an include file has changed but not the
- * source file, and you typically change source files more often than
- * header files. However, it's certainly possible to imagine cases where
- * the manifest will grow large (for instance, a generated header file that
- * changes for every build), and this must be taken care of since
- * processing an ever growing manifest eventually will take too much time.
- * A good way of solving this would be to maintain the object entries in
- * LRU order and discarding the old ones. An easy way is to throw away all
- * entries when there are too many. Let's do that for now.
- */
+ // Normally, there shouldn't be many object entries in the manifest since
+ // new entries are added only if an include file has changed but not the
+ // source file, and you typically change source files more often than
+ // header files. However, it's certainly possible to imagine cases where
+ // the manifest will grow large (for instance, a generated header file that
+ // changes for every build), and this must be taken care of since
+ // processing an ever growing manifest eventually will take too much time.
+ // A good way of solving this would be to maintain the object entries in
+ // LRU order and discarding the old ones. An easy way is to throw away all
+ // entries when there are too many. Let's do that for now.
cc_log("More than %u entries in manifest file; discarding",
MAX_MANIFEST_ENTRIES);
free_manifest(mf);
mf = create_empty_manifest();
} else if (mf->n_file_infos > MAX_MANIFEST_FILE_INFO_ENTRIES) {
- /* Rarely, file_info entries can grow large in pathological cases where
- * many included files change, but the main file does not. This also puts
- * an upper bound on the number of file_info entries.
- */
+ // Rarely, file_info entries can grow large in pathological cases where
+ // many included files change, but the main file does not. This also puts
+ // an upper bound on the number of file_info entries.
cc_log("More than %u file_info entries in manifest file; discarding",
MAX_MANIFEST_FILE_INFO_ENTRIES);
free_manifest(mf);
-/*
- * Copyright (C) 1997-1998 Andrew Tridgell
- *
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 1997-1998 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
-/* NOTE: This code makes no attempt to be fast! */
+// NOTE: This code makes no attempt to be fast!
static struct mdfour *m;
#define ROUND3(a, b, c, d, k, s) \
a = lshift((a + H(b, c, d) + M[k] + 0x6ED9EBA1)&MASK32, s)
-/* this applies md4 to 64 byte chunks */
+// This applies md4 to 64 byte chunks.
static void
mdfour64(uint32_t *M)
{
-/*
- * MurmurHashNeutral2, by Austin Appleby. Released to the public domain. See
- * <http://murmurhash.googlepages.com>.
- */
+// MurmurHashNeutral2, by Austin Appleby. Released to the public domain. See
+// <http://murmurhash.googlepages.com>.
#include "murmurhashneutral2.h"
-/*
- * Copyright (C) 2002-2004 Andrew Tridgell
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Routines to handle the stats files. The stats file is stored one per cache
- * subdirectory to make this more scalable.
- */
+// Copyright (C) 2002-2004 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// Routines to handle the stats files. The stats file is stored one per cache
+// subdirectory to make this more scalable.
#include "ccache.h"
#include "hashutil.h"
static struct counters *counter_updates;
-#define FLAG_NOZERO 1 /* don't zero with the -z option */
-#define FLAG_ALWAYS 2 /* always show, even if zero */
-#define FLAG_NEVER 4 /* never show */
+#define FLAG_NOZERO 1 // don't zero with the -z option
+#define FLAG_ALWAYS 2 // always show, even if zero
+#define FLAG_NEVER 4 // never show
static void display_size_times_1024(uint64_t size);
-/* statistics fields in display order */
+// Statistics fields in display order.
static struct {
enum stats stat;
char *message;
display_size(size * 1024);
}
-/* parse a stats file from a buffer - adding to the counters */
+// Parse a stats file from a buffer, adding to the counters.
static void
parse_stats(struct counters *counters, const char *buf)
{
}
}
-/* write out a stats file */
+// Write out a stats file.
void
stats_write(const char *path, struct counters *counters)
{
}
}
-/*
- * Record that a number of bytes and files have been added to the cache. Size
- * is in bytes.
- */
+// Record that a number of bytes and files have been added to the cache. Size
+// is in bytes.
void
stats_update_size(uint64_t size, unsigned files)
{
counter_updates->data[STATS_TOTALSIZE] += size / 1024;
}
-/* Read in the stats from one directory and add to the counters. */
+// Read in the stats from one directory and add to the counters.
void
stats_read(const char *sfile, struct counters *counters)
{
free(data);
}
-/*
- * Write counter updates in counter_updates to disk.
- */
+// Write counter updates in counter_updates to disk.
void
stats_flush(void)
{
if (!stats_file) {
char *stats_dir;
- /*
- * A NULL stats_file means that we didn't get past calculate_object_hash(),
- * so we just choose one of stats files in the 16 subdirectories.
- */
+ // A NULL stats_file means that we didn't get past calculate_object_hash(),
+ // so we just choose one of stats files in the 16 subdirectories.
stats_dir = format("%s/%x", conf->cache_dir, hash_from_int(getpid()) % 16);
stats_file = format("%s/stats", stats_dir);
free(stats_dir);
counters_free(counters);
}
-/* update a normal stat */
+// Update a normal stat.
void
stats_update(enum stats stat)
{
counter_updates->data[stat]++;
}
-/* Get the pending update of a counter value. */
+// Get the pending update of a counter value.
unsigned
stats_get_pending(enum stats stat)
{
return counter_updates->data[stat];
}
-/* sum and display the total stats for all cache dirs */
+// Sum and display the total stats for all cache dirs.
void
stats_summary(struct conf *conf)
{
assert(conf);
- /* add up the stats in each directory */
+ // Add up the stats in each directory.
for (dir = -1; dir <= 0xF; dir++) {
char *fname;
printf("secondary config (readonly) %s\n",
secondary_config_path ? secondary_config_path : "");
- /* and display them */
+ // ...and display them.
for (i = 0; stats_info[i].message; i++) {
enum stats stat = stats_info[i].stat;
counters_free(counters);
}
-/* zero all the stats structures */
+// Zero all the stats structures.
void
stats_zero(void)
{
struct stat st;
fname = format("%s/%1x/stats", conf->cache_dir, dir);
if (stat(fname, &st) != 0) {
- /* No point in trying to reset the stats file if it doesn't exist. */
+ // No point in trying to reset the stats file if it doesn't exist.
free(fname);
continue;
}
}
}
-/* Get the per directory limits */
+// Get the per-directory limits.
void
stats_get_obsolete_limits(const char *dir, unsigned *maxfiles,
uint64_t *maxsize)
counters_free(counters);
}
-/* set the per directory sizes */
+// Set the per-directory sizes.
void
stats_set_sizes(const char *dir, unsigned num_files, uint64_t total_size)
{
counters_free(counters);
}
-/* count directory cleanup run */
+// Count directory cleanup run.
void
stats_add_cleanup(const char *dir, unsigned count)
{
-/*
- * Copyright (C) 2010-2015 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef CCACHE_SYSTEM_H
#define CCACHE_SYSTEM_H
#define asprintf rpl_asprintf
#endif
-#endif /* CCACHE_SYSTEM_H */
+#endif // CCACHE_SYSTEM_H
testname="CCACHE_COMMENTS"
mv test1.c test1-saved.c
- echo '/* initial comment */' > test1.c
+ echo '// initial comment' > test1.c
cat test1-saved.c >> test1.c
CCACHE_COMMENTS=1 $CCACHE_COMPILE -c test1.c
checkstat 'cache hit (preprocessed)' 4
checkstat 'cache miss' 3
- echo '/* different comment */' > test1.c
+ echo '// different comment' > test1.c
cat test1-saved.c >> test1.c
CCACHE_COMMENTS=1 $CCACHE_COMPILE -c test1.c
mv test1-saved.c test1.c
checkstat 'files in cache' 7
testname="comments"
- echo '/* a silly comment */' > test1-comment.c
+ echo '// a silly comment' > test1-comment.c
cat test1.c >> test1-comment.c
$CCACHE_COMPILE -c test1-comment.c
rm -f test1-comment*
checkstat 'cache hit (preprocessed)' 6
checkstat 'cache miss' 9
mv test1.c test1-saved.c
- echo '/* another comment */' > test1.c
+ echo '// another comment' > test1.c
cat test1-saved.c >> test1.c
CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
mv test1-saved.c test1.c
cat <<EOF >stderr.c
int stderr(void)
{
- /* Trigger warning by having no return statement. */
+ // Trigger warning by having no return statement.
}
EOF
checkstat 'files in cache' 0
##################################################################
# Create some code to compile.
cat <<EOF >test.c
-/* test.c */
+// test.c
#include "test1.h"
#include "test2.h"
EOF
int test3;
EOF
cat <<EOF >code.c
-/* code.c */
+// code.c
int test() { return 0; }
EOF
backdate test1.h test2.h test3.h
mv test1.h test1.h.saved
mv test3.h test3.h.saved
cat <<EOF >test1.h
-/* No more include of test3.h */
+// No more include of test3.h
int test1;
EOF
backdate test1.h
$CCACHE -C >/dev/null
cat <<EOF >cpp-warning.c
#if FOO
-/* Trigger preprocessor warning about extra token after #endif. */
+// Trigger preprocessor warning about extra token after #endif.
#endif FOO
int stderr(void)
{
- /* Trigger compiler warning by having no return statement. */
+ // Trigger compiler warning by having no return statement.
}
EOF
$CCACHE $COMPILER -Wall -W -c cpp-warning.c 2>stderr-orig.txt
cat <<EOF >stderr.h
int stderr(void)
{
- /* Trigger warning by having no return statement. */
+ // Trigger warning by having no return statement.
}
EOF
cat <<EOF >stderr.c
testname="ignore headers in manifest"
$CCACHE -Cz >/dev/null
cat <<EOF >ignore.h
-/* We don't want this header in the manifest */
+// We don't want this header in the manifest.
EOF
backdate ignore.h
cat <<EOF >ignore.c
-/*
- * Copyright (C) 2010-2014 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "../ccache.h"
#include "framework.h"
suite_fn *suite;
int tty = is_tty(1);
- x_unsetenv("GCC_COLORS"); /* Avoid confusing argument processing tests. */
+ x_unsetenv("GCC_COLORS"); // Avoid confusing argument processing tests.
verbose = verbose_output;
for (suite = suites; *suite; suite++) {
while (true) {
test_index = (*suite)(test_index + 1);
if (test_index == 0) {
- /* We have reached the end of the suite. */
+ // We have reached the end of the suite.
break;
}
}
void
cct_wipe(const char *path)
{
- /* TODO: rewrite using traverse(). */
+ // TODO: rewrite using traverse().
#ifndef __MINGW32__
char *command = format("rm -rf %s", path);
#else
-/*
- * Copyright (C) 2010-2012 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef TEST_FRAMEWORK_H
#define TEST_FRAMEWORK_H
#include "../ccache.h"
-/*****************************************************************************/
+// ============================================================================
#define TEST_SUITE(name) \
unsigned suite_##name(unsigned _start_point) \
unsigned _test_counter = 0; \
cct_suite_begin(#name); \
{ \
- /* Empty due to macro trickery. */
+ // Empty due to macro trickery.
#define TEST(name) \
cct_test_end(); \
return 0; /* We have reached the end. */ \
}
-/*****************************************************************************/
+// ============================================================================
#define CHECKM(assertion, message) \
do { \
} \
} while (false)
-/*****************************************************************************/
+// ============================================================================
#define CHECK_INT_EQ(expected, actual) \
do { \
} \
} while (false)
-/*****************************************************************************/
+// ============================================================================
#define CHECK_STR_EQ(expected, actual) \
CHECK_POINTER_EQ_BASE(str, expected, actual, false, false)
#define CHECK_STR_EQ_FREE12(expected, actual) \
CHECK_POINTER_EQ_BASE(str, expected, actual, true, true)
-/*****************************************************************************/
+// ============================================================================
#define CHECK_ARGS_EQ(expected, actual) \
CHECK_POINTER_EQ_BASE(args, expected, actual, false, false)
#define CHECK_ARGS_EQ_FREE12(expected, actual) \
CHECK_POINTER_EQ_BASE(args, expected, actual, true, true)
-/*****************************************************************************/
+// ============================================================================
typedef unsigned (*suite_fn)(unsigned);
int cct_run(suite_fn *suites, int verbose);
-/* Mode: -*-c-*- */
-/*
- * Copyright (C) 2010 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "framework.h"
#ifdef HAVE_GETOPT_LONG
#include "../getopt_long.h"
#endif
-/* *INDENT-OFF* disable uncrustify */
+// *INDENT-OFF* disable uncrustify
#define SUITE(name) unsigned suite_ ## name(unsigned);
-#include "test/suites.h"
+#include "suites.h"
#undef SUITE
-/* *INDENT-ON* enable uncrustify */
+// *INDENT-ON* enable uncrustify
const char USAGE_TEXT[] =
"Usage:\n"
-/*
- * Copyright (C) 2010, 2012 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This file contains tests for the functions operating on struct args.
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// This file contains tests for the functions operating on struct args.
#include "../ccache.h"
#include "framework.h"
-/*
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This file contains tests for the processing of compiler arguments.
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// This file contains tests for the processing of compiler arguments.
#include "../ccache.h"
#include "../conf.h"
#ifndef _WIN32
return x_strdup("/");
#else
- char volume[4]; /* "C:\" */
+ char volume[4]; // "C:\"
GetVolumePathName(get_cwd(), volume, sizeof(volume));
return x_strdup(volume);
#endif
char *posix;
char *p;
- /* / escape volume */
+ // /-escape volume.
if (path[0] >= 'A' && path[0] <= 'Z' && path[1] == ':') {
posix = format("/%s", path);
} else {
posix = x_strdup(path);
}
- /* convert slashes */
+ // Convert slashes.
for (p = posix; *p; p++) {
if (*p == '\\') {
*p = '/';
create_file("foo.c", "");
free(conf->base_dir);
- conf->base_dir = x_strdup("/"); /* posix */
+ conf->base_dir = x_strdup("/"); // posix
current_working_dir = get_cwd();
- /* windows path don't work concatenated */
+ // Windows path doesn't work concatenated.
cwd = get_posix_path(current_working_dir);
arg_string = format("cc -isystem%s/foo -c foo.c", cwd);
orig = args_init_from_string(arg_string);
create_file("foo.c", "");
free(conf->base_dir);
- conf->base_dir = x_strdup("/"); /* posix */
+ conf->base_dir = x_strdup("/"); // posix
current_working_dir = get_cwd();
- /* windows path don't work concatenated */
+ // Windows path doesn't work concatenated.
cwd = get_posix_path(current_working_dir);
arg_string = format("cc -I%s/foo -c foo.c", cwd);
orig = args_init_from_string(arg_string);
-/*
- * Copyright (C) 2010, 2012 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This file contains tests for the compopt_* functions.
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// This file contains tests for the compopt_* functions.
#include "../ccache.h"
#include "../compopt.h"
-/*
- * Copyright (C) 2011-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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2011-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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "../conf.h"
#include "framework.h"
"stats = false\n"
"temporary_dir = ${USER}_foo\n"
"umask = 777\n"
- "unify = true"); /* Note: no newline */
+ "unify = true"); // Note: no newline.
CHECK(conf_read(conf, "ccache.conf", &errmsg));
CHECK(!errmsg);
CHECK(!conf_read(conf, "ccache.conf", &errmsg));
CHECK_STR_EQ_FREE2("ccache.conf:1: syntax error: missing '}' after \"foo\"",
errmsg);
- /* Other cases tested in test_util.c. */
+ // Other cases tested in test_util.c.
conf_free(conf);
}
CHECK(!conf_read(conf, "ccache.conf", &errmsg));
CHECK_STR_EQ_FREE2("ccache.conf:1: invalid size: \"foo\"",
errmsg);
- /* Other cases tested in test_util.c. */
+ // Other cases tested in test_util.c.
conf_free(conf);
}
-/*
- * Copyright (C) 2010-2011 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2010-2011 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "../ccache.h"
#include "../counters.h"
-/*
- * Copyright (C) 2010 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This file contains tests for functions in hash.c.
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// This file contains tests for functions in hash.c.
#include "../ccache.h"
#include "framework.h"
-/*
- * Copyright (C) 2010, 2012 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This file contains tests for functions in hashutil.c.
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// This file contains tests for functions in hashutil.c.
#include "../ccache.h"
#include "../hashutil.h"
-/*
- * Copyright (C) 2010 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-/*
- * This file contains tests for functions in lockfile.c.
- */
+// This file contains tests for functions in lockfile.c.
#include "../ccache.h"
#include "framework.h"
-/*
- * Copyright (C) 2010-2011 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This file contains tests for statistics handling.
- */
+// Copyright (C) 2010-2011 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// This file contains tests for statistics handling.
#include "../ccache.h"
#include "../counters.h"
-/*
- * Copyright (C) 2010-2015 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This file contains tests for functions in util.c.
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+// This file contains tests for functions in util.c.
#include "../ccache.h"
#include "framework.h"
size_t i;
struct { const char *size; int64_t expected; } sizes[] = {
{"0", 0},
- {"42", (int64_t)42 * 1000 * 1000 * 1000}, /* Default suffix: G */
+ {"42", (int64_t)42 * 1000 * 1000 * 1000}, // Default suffix: G
{"78k", 78 * 1000},
{"78K", 78 * 1000},
-/*
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "../system.h"
#include "util.h"
-/*
- * Copyright (C) 2002 Andrew Tridgell
- *
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2002 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-/*
- * C/C++ unifier
- *
- * The idea is that changes that don't affect the resulting C code should not
- * change the hash. This is achieved by folding white-space and other
- * non-semantic fluff in the input into a single unified format.
- *
- * This unifier was design to match the output of the unifier in compilercache,
- * which is flex based. The major difference is that this unifier is much
- * faster (about 2x) and more forgiving of syntactic errors. Continuing on
- * syntactic errors is important to cope with C/C++ extensions in the local
- * compiler (for example, inline assembly systems).
- */
+// C/C++ unifier
+//
+// The idea is that changes that don't affect the resulting C code should not
+// change the hash. This is achieved by folding white-space and other
+// non-semantic fluff in the input into a single unified format.
+//
+// This unifier was design to match the output of the unifier in compilercache,
+// which is flex based. The major difference is that this unifier is much
+// faster (about 2x) and more forgiving of syntactic errors. Continuing on
+// syntactic errors is important to cope with C/C++ extensions in the local
+// compiler (for example, inline assembly systems).
#include "ccache.h"
const char *toks[7];
} tokens[256];
-/* build up the table used by the unifier */
+// Build up the table used by the unifier.
static void
build_table(void)
{
}
}
-/* buffer up characters before hashing them */
+// Buffer up characters before hashing them.
static void
pushchar(struct mdfour *hash, unsigned char c)
{
}
}
-/* hash some C/C++ code after unifying */
+// Hash some C/C++ code after unifying.
static void
unify(struct mdfour *hash, unsigned char *p, size_t size)
{
}
-/* hash a file that consists of preprocessor output, but remove any line
- number information from the hash
- */
+// Hash a file that consists of preprocessor output, but remove any line number
+// information from the hash.
int
unify_hash(struct mdfour *hash, const char *fname)
{
-/*
- * Copyright (C) 2002 Andrew Tridgell
- * 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
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// Copyright (C) 2002 Andrew Tridgell
+// 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
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ccache.h"
#endif
}
-/*
- * Warn about failure writing to the log file and then exit.
- */
+// Warn about failure writing to the log file and then exit.
static void
warn_log_fail(void)
{
extern struct conf *conf;
- /* Note: Can't call fatal() since that would lead to recursion. */
+ // Note: Can't call fatal() since that would lead to recursion.
fprintf(stderr, "ccache: error: Failed to write to %s: %s\n",
conf->log_file, strerror(errno));
x_exit(EXIT_FAILURE);
}
}
-/*
- * Write a message to the log file (adding a newline) and flush.
- */
+// Write a message to the log file (adding a newline) and flush.
void
cc_log(const char *format, ...)
{
}
}
-/*
- * Write a message to the log file (adding a newline) without flushing and with
- * a reused timestamp.
- */
+// Write a message to the log file (adding a newline) without flushing and with
+// a reused timestamp.
void
cc_bulklog(const char *format, ...)
{
va_end(ap);
}
-/*
- * Log an executed command to the CCACHE_LOGFILE location.
- */
+// Log an executed command to the CCACHE_LOGFILE location.
void
cc_log_argv(const char *prefix, char **argv)
{
}
}
-/* something went badly wrong! */
+// Something went badly wrong!
void
fatal(const char *format, ...)
{
x_exit(1);
}
-/*
- * Copy all data from fd_in to fd_out, decompressing data from fd_in if needed.
- */
+// Copy all data from fd_in to fd_out, decompressing data from fd_in if needed.
void
copy_fd(int fd_in, int fd_out)
{
}
#ifndef HAVE_MKSTEMP
-/* cheap and nasty mkstemp replacement */
+// Cheap and nasty mkstemp replacement.
int
mkstemp(char *template)
{
}
#endif
-/*
- * Copy src to dest, decompressing src if needed. compress_level > 0 decides
- * whether dest will be compressed, and with which compression level. Returns 0
- * on success and -1 on failure. On failure, errno represents the error.
- */
+// Copy src to dest, decompressing src if needed. compress_level > 0 decides
+// whether dest will be compressed, and with which compression level. Returns 0
+// on success and -1 on failure. On failure, errno represents the error.
int
copy_file(const char *src, const char *dest, int compress_level)
{
int errnum;
int saved_errno = 0;
- /* open destination file */
+ // Open destination file.
tmp_name = x_strdup(dest);
fd_out = create_tmp_fd(&tmp_name);
cc_log("Copying %s to %s via %s (%scompressed)",
src, dest, tmp_name, compress_level > 0 ? "" : "un");
- /* open source file */
+ // Open source file.
fd_in = open(src, O_RDONLY | O_BINARY);
if (fd_in == -1) {
saved_errno = errno;
}
if (compress_level > 0) {
- /*
- * A gzip file occupies at least 20 bytes, so it will always
- * occupy an entire filesystem block, even for empty files.
- * Turn off compression for empty files to save some space.
- */
+ // A gzip file occupies at least 20 bytes, so it will always occupy an
+ // entire filesystem block, even for empty files. Turn off compression for
+ // empty files to save some space.
if (x_fstat(fd_in, &st) != 0) {
goto error;
}
}
}
- /*
- * gzeof won't tell if there's an error in the trailing CRC, so we must check
- * gzerror before considering everything OK.
- */
+ // gzeof won't tell if there's an error in the trailing CRC, so we must check
+ // gzerror before considering everything OK.
gzerror(gz_in, &errnum);
if (!gzeof(gz_in) || (errnum != Z_OK && errnum != Z_STREAM_END)) {
saved_errno = errno;
fchmod(fd_out, 0666 & ~get_umask());
#endif
- /* the close can fail on NFS if out of space */
+ // The close can fail on NFS if out of space.
if (close(fd_out) == -1) {
saved_errno = errno;
cc_log("close error: %s", strerror(saved_errno));
return -1;
}
-/* Run copy_file() and, if successful, delete the source file. */
+// Run copy_file() and, if successful, delete the source file.
int
move_file(const char *src, const char *dest, int compress_level)
{
return ret;
}
-/*
- * Like move_file(), but assumes that src is uncompressed and that src and dest
- * are on the same file system.
- */
+// Like move_file(), but assumes that src is uncompressed and that src and dest
+// are on the same file system.
int
move_uncompressed_file(const char *src, const char *dest, int compress_level)
{
}
}
-/* test if a file is zlib compressed */
+// Test if a file is zlib compressed.
bool
file_is_compressed(const char *filename)
{
return false;
}
- /* test if file starts with 1F8B, which is zlib's
- * magic number */
+ // Test if file starts with 1F8B, which is zlib's magic number.
if ((fgetc(f) != 0x1f) || (fgetc(f) != 0x8b)) {
fclose(f);
return false;
return true;
}
-/* make sure a directory exists */
+// Make sure a directory exists.
int
create_dir(const char *dir)
{
return 0;
}
-/* Create directories leading to path. Returns 0 on success, otherwise -1. */
+// Create directories leading to path. Returns 0 on success, otherwise -1.
int
create_parent_dirs(const char *path)
{
res = create_parent_dirs(parent);
if (res == 0) {
res = mkdir(parent, 0777);
- /* Have to handle the condition of the directory already existing because
- * the file system could have changed in between calling stat and
- * actually creating the directory. This can happen when there are
- * multiple instances of ccache running and trying to create the same
- * directory chain, which usually is the case when the cache root does
- * not initially exist. As long as one of the processes creates the
- * directories then our condition is satisfied and we avoid a race
- * condition.
- */
+ // Have to handle the condition of the directory already existing because
+ // the file system could have changed in between calling stat and
+ // actually creating the directory. This can happen when there are
+ // multiple instances of ccache running and trying to create the same
+ // directory chain, which usually is the case when the cache root does
+ // not initially exist. As long as one of the processes creates the
+ // directories then our condition is satisfied and we avoid a race
+ // condition.
if (res != 0 && errno == EEXIST) {
res = 0;
}
return res;
}
-/*
- * Return a static string with the current hostname.
- */
+// Return a static string with the current hostname.
const char *
get_hostname(void)
{
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
- /* Tell the user that we could not find a usable Winsock DLL. */
+ // Tell the user that we could not find a usable Winsock DLL.
cc_log("WSAStartup failed with error: %d", err);
return hostname;
}
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
- /* Tell the user that we could not find a usable WinSock DLL. */
+ // Tell the user that we could not find a usable WinSock DLL.
cc_log("Could not find a usable version of Winsock.dll");
WSACleanup();
return hostname;
return hostname;
}
-/*
- * Return a string to be passed to mkstemp to create a temporary file. Also
- * tries to cope with NFS by adding the local hostname.
- */
+// Return a string to be passed to mkstemp to create a temporary file. Also
+// tries to cope with NFS by adding the local hostname.
const char *
tmp_string(void)
{
return ret;
}
-/*
- * Return the hash result as a hex string. Size -1 means don't include size
- * suffix. Caller frees.
- */
+// Return the hash result as a hex string. Size -1 means don't include size
+// suffix. Caller frees.
char *
format_hash_as_string(const unsigned char *hash, int size)
{
return 1;
}
-/* Construct a string according to a format. Caller frees. */
+// Construct a string according to a format. Caller frees.
char *
format(const char *format, ...)
{
return ptr;
}
-/* This is like strdup() but dies if the malloc fails. */
+// This is like strdup() but dies if the malloc fails.
char *
x_strdup(const char *s)
{
return ret;
}
-/* This is like strndup() but dies if the malloc fails. */
+// This is like strndup() but dies if the malloc fails.
char *
x_strndup(const char *s, size_t n)
{
return ret;
}
-/* This is like malloc() but dies if the malloc fails. */
+// This is like malloc() but dies if the malloc fails.
void *
x_malloc(size_t size)
{
void *ret;
if (size == 0) {
- /*
- * malloc() may return NULL if size is zero, so always do this to make sure
- * that the code handles it regardless of platform.
- */
+ // malloc() may return NULL if size is zero, so always do this to make sure
+ // that the code handles it regardless of platform.
return NULL;
}
ret = malloc(size);
return ret;
}
-/* This is like calloc() but dies if the allocation fails. */
+// This is like calloc() but dies if the allocation fails.
void *
x_calloc(size_t nmemb, size_t size)
{
void *ret;
if (nmemb * size == 0) {
- /*
- * calloc() may return NULL if nmemb or size is 0, so always do this to
- * make sure that the code handles it regardless of platform.
- */
+ // calloc() may return NULL if nmemb or size is 0, so always do this to
+ // make sure that the code handles it regardless of platform.
return NULL;
}
ret = calloc(nmemb, size);
return ret;
}
-/* This is like realloc() but dies if the malloc fails. */
+// This is like realloc() but dies if the malloc fails.
void *
x_realloc(void *ptr, size_t size)
{
return p2;
}
-/* This is like unsetenv. */
+// This is like unsetenv.
void x_unsetenv(const char *name)
{
#ifdef HAVE_UNSETENV
unsetenv(name);
#else
- putenv(x_strdup(name)); /* Leak to environment. */
+ putenv(x_strdup(name)); // Leak to environment.
#endif
}
-/* Like fstat() but also call cc_log on failure. */
+// Like fstat() but also call cc_log on failure.
int
x_fstat(int fd, struct stat *buf)
{
return result;
}
-/* Like lstat() but also call cc_log on failure. */
+// Like lstat() but also call cc_log on failure.
int
x_lstat(const char *pathname, struct stat *buf)
{
return result;
}
-/* Like stat() but also call cc_log on failure. */
+// Like stat() but also call cc_log on failure.
int
x_stat(const char *pathname, struct stat *buf)
{
return result;
}
-/*
- * Construct a string according to the format and store it in *ptr. The
- * original *ptr is then freed.
- */
+// Construct a string according to the format and store it in *ptr. The
+// original *ptr is then freed.
void
reformat(char **ptr, const char *format, ...)
{
}
}
-/*
- * Recursive directory traversal. fn() is called on all entries in the tree.
- */
+// Recursive directory traversal. fn() is called on all entries in the tree.
void
traverse(const char *dir, void (*fn)(const char *, struct stat *))
{
}
-/* return the base name of a file - caller frees */
+// Return the base name of a file - caller frees.
char *
basename(const char *path)
{
return x_strdup(path);
}
-/* return the dir name of a file - caller frees */
+// Return the dir name of a file - caller frees.
char *
dirname(const char *path)
{
return s;
}
-/*
- * Return the file extension (including the dot) of a path as a pointer into
- * path. If path has no file extension, the empty string and the end of path is
- * returned.
- */
+// Return the file extension (including the dot) of a path as a pointer into
+// path. If path has no file extension, the empty string and the end of path is
+// returned.
const char *
get_extension(const char *path)
{
return &path[len];
}
-/*
- * Return a string containing the given path without the filename extension.
- * Caller frees.
- */
+// Return a string containing the given path without the filename extension.
+// Caller frees.
char *
remove_extension(const char *path)
{
return x_strndup(path, strlen(path) - strlen(get_extension(path)));
}
-/* return size on disk of a file */
+// Return size on disk of a file.
size_t
file_size(struct stat *st)
{
#else
size_t size = st->st_blocks * 512;
if ((size_t)st->st_size > size) {
- /* probably a broken stat() call ... */
+ // Probably a broken stat() call...
size = (st->st_size + 1023) & ~1023;
}
return size;
#endif
}
-/* Format a size as a human-readable string. Caller frees. */
+// Format a size as a human-readable string. Caller frees.
char *
format_human_readable_size(uint64_t v)
{
return s;
}
-/* Format a size as a parsable string. Caller frees. */
+// Format a size as a parsable string. Caller frees.
char *
format_parsable_size_with_suffix(uint64_t size)
{
return s;
}
-/*
- * Parse a "size value", i.e. a string that can end in k, M, G, T (10-based
- * suffixes) or Ki, Mi, Gi, Ti (2-based suffixes). For backward compatibility,
- * K is also recognized as a synonym of k.
- */
+// Parse a "size value", i.e. a string that can end in k, M, G, T (10-based
+// suffixes) or Ki, Mi, Gi, Ti (2-based suffixes). For backward compatibility,
+// K is also recognized as a synonym of k.
bool
parse_size_with_suffix(const char *str, uint64_t *size)
{
return false;
}
} else {
- /* Default suffix: G. */
+ // Default suffix: G.
x *= 1000 * 1000 * 1000;
}
*size = x;
TCHAR *p = szTemp;
do {
- // Copy the drive letter to the template string
+ // Copy the drive letter to the template string.
*szDrive = *p;
- // Look up each device name
+ // Look up each device name.
if (QueryDosDevice(szDrive, szName, MAX_PATH)) {
size_t uNameLen = _tcslen(szName);
bFound = _tcsnicmp(pszFilename, szName, uNameLen) == 0
&& *(pszFilename + uNameLen) == _T('\\');
if (bFound) {
- // Reconstruct pszFilename using szTempFile
- // Replace device path with DOS path
+ // Reconstruct pszFilename using szTempFile and replace device
+ // path with DOS path.
TCHAR szTempFile[MAX_PATH];
_sntprintf(szTempFile,
MAX_PATH - 1,
while (*p++) {
// Do nothing.
}
- } while (!bFound && *p); // end of string
+ } while (!bFound && *p); // End of string.
}
}
bSuccess = TRUE;
}
#endif
-/* A sane realpath() function, trying to cope with stupid path limits and a
- * broken API. Caller frees. */
+// A sane realpath() function, trying to cope with stupid path limits and a
+// broken API. Caller frees.
char *
x_realpath(const char *path)
{
p = realpath(path, ret);
#elif defined(_WIN32)
if (path[0] == '/') {
- path++; /* skip leading slash */
+ path++; // Skip leading slash.
}
path_handle = CreateFile(
path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
GetFileNameFromHandle(path_handle, ret, maxlen);
#endif
CloseHandle(path_handle);
- p = ret + 4; /* strip \\?\ from the file name */
+ p = ret + 4; // Strip \\?\ from the file name.
} else {
snprintf(ret, maxlen, "%s", path);
p = ret;
}
#else
- /* yes, there are such systems. This replacement relies on
- the fact that when we call x_realpath we only care about symlinks */
+ // Yes, there are such systems. This replacement relies on the fact that when
+ // we call x_realpath we only care about symlinks.
{
int len = readlink(path, ret, maxlen-1);
if (len == -1) {
return NULL;
}
-/* a getcwd that will returns an allocated buffer */
+// A getcwd that will returns an allocated buffer.
char *
gnu_getcwd(void)
{
}
#ifndef HAVE_STRTOK_R
-/* strtok_r replacement */
+// strtok_r replacement.
char *
strtok_r(char *str, const char *delim, char **saveptr)
{
if (ret) {
char *save = ret;
while (*save++) {
- /* Do nothing. */
+ // Do nothing.
}
if ((len + 1) == (intptr_t) (save - str)) {
save--;
}
#endif
-/*
- * Create an empty temporary file. *fname will be reallocated and set to the
- * resulting filename. Returns an open file descriptor to the file.
- */
+// Create an empty temporary file. *fname will be reallocated and set to the
+// resulting filename. Returns an open file descriptor to the file.
int
create_tmp_fd(char **fname)
{
return fd;
}
-/*
- * Create an empty temporary file. *fname will be reallocated and set to the
- * resulting filename. Returns an open FILE*.
- */
+// Create an empty temporary file. *fname will be reallocated and set to the
+// resulting filename. Returns an open FILE*.
FILE *
create_tmp_file(char **fname, const char *mode)
{
return file;
}
-/*
- * Return current user's home directory, or NULL if it can't be determined.
- */
+// Return current user's home directory, or NULL if it can't be determined.
const char *
get_home_directory(void)
{
return NULL;
}
-/*
- * Get the current directory by reading $PWD. If $PWD isn't sane, gnu_getcwd()
- * is used. Caller frees.
- */
+// Get the current directory by reading $PWD. If $PWD isn't sane, gnu_getcwd()
+// is used. Caller frees.
char *
get_cwd(void)
{
}
}
-/*
- * Check whether s1 and s2 have the same executable name.
- */
+// Check whether s1 and s2 have the same executable name.
bool
same_executable_name(const char *s1, const char *s2)
{
#endif
}
-/*
- * Compute the length of the longest directory path that is common to two
- * paths. s1 is assumed to be the path to a directory.
- */
+// Compute the length of the longest directory path that is common to two
+// paths. s1 is assumed to be the path to a directory.
size_t
common_dir_prefix_length(const char *s1, const char *s2)
{
p2--;
}
if (!*p1 && !*p2 && p2 == s2 + 1) {
- /* Special case for s1 and s2 both being "/". */
+ // Special case for s1 and s2 both being "/".
return 0;
}
return p1 - s1;
}
-/*
- * Compute a relative path from from (an absolute path to a directory) to to (a
- * path). Assumes that both from and to are well-formed and canonical. Caller
- * frees.
- */
+// Compute a relative path from from (an absolute path to a directory) to to (a
+// path). Assumes that both from and to are well-formed and canonical. Caller
+// frees.
char *
get_relative_path(const char *from, const char *to)
{
}
#ifdef _WIN32
- // Paths can be escaped by a slash for use with -isystem
+ // Paths can be escaped by a slash for use with -isystem.
if (from[0] == '/') {
from++;
}
if (to[0] == '/') {
to++;
}
- // Both paths are absolute, drop the drive letters
- assert(from[0] == to[0]); // Assume the same drive letter
+ // Both paths are absolute, drop the drive letters.
+ assert(from[0] == to[0]); // Assume the same drive letter.
from += 2;
to += 2;
#endif
return result;
}
-/*
- * Return whether path is absolute.
- */
+// Return whether path is absolute.
bool
is_absolute_path(const char *path)
{
#endif
}
-/*
- * Return whether the argument is a full path.
- */
+// Return whether the argument is a full path.
bool
is_full_path(const char *path)
{
#endif
}
-/*
- * Update the modification time of a file in the cache to save it from LRU
- * cleanup.
- */
+// Update the modification time of a file in the cache to save it from LRU
+// cleanup.
void
update_mtime(const char *path)
{
#endif
}
-/*
- * If exit() already has been called, call _exit(), otherwise exit(). This is
- * used to avoid calling exit() inside an atexit handler.
- */
+// If exit() already has been called, call _exit(), otherwise exit(). This is
+// used to avoid calling exit() inside an atexit handler.
void
x_exit(int status)
{
}
}
-/*
- * Rename oldpath to newpath (deleting newpath).
- */
+// Rename oldpath to newpath (deleting newpath).
int
x_rename(const char *oldpath, const char *newpath)
{
#ifndef _WIN32
return rename(oldpath, newpath);
#else
- /* Windows' rename() refuses to overwrite an existing file. */
- unlink(newpath); /* not x_unlink, as x_unlink calls x_rename */
- /* If the function succeeds, the return value is nonzero. */
+ // Windows' rename() refuses to overwrite an existing file.
+ unlink(newpath); // Not x_unlink, as x_unlink calls x_rename.
+ // If the function succeeds, the return value is nonzero.
if (MoveFileA(oldpath, newpath) == 0) {
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
#endif
}
-/*
- * Remove path, NFS hazardous. Use only for temporary files that will not exist
- * on other systems. That is, the path should include tmp_string().
- */
+// Remove path, NFS hazardous. Use only for temporary files that will not exist
+// on other systems. That is, the path should include tmp_string().
int
tmp_unlink(const char *path)
{
return rc;
}
-/*
- * Remove path, NFS safe.
- */
+// Remove path, NFS safe.
int
x_unlink(const char *path)
{
- /*
- * If path is on an NFS share, unlink isn't atomic, so we rename to a temp
- * file. We don't care if the temp file is trashed, so it's always safe to
- * unlink it first.
- */
+ // If path is on an NFS share, unlink isn't atomic, so we rename to a temp
+ // file. We don't care if the temp file is trashed, so it's always safe to
+ // unlink it first.
char *tmp_name = format("%s.rm.%s", path, tmp_string());
int result = 0;
int saved_errno = 0;
goto out;
}
if (unlink(tmp_name) == -1) {
- /* If it was released in a race, that's OK. */
+ // If it was released in a race, that's OK.
if (errno != ENOENT && errno != ESTALE) {
result = -1;
saved_errno = errno;
}
#ifndef _WIN32
-/* Like readlink() but returns the string or NULL on failure. Caller frees. */
+// Like readlink() but returns the string or NULL on failure. Caller frees.
char *
x_readlink(const char *path)
{
}
#endif
-/*
- * Reads the content of a file. Size hint 0 means no hint. Returns true on
- * success, otherwise false.
- */
+// Reads the content of a file. Size hint 0 means no hint. Returns true on
+// success, otherwise false.
bool
read_file(const char *path, size_t size_hint, char **data, size_t *size)
{
return true;
}
-/*
- * Return the content (with NUL termination) of a text file, or NULL on error.
- * Caller frees. Size hint 0 means no hint.
- */
+// Return the content (with NUL termination) of a text file, or NULL on error.
+// Caller frees. Size hint 0 means no hint.
char *
read_text_file(const char *path, size_t size_hint)
{
}
if (q == p) {
- /* Special case: don't consider a single $ the start of a variable. */
+ // Special case: don't consider a single $ the start of a variable.
reformat(result, "%s$", *result);
return true;
}
return true;
}
-/*
- * Substitute all instances of $VAR or ${VAR}, where VAR is an environment
- * variable, in a string. Caller frees. If one of the environment variables
- * doesn't exist, NULL will be returned and *errmsg will be an appropriate
- * error message (caller frees).
- */
+// Substitute all instances of $VAR or ${VAR}, where VAR is an environment
+// variable, in a string. Caller frees. If one of the environment variables
+// doesn't exist, NULL will be returned and *errmsg will be an appropriate
+// error message (caller frees).
char *
subst_env_in_string(const char *str, char **errmsg)
{
- const char *p; /* Interval start. */
- const char *q; /* Interval end. */
+ const char *p; // Interval start.
+ const char *q; // Interval end.
char *result;
assert(errmsg);