]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
make lots of global variables `const`
authorMax Kellermann <max.kellermann@gmail.com>
Tue, 25 Mar 2025 14:13:43 +0000 (15:13 +0100)
committerAndrew Tridgell <andrew@tridgell.net>
Sat, 23 Aug 2025 07:31:40 +0000 (17:31 +1000)
This way, they can live in `.rodata` and the compiler is allowed to do
certain optimizations.

batch.c
daemon-parm.awk
flist.c
io.c
lib/md5.c
loadparm.c
main.c
options.c
tls.c
wildtest.c

diff --git a/batch.c b/batch.c
index accc4c6e677b639fe870084d914a68a61684a4a1..878b6dd1d156e4d7444d942f89892c4be37b0d70 100644 (file)
--- a/batch.c
+++ b/batch.c
@@ -75,7 +75,7 @@ static int *flag_ptr[] = {
        NULL
 };
 
-static char *flag_name[] = {
+static const char *const flag_name[] = {
        "--recurse (-r)",
        "--owner (-o)",
        "--group (-g)",
index ad52e9d9682603a135e75bca62527993a55735fb..f803e43c8d304afa24950a47fd1a4984f50c97b6 100755 (executable)
@@ -6,7 +6,7 @@
 BEGIN {
     heading = "/* DO NOT EDIT THIS FILE!  It is auto-generated from a list of values in " ARGV[1] "! */\n\n"
     sect = psect = defines = accessors = prior_ptype = ""
-    parms = "\nstatic struct parm_struct parm_table[] = {"
+    parms = "\nstatic const struct parm_struct parm_table[] = {"
     comment_fmt = "\n/********** %s **********/\n"
     tdstruct = "typedef struct {"
 }
diff --git a/flist.c b/flist.c
index 17832533ed2a9a7e83ca9c2432146e92cea5bf8f..7bf3030e5a91e8f41fb40eed79aebc089b0cdfa9 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -3167,8 +3167,8 @@ static void output_flist(struct file_list *flist)
                } else
                        *uidbuf = '\0';
                if (gid_ndx) {
-                       static char parens[] = "(\0)\0\0\0";
-                       char *pp = parens + (file->flags & FLAG_SKIP_GROUP ? 0 : 3);
+                       static const char parens[] = "(\0)\0\0\0";
+                       const char *pp = parens + (file->flags & FLAG_SKIP_GROUP ? 0 : 3);
                        snprintf(gidbuf, sizeof gidbuf, " gid=%s%u%s",
                                 pp, F_GROUP(file), pp + 2);
                } else
diff --git a/io.c b/io.c
index bb60eecaba4d922e276ba5eb096e535c53e73e35..436bed45ee42891d783b139eb3fd05fc11fabfcb 100644 (file)
--- a/io.c
+++ b/io.c
@@ -117,7 +117,7 @@ static int active_filecnt = 0;
 static OFF_T active_bytecnt = 0;
 static int first_message = 1;
 
-static char int_byte_extra[64] = {
+static const char int_byte_extra[64] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* (00 - 3F)/4 */
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* (40 - 7F)/4 */
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* (80 - BF)/4 */
@@ -1158,7 +1158,7 @@ void set_io_timeout(int secs)
 
 static void check_for_d_option_error(const char *msg)
 {
-       static char rsync263_opts[] = "BCDHIKLPRSTWabceghlnopqrtuvxz";
+       static const char rsync263_opts[] = "BCDHIKLPRSTWabceghlnopqrtuvxz";
        char *colon;
        int saw_d = 0;
 
index f36c5ba7e6d9a2305562c310b784917595ac5ae1..1506d0742e9eb11b849ca2b8e66e1c981b75f0b9 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -197,7 +197,7 @@ void md5_update(md_context *ctx, const uchar *input, uint32 length)
                memcpy(ctx->buffer + left, input, length);
 }
 
-static uchar md5_padding[CSUM_CHUNK] = { 0x80 };
+static const uchar md5_padding[CSUM_CHUNK] = { 0x80 };
 
 void md5_result(md_context *ctx, uchar digest[MD5_DIGEST_LEN])
 {
index 3906bc0f419faea3c4d4d666ce77fa560b5c3a60..f557484c4e6a949d9c0a5db8cbb7f21ee62828a8 100644 (file)
@@ -65,7 +65,7 @@ typedef enum {
 
 struct enum_list {
        int value;
-       char *name;
+       const char *name;
 };
 
 struct parm_struct {
@@ -73,7 +73,7 @@ struct parm_struct {
        parm_type type;
        parm_class class;
        void *ptr;
-       struct enum_list *enum_list;
+       const struct enum_list *enum_list;
        unsigned flags;
 };
 
@@ -95,7 +95,7 @@ static item_list section_list = EMPTY_ITEM_LIST;
 static int iSectionIndex = -1;
 static BOOL bInGlobalSection = True;
 
-static struct enum_list enum_syslog_facility[] = {
+static const struct enum_list enum_syslog_facility[] = {
 #ifdef LOG_AUTH
        { LOG_AUTH, "auth" },
 #endif
diff --git a/main.c b/main.c
index 4f070acccc0f14951a9f9d66115aa7c8d1e25069..9d764e16b6eb4c583dfc74de26994305da80b35a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -386,7 +386,7 @@ static void handle_stats(int f)
 
 static void output_itemized_counts(const char *prefix, int *counts)
 {
-       static char *labels[] = { "reg", "dir", "link", "dev", "special" };
+       static char *const labels[] = { "reg", "dir", "link", "dev", "special" };
        char buf[1024], *pre = " (";
        int j, len = 0;
        int total = counts[0];
index 40f7bd18c4a6ce5d29e5664e7df844c87faaf28e..55aef66c943de78c9233d71cb603caddf554a9e0 100644 (file)
--- a/options.c
+++ b/options.c
@@ -226,7 +226,7 @@ char *iconv_opt =
 
 struct chmod_mode_struct *chmod_modes = NULL;
 
-static const char *debug_verbosity[] = {
+static const char *const debug_verbosity[] = {
        /*0*/ NULL,
        /*1*/ NULL,
        /*2*/ "BIND,CMD,CONNECT,DEL,DELTASUM,DUP,FILTER,FLIST,ICONV",
@@ -237,7 +237,7 @@ static const char *debug_verbosity[] = {
 
 #define MAX_VERBOSITY ((int)(sizeof debug_verbosity / sizeof debug_verbosity[0]) - 1)
 
-static const char *info_verbosity[1+MAX_VERBOSITY] = {
+static const char *const info_verbosity[1+MAX_VERBOSITY] = {
        /*0*/ "NONREG",
        /*1*/ "COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE",
        /*2*/ "BACKUP,MISC2,MOUNT,NAME2,REMOVE,SKIP",
@@ -475,7 +475,7 @@ static void parse_output_words(struct output_struct *words, short *levels, const
 static void output_item_help(struct output_struct *words)
 {
        short *levels = words == info_words ? info_levels : debug_levels;
-       const char **verbosity = words == info_words ? info_verbosity : debug_verbosity;
+       const char *const*verbosity = words == info_words ? info_verbosity : debug_verbosity;
        char buf[128], *opt, *fmt = "%-10s %s\n";
        int j;
 
@@ -847,7 +847,7 @@ static struct poptOption long_options[] = {
   {0,0,0,0, 0, 0, 0}
 };
 
-static struct poptOption long_daemon_options[] = {
+static const struct poptOption long_daemon_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
   {"address",          0,  POPT_ARG_STRING, &bind_address, 0, 0, 0 },
   {"bwlimit",          0,  POPT_ARG_INT,    &daemon_bwlimit, 0, 0, 0 },
diff --git a/tls.c b/tls.c
index 858f8f10c83fdafbf96e2b67756fbbca436e18fe..e311240aff3850e4724608df09736079687a8c4a 100644 (file)
--- a/tls.c
+++ b/tls.c
@@ -230,7 +230,7 @@ static void list_file(const char *fname)
               mtimebuf, atimebuf, crtimebuf, fname, linkbuf);
 }
 
-static struct poptOption long_options[] = {
+static const struct poptOption long_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
   {"atimes",          'U', POPT_ARG_NONE,   &display_atimes, 0, 0, 0},
 #ifdef SUPPORT_CRTIMES
index 482cdf1703c4b25c1f3a748391738cef2f96af38..381ac59d4d80d98cdd826aa242451884f65548e0 100644 (file)
@@ -42,7 +42,7 @@ int empties_mod = 0;
 int empty_at_start = 0;
 int empty_at_end = 0;
 
-static struct poptOption long_options[] = {
+static const struct poptOption long_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
   {"iterations",     'i', POPT_ARG_NONE,   &output_iterations, 0, 0, 0},
   {"empties",        'e', POPT_ARG_STRING, 0, 'e', 0, 0},