]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve names of variables and functions related to the debug log
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 24 Jan 2019 20:41:57 +0000 (21:41 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 24 Jan 2019 20:41:57 +0000 (21:41 +0100)
src/ccache.c
src/ccache.h
src/util.c

index 8c227df40ffa8aed2d4e16081045e75e86ee482b..34839354404fbabaddc030dbf1161a918756bb9d 100644 (file)
@@ -500,14 +500,14 @@ fclose_exitfn(void *context)
 }
 
 static void
-dump_log_buffer_exitfn(void *context)
+dump_debug_log_buffer_exitfn(void *context)
 {
        if (!conf->debug) {
                return;
        }
 
        char *path = format("%s.ccache-log", (const char *)context);
-       cc_dump_log_buffer(path);
+       cc_dump_debug_log_buffer(path);
        free(path);
 }
 
@@ -3668,7 +3668,7 @@ ccache(int argc, char *argv[])
        cc_log("Object file: %s", output_obj);
 
        // Need to dump log buffer as the last exit function to not lose any logs.
-       exitfn_add_last(dump_log_buffer_exitfn, output_obj);
+       exitfn_add_last(dump_debug_log_buffer_exitfn, output_obj);
 
        FILE *debug_text_file = NULL;
        if (conf->debug) {
index 70c18b38da871e3c8ff45541216b2a72456956ec..12d155ddcaf89cc766dda4ee57ff67cc75a6fb13 100644 (file)
@@ -144,7 +144,7 @@ bool args_equal(struct args *args1, struct args *args2);
 void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 void cc_bulklog(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 void cc_log_argv(const char *prefix, char **argv);
-void cc_dump_log_buffer(const char *path);
+void cc_dump_debug_log_buffer(const char *path);
 void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2) ATTR_NORETURN;
 void warn(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 
index ba80a72ae01701ebd62f36aad19583bb7a2590de..7fa9fe6d4e81fb234381a1817438f637677f6ea0 100644 (file)
 #include <tchar.h>
 #endif
 
+// Destination for conf->log_file.
 static FILE *logfile;
-static char *logbuffer;
-static size_t logbufsize;
-static size_t logsize;
 
-#define LOGBUFSIZ 1024
+// Buffer used for logs in conf->debug mode.
+static char *debug_log_buffer;
+
+// Allocated debug_log_buffer size.
+static size_t debug_log_buffer_capacity;
+
+// The amount of log data stored in debug_log_buffer.
+static size_t debug_log_size;
+
+#define DEBUG_LOG_BUFFER_MARGIN 1024
 
 static bool
 init_log(void)
 {
        extern struct conf *conf;
 
-       if (logbuffer || logfile) {
+       if (debug_log_buffer || logfile) {
                return true;
        }
        assert(conf);
        if (conf->debug) {
-               logbufsize = LOGBUFSIZ;
-               logbuffer = x_malloc(logbufsize);
-               logsize = 0;
+               debug_log_buffer_capacity = DEBUG_LOG_BUFFER_MARGIN;
+               debug_log_buffer = x_malloc(debug_log_buffer_capacity);
+               debug_log_size = 0;
        }
        if (str_eq(conf->log_file, "")) {
                return conf->debug;
@@ -69,15 +76,15 @@ init_log(void)
 }
 
 static void
-append_log(const char *s, size_t len)
+append_to_debug_log(const char *s, size_t len)
 {
-       assert(logbuffer);
-       if (logsize + len + 1 > logbufsize) {
-               logbufsize = logbufsize + len + 1 + LOGBUFSIZ;
-               logbuffer = x_realloc(logbuffer, logbufsize);
+       assert(debug_log_buffer);
+       if (debug_log_size + len + 1 > debug_log_buffer_capacity) {
+               debug_log_buffer_capacity += len + 1 + DEBUG_LOG_BUFFER_MARGIN;
+               debug_log_buffer = x_realloc(debug_log_buffer, debug_log_buffer_capacity);
        }
-       memcpy(logbuffer + logsize, s, len);
-       logsize += len;
+       memcpy(debug_log_buffer + debug_log_size, s, len);
+       debug_log_size += len;
 }
 
 static void
@@ -105,8 +112,8 @@ log_prefix(bool log_updated_time)
        if (logfile) {
                fputs(prefix, logfile);
        }
-       if (logbuffer) {
-               append_log(prefix, strlen(prefix));
+       if (debug_log_buffer) {
+               append_to_debug_log(prefix, strlen(prefix));
        }
 }
 
@@ -156,12 +163,12 @@ vlog(const char *format, va_list ap, bool log_updated_time)
                        warn_log_fail();
                }
        }
-       if (logbuffer) {
+       if (debug_log_buffer) {
                char buf[8192];
                int len = vsnprintf(buf, sizeof(buf), format, aq);
                if (len >= 0) {
-                       append_log(buf, MIN((size_t)len, sizeof(buf) - 1));
-                       append_log("\n", 1);
+                       append_to_debug_log(buf, MIN((size_t)len, sizeof(buf) - 1));
+                       append_to_debug_log("\n", 1);
                }
        }
        va_end(aq);
@@ -208,21 +215,21 @@ cc_log_argv(const char *prefix, char **argv)
                        warn_log_fail();
                }
        }
-       if (logbuffer) {
-               append_log(prefix, strlen(prefix));
+       if (debug_log_buffer) {
+               append_to_debug_log(prefix, strlen(prefix));
                char *s = format_command(argv);
-               append_log(s, strlen(s));
+               append_to_debug_log(s, strlen(s));
                free(s);
        }
 }
 
 // Copy the current log memory buffer to an output file.
 void
-cc_dump_log_buffer(const char *path)
+cc_dump_debug_log_buffer(const char *path)
 {
        FILE *file = fopen(path, "w");
        if (file) {
-               (void) fwrite(logbuffer, 1, logsize, file);
+               (void) fwrite(debug_log_buffer, 1, debug_log_size, file);
                fclose(file);
        } else {
                cc_log("Failed to open %s: %s", path, strerror(errno));