struct stat st;
time_t now = time(NULL);
- stat(conf->cache_dir, &st);
- if (st.st_mtime + 3600 >= now) {
+ if (x_stat(conf->cache_dir, &st) != 0 || st.st_mtime + 3600 >= now) {
/* No cleanup needed. */
return;
}
}
path = format("%s/%s", temp_dir(), entry->d_name);
- if (lstat(path, &st) == 0 && st.st_mtime + 3600 < now) {
+ if (x_lstat(path, &st) == 0 && st.st_mtime + 3600 < now) {
tmp_unlink(path);
}
free(path);
goto ignore;
#endif
- if (stat(path, &st) != 0) {
- cc_log("Failed to stat include file %s: %s", path, strerror(errno));
+ if (x_stat(path, &st) != 0) {
goto failure;
}
if (S_ISDIR(st.st_mode)) {
failed();
}
cc_log("Stored in cache: %s -> %s", source, dest);
- if (stat(dest, &st) != 0) {
- cc_log("Failed to stat %s: %s", dest, strerror(errno));
+ if (x_stat(dest, &st) != 0) {
stats_update(STATS_ERROR);
failed();
}
if (manifest_put(manifest_path, cached_obj_hash, included_files)) {
cc_log("Added object file hash to %s", manifest_path);
update_mtime(manifest_path);
- if (stat(manifest_path, &st) == 0) {
+ if (x_stat(manifest_path, &st) == 0) {
stats_update_size(file_size(&st) - old_size, old_size == 0 ? 1 : 0);
- } else {
- cc_log("Failed to stat %s: %s", manifest_path, strerror(errno));
}
} else {
cc_log("Failed to add object file hash to %s", manifest_path);
status = execute(args->argv, tmp_stdout_fd, tmp_stderr_fd);
args_pop(args, 3);
- if (stat(tmp_stdout, &st) != 0) {
+ if (x_stat(tmp_stdout, &st) != 0) {
/* The stdout file was removed - cleanup in progress? Better bail out. */
- cc_log("%s not found: %s", tmp_stdout, strerror(errno));
stats_update(STATS_MISSING);
tmp_unlink(tmp_stdout);
tmp_unlink(tmp_stderr);
failed();
}
- if (stat(output_obj, &st) != 0) {
+ if (x_stat(output_obj, &st) != 0) {
cc_log("Compiler didn't produce an object file");
stats_update(STATS_NOOUTPUT);
failed();
failed();
}
- if (stat(tmp_stderr, &st) != 0) {
- cc_log("Failed to stat %s: %s", tmp_stderr, strerror(errno));
+ if (x_stat(tmp_stderr, &st) != 0) {
stats_update(STATS_ERROR);
failed();
}
failed();
}
cc_log("Stored in cache: %s", cached_stderr);
- if (conf->compression) {
- /* The file was compressed, so obtain the size again. */
- if (stat(cached_stderr, &st) == 0) {
- stats_update_size(file_size(&st), 1);
- } else {
- cc_log("Failed to stat %s: %s", cached_stderr, strerror(errno));
- }
- } else {
+ if (!conf->compression
+ /* If the file was compressed, obtain the size again: */
+ || (conf->compression && x_stat(cached_stderr, &st) == 0)) {
stats_update_size(file_size(&st), 1);
}
} else {
}
if (output_dia) {
- if (stat(output_dia, &st) != 0) {
- cc_log("Failed to stat %s: %s", output_dia, strerror(errno));
+ if (x_stat(output_dia, &st) != 0) {
stats_update(STATS_ERROR);
failed();
}
full_path = full_path_win_ext;
#endif
- if (stat(full_path, &st) != 0) {
- cc_log("Couldn't stat compiler %s: %s", args->argv[0], strerror(errno));
+ if (x_stat(full_path, &st) != 0) {
stats_update(STATS_COMPILER);
failed();
}
} else if (str_startswith(args->argv[i], "--specs=")) {
p = args->argv[i] + 8;
}
- if (p && stat(p, &st) == 0) {
+ 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. */
hash_delimiter(hash, "specs");
}
if (str_startswith(args->argv[i], "-fplugin=")
- && stat(args->argv[i] + 9, &st) == 0) {
+ && x_stat(args->argv[i] + 9, &st) == 0) {
hash_delimiter(hash, "plugin");
hash_compiler(hash, &st, args->argv[i] + 9, false);
continue;
&& i + 3 < args->argc
&& str_eq(args->argv[i+1], "-load")
&& str_eq(args->argv[i+2], "-Xclang")
- && stat(args->argv[i+3], &st) == 0) {
+ && x_stat(args->argv[i+3], &st) == 0) {
hash_delimiter(hash, "plugin");
hash_compiler(hash, &st, args->argv[i+3], false);
continue;
* occupy an entire filesystem block, even for empty files.
* Turn off compression for empty files to save some space.
*/
- if (fstat(fd_in, &st) != 0) {
- cc_log("fstat error: %s", strerror(errno));
+ if (x_fstat(fd_in, &st) != 0) {
goto error;
}
if (file_size(&st) == 0) {
#endif
}
+/* Like fstat() but also call cc_log on failure. */
+int
+x_fstat(int fd, struct stat *buf)
+{
+ int result = fstat(fd, buf);
+ if (result != 0) {
+ cc_log("Failed to fstat fd %d: %s", fd, strerror(errno));
+ }
+ return result;
+}
+
+/* Like lstat() but also call cc_log on failure. */
+int
+x_lstat(const char *pathname, struct stat *buf)
+{
+ int result = lstat(pathname, buf);
+ if (result != 0) {
+ cc_log("Failed to lstat %s: %s", pathname, strerror(errno));
+ }
+ return result;
+}
+
+/* Like stat() but also call cc_log on failure. */
+int
+x_stat(const char *pathname, struct stat *buf)
+{
+ int result = stat(pathname, buf);
+ if (result != 0) {
+ cc_log("Failed to stat %s: %s", pathname, strerror(errno));
+ }
+ return result;
+}
+
/*
* Construct a string according to the format and store it in *ptr. The
* original *ptr is then freed.
if (size_hint == 0) {
struct stat st;
- if (stat(path, &st) == 0) {
+ if (x_stat(path, &st) == 0) {
size_hint = st.st_size;
}
}