]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve const-ness of parameters related to argv
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Apr 2020 17:23:45 +0000 (19:23 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Apr 2020 18:58:19 +0000 (20:58 +0200)
src/ccache.cpp
src/execute.cpp
src/execute.hpp
src/logging.cpp
src/logging.hpp
src/main.cpp
src/system.hpp

index 5560e1c43c402a9ec529a268fe7dc9e8f23878bf..12127380d726dd1bfa95d725122f19af73340f29 100644 (file)
@@ -2073,7 +2073,7 @@ from_cache(Context& ctx,
 // 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(const Context& ctx, char** argv)
+find_compiler(const Context& ctx, const char* const* argv)
 {
   // We might be being invoked like "ccache gcc -c foo.c".
   std::string base(Util::base_name(argv[0]));
@@ -3392,7 +3392,7 @@ set_up_config(Config& config)
 
 // Initialize ccache, must be called once before anything else is run.
 static Context&
-initialize(int argc, char* argv[])
+initialize(int argc, const char* const* argv)
 {
   // This object is placed onto the heap so it is available in exit functions
   // which run after main(). It is cleaned up by the last exit function.
@@ -3468,12 +3468,12 @@ configuration_printer(const std::string& key,
   fmt::print("({}) {} = {}\n", origin, key, value);
 }
 
-static int cache_compilation(int argc, char* argv[]);
-static enum stats do_cache_compilation(Context& ctx, char* argv[]);
+static int cache_compilation(int argc, const char* const* argv);
+static enum stats do_cache_compilation(Context& ctx, const char* const* argv);
 
 // The entry point when invoked to cache a compilation.
 static int
-cache_compilation(int argc, char* argv[])
+cache_compilation(int argc, const char* const* argv)
 {
 #ifndef _WIN32
   set_up_signal_handlers();
@@ -3519,7 +3519,7 @@ cache_compilation(int argc, char* argv[])
 }
 
 static enum stats
-do_cache_compilation(Context& ctx, char* argv[])
+do_cache_compilation(Context& ctx, const char* const* argv)
 {
   if (ctx.actual_cwd.empty()) {
     cc_log("Unable to determine current working directory: %s",
@@ -3753,7 +3753,7 @@ do_cache_compilation(Context& ctx, char* argv[])
 
 // The main program when not doing a compile.
 static int
-handle_main_options(int argc, char* argv[])
+handle_main_options(int argc, const char* const* argv)
 {
   enum longopts {
     DUMP_MANIFEST,
@@ -3785,7 +3785,11 @@ handle_main_options(int argc, char* argv[])
   (void)ctx;
 
   int c;
-  while ((c = getopt_long(argc, argv, "cCk:hF:M:po:sVxX:z", options, nullptr))
+  while ((c = getopt_long(argc,
+                          const_cast<char* const*>(argv),
+                          "cCk:hF:M:po:sVxX:z",
+                          options,
+                          nullptr))
          != -1) {
     switch (c) {
     case DUMP_MANIFEST:
@@ -3942,10 +3946,10 @@ handle_main_options(int argc, char* argv[])
   return 0;
 }
 
-int ccache_main(int argc, char* argv[]);
+int ccache_main(int argc, const char* const* argv);
 
 int
-ccache_main(int argc, char* argv[])
+ccache_main(int argc, const char* const* argv)
 {
   try {
     // Check if we are being invoked as "ccache".
index 67e1d9504ebc52b161b46ab224775ef36a5bd0b5..bbd3a6e0981b94272a703642fb6ee293043f6670 100644 (file)
@@ -30,7 +30,7 @@ using nonstd::string_view;
 
 #ifdef _WIN32
 int
-execute(char** argv, int fd_out, int fd_err, pid_t* /*pid*/)
+execute(const char* const* argv, int fd_out, int fd_err, pid_t* /*pid*/)
 {
   return win32execute(argv[0], argv, 1, fd_out, fd_err);
 }
@@ -38,11 +38,11 @@ execute(char** argv, int fd_out, int fd_err, pid_t* /*pid*/)
 // 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, int* length)
+win32argvtos(const char* prefix, const char* const* argv, int* length)
 {
   int i = 0;
   int k = 0;
-  char* arg = prefix ? prefix : argv[i++];
+  const char* arg = prefix ? prefix : argv[i++];
   do {
     int bs = 0;
     for (int j = 0; arg[j]; j++) {
@@ -103,7 +103,7 @@ win32argvtos(char* prefix, char** argv, int* length)
 }
 
 char*
-win32getshell(char* path)
+win32getshell(const char* path)
 {
   char* path_env;
   char* sh = NULL;
@@ -144,8 +144,11 @@ add_exe_ext_if_no_to_fullpath(char* full_path_win_ext,
 }
 
 int
-win32execute(
-  char* path, char** argv, int doreturn, int fd_stdout, int fd_stderr)
+win32execute(const char* path,
+             const char* const* argv,
+             int doreturn,
+             int fd_stdout,
+             int fd_stderr)
 {
   PROCESS_INFORMATION pi;
   memset(&pi, 0x00, sizeof(pi));
@@ -258,7 +261,7 @@ win32execute(
 // 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)
+execute(const char* const* argv, int fd_out, int fd_err, pid_t* pid)
 {
   cc_log_argv("Executing ", argv);
 
@@ -276,7 +279,7 @@ execute(char** argv, int fd_out, int fd_err, pid_t* pid)
     close(fd_out);
     dup2(fd_err, 2);
     close(fd_err);
-    x_exit(execv(argv[0], argv));
+    x_exit(execv(argv[0], const_cast<char* const*>(argv)));
   }
 
   close(fd_out);
@@ -377,7 +380,7 @@ find_executable_in_path(const char* name,
 }
 
 void
-print_command(FILE* fp, char** argv)
+print_command(FILE* fp, const char* const* argv)
 {
   for (int i = 0; argv[i]; i++) {
     fprintf(fp, "%s%s", (i == 0) ? "" : " ", argv[i]);
index 81794d7c1c70251e546b35ea91fc35e1561813b7..803128f0e9db4401c738c1efcb178c6c438661f8 100644 (file)
 
 struct Context;
 
-int execute(char** argv, int fd_out, int fd_err, pid_t* pid);
+int execute(const char* const* argv, int fd_out, int fd_err, pid_t* pid);
 char*
 find_executable(const Context& ctx, const char* name, const char* exclude_name);
 char* find_executable_in_path(const char* name,
                               const char* exclude_name,
                               const char* path);
 
-void print_command(FILE* fp, char** argv);
+void print_command(FILE* fp, const char* const* argv);
 char* format_command(const char* const* argv);
index bac365637759766bffb17c730ab2640d2b4ab0da..9701294eeba1c89bfc1853d44952b7bf3abaf6d8 100644 (file)
@@ -214,7 +214,7 @@ cc_bulklog(const char* format, ...)
 
 // Log an executed command to the CCACHE_LOGFILE location.
 void
-cc_log_argv(const char* prefix, char** argv)
+cc_log_argv(const char* prefix, const char* const* argv)
 {
   if (!(debug_log_buffer || logfile || use_syslog)) {
     return;
index 80bddf64bfed1237001002d37c4d9cb6e9b551cd..e65a3535ea669d60236f4385cedc5427fdf45d78 100644 (file)
@@ -27,5 +27,5 @@ class Config;
 void init_log(const Config& config);
 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_log_argv(const char* prefix, const char* const* argv);
 void cc_dump_debug_log_buffer(const char* path);
index c8383a44f4a18f168aa824d05fc4a0d1662be492..9b4e5fa935bde55bb062d19cb14e63f33e8f675f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2016 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 // 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[]);
+int ccache_main(int argc, const char* const* argv);
 
 int
-main(int argc, char *argv[])
+main(int argc, char* const* argv)
 {
-       return ccache_main(argc, argv);
+  return ccache_main(argc, argv);
 }
index f22cddd7548d077406c4d484ef9cafebc0f0f368..a4106e26dcb78e7b107c794dc851456cca7ac0b3 100644 (file)
@@ -113,10 +113,13 @@ extern char** environ;
 #endif
 
 #ifdef _WIN32
-char* win32argvtos(char* prefix, char** argv, int* length);
-char* win32getshell(char* path);
-int win32execute(
-  char* path, char** argv, int doreturn, int fd_stdout, int fd_stderr);
+char* win32argvtos(const char* prefix, const char* const* argv, int* length);
+char* win32getshell(const char* path);
+int win32execute(const char* path,
+                 const char* const* argv,
+                 int doreturn,
+                 int fd_stdout,
+                 int fd_stderr);
 void add_exe_ext_if_no_to_fullpath(char* full_path_win_ext,
                                    size_t max_size,
                                    const char* ext,