* quote */
quoting = '\0';
- if (!(argtext = read_text_file(filename, 0)))
+ if (!(argtext = read_text_file(filename, 0))) {
return NULL;
+ }
args = args_init(0, NULL);
pos = argtext;
case '\0':
/* end of token */
*argpos = '\0';
- if (argbuf[0] != '\0')
+ if (argbuf[0] != '\0') {
args_add(args, argbuf);
+ }
argpos = argbuf;
if (*pos == '\0') {
goto out;
/* stat fails on directories on win32 */
attributes = GetFileAttributes(path);
if (attributes != INVALID_FILE_ATTRIBUTES &&
- attributes & FILE_ATTRIBUTE_DIRECTORY)
+ attributes & FILE_ATTRIBUTE_DIRECTORY) {
goto ignore;
+ }
#endif
if (x_stat(path, &st) != 0) {
}
#ifdef _WIN32
- if (path[0] == '/')
+ if (path[0] == '/') {
path++; /* skip leading slash */
+ }
#endif
/* x_realpath only works for existing paths, so if path doesn't exist, try
add_pending_tmp_file(path_stdout);
args_add(args, "-E");
- if (conf->keep_comments_cpp)
+ if (conf->keep_comments_cpp) {
args_add(args, "-C");
+ }
args_add(args, input_file);
add_prefix(args, conf->prefix_command_cpp);
cc_log("Running preprocessor");
context);
reformat(&s, "keep_comments_cpp = %s", bool_to_string(conf->keep_comments_cpp));
- printer(s, conf->item_origins[find_conf("keep_comments_cpp")->number], context);
+ printer(s, conf->item_origins[find_conf(
+ "keep_comments_cpp")->number], context);
reformat(&s, "log_file = %s", conf->log_file);
printer(s, conf->item_origins[find_conf("log_file")->number], context);
} while ((arg = argv[i++]));
str = ptr = malloc(l + 1);
- if (!str)
+ if (!str) {
return NULL;
+ }
i = 0;
arg = prefix ? prefix : argv[i++];
case '"':
bs = (bs << 1) + 1;
default:
- while (bs && bs--)
+ while (bs && bs--) {
*ptr++ = '\\';
+ }
*ptr++ = arg[j];
}
}
bs <<= 1;
- while (bs && bs--)
+ while (bs && bs--) {
*ptr++ = '\\';
+ }
*ptr++ = '"';
*ptr++ = ' ';
/* cppcheck-suppress unreadVariable */
const char *ext;
ext = get_extension(path);
- if (ext && strcasecmp(ext, ".sh") == 0 && (path_env = getenv("PATH")))
+ if (ext && strcasecmp(ext, ".sh") == 0 && (path_env = getenv("PATH"))) {
sh = find_executable_in_path("sh.exe", NULL, path_env);
+ }
if (!sh && getenv("CCACHE_DETECT_SHEBANG")) {
/* Detect shebang. */
FILE *fp;
char buf[10];
fgets(buf, sizeof(buf), fp);
buf[9] = 0;
- if (str_eq(buf, "#!/bin/sh") && (path_env = getenv("PATH")))
+ if (str_eq(buf, "#!/bin/sh") && (path_env = getenv("PATH"))) {
sh = find_executable_in_path("sh.exe", NULL, path_env);
+ }
fclose(fp);
}
}
memset(&si, 0x00, sizeof(si));
sh = win32getshell(path);
- if (sh)
+ if (sh) {
path = sh;
+ }
si.cb = sizeof(STARTUPINFO);
if (fd_stdout != -1) {
GetExitCodeProcess(pi.hProcess, &exitcode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
- if (!doreturn)
+ if (!doreturn) {
x_exit(exitcode);
+ }
return exitcode;
}
#ifdef _WIN32
/* trim leading space */
- while (isspace(*command))
+ while (isspace(*command)) {
command++;
+ }
/* add "echo" command */
if (str_startswith(command, "echo")) {
command = format("cmd.exe /c \"%s\"", command);
cmd = true;
- } else if (str_startswith(command, "%compiler%") && str_eq(compiler, "echo")) {
+ } else if (str_startswith(command,
+ "%compiler%") && str_eq(compiler, "echo")) {
command = format("cmd.exe /c \"%s%s\"", compiler, command + 10);
cmd = true;
} else {
memset(&si, 0x00, sizeof(si));
path = find_executable(args->argv[0], NULL);
- if (!path)
+ if (!path) {
path = args->argv[0];
+ }
sh = win32getshell(path);
- if (sh)
+ if (sh) {
path = sh;
+ }
si.cb = sizeof(STARTUPINFO);
CreatePipe(&pipe_out[0], &pipe_out[1], &sa, 0);
si.hStdError = pipe_out[1];
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
si.dwFlags = STARTF_USESTDHANDLES;
- if (!cmd)
+ if (!cmd) {
win32args = win32argvtos(sh, args->argv);
- else
- win32args = (char *) command; /* quoted */
+ } else {
+ 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 */
+ if (cmd) {
+ free((char *) command); /* original argument was replaced above */
+ }
if (ret == 0) {
stats_update(STATS_COMPCHECK);
return false;
#ifdef WORDS_BIGENDIAN
int i;
- for (i = 0; i < 16; i++)
+ for (i = 0; i < 16; i++) {
M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
(in[i*4+1]<<8) | (in[i*4+0]<<0);
+ }
#else
memcpy(M, in, 16*4);
#endif
char *p;
/* / escape volume */
- if (path[0] >= 'A' && path[0] <= 'Z' && path[1] == ':')
+ if (path[0] >= 'A' && path[0] <= 'Z' && path[1] == ':') {
posix = format("/%s", path);
- else
+ } else {
posix = x_strdup(path);
+ }
/* convert slashes */
for (p = posix; *p; p++) {
- if (*p == '\\')
+ if (*p == '\\') {
*p = '/';
+ }
}
return posix;
#endif
#ifndef HAVE_STRNDUP
size_t m;
- if (!s)
+ if (!s) {
return NULL;
+ }
m = 0;
while (m < n && s[m]) {
m++;
}
// Go to the next NULL character.
- while (*p++) ;
+ while (*p++) {
+ // Do nothing.
+ }
} while (!bFound && *p); // end of string
}
}
#if HAVE_REALPATH
p = realpath(path, ret);
#elif defined(_WIN32)
- if (path[0] == '/')
+ if (path[0] == '/') {
path++; /* skip leading slash */
+ }
path_handle = CreateFile(
path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
{
int len;
char *ret;
- if (!str)
+ if (!str) {
str = *saveptr;
+ }
len = strlen(str);
ret = strtok(str, delim);
if (ret) {
char *save = ret;
- while (*save++) ;
- if ((len + 1) == (intptr_t) (save - str))
+ while (*save++) {
+ /* Do nothing. */
+ }
+ if ((len + 1) == (intptr_t) (save - str)) {
save--;
+ }
*saveptr = save;
}
return ret;
#ifdef _WIN32
// Paths can be escaped by a slash for use with -isystem
- if (from[0] == '/')
+ if (from[0] == '/') {
from++;
- if (to[0] == '/')
+ }
+ if (to[0] == '/') {
to++;
+ }
// Both paths are absolute, drop the drive letters
assert(from[0] == to[0]); // Assume the same drive letter
from += 2;
bool
is_full_path(const char *path)
{
- if (strchr(path, '/'))
+ if (strchr(path, '/')) {
return true;
+ }
#ifdef _WIN32
- if (strchr(path, '\\'))
+ if (strchr(path, '\\')) {
return true;
+ }
#endif
return false;
}