]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
constify variables more 891/head
authorMike Frysinger <vapier@gentoo.org>
Thu, 23 Mar 2017 06:26:52 +0000 (02:26 -0400)
committerMike Frysinger <vapier@gentoo.org>
Thu, 23 Mar 2017 17:28:26 +0000 (13:28 -0400)
A bunch of constant variables/tables are missing const markings.
Adding them allows moving more data to the read only sections, and
ends up shrinking writable data a bit by 1k on x86_64/Linux.  Not
much, but still nice.

16 files changed:
libarchive/archive_entry.c
libarchive/archive_pack_dev.c
libarchive/archive_read_support_format_cab.c
libarchive/archive_read_support_format_lha.c
libarchive/archive_read_support_format_mtree.c
libarchive/archive_read_support_format_zip.c
libarchive/archive_string_sprintf.c
libarchive/archive_util.c
libarchive/archive_write_add_filter.c
libarchive/archive_write_add_filter_by_name.c
libarchive/archive_write_add_filter_lz4.c
libarchive/archive_write_add_filter_program.c
libarchive/archive_write_set_format.c
libarchive/archive_write_set_format_by_name.c
libarchive/archive_write_set_format_filter_by_ext.c
libarchive/archive_write_set_format_warc.c

index e268194143dd20036efb85e5de96970e74bd4b3e..9eaa8a434c5b3d263ff0f94393ca2fbb9b58836e 100644 (file)
@@ -1638,7 +1638,7 @@ _archive_entry_acl_text_l(struct archive_entry *entry, int flags,
  * SUCH DAMAGE.
  */
 
-static struct flag {
+static const struct flag {
        const char      *name;
        const wchar_t   *wname;
        unsigned long    set;
@@ -1840,7 +1840,7 @@ ae_fflagstostr(unsigned long bitset, unsigned long bitclear)
        char *string, *dp;
        const char *sp;
        unsigned long bits;
-       struct flag *flag;
+       const struct flag *flag;
        size_t  length;
 
        bits = bitset | bitclear;
@@ -1892,7 +1892,7 @@ static const char *
 ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp)
 {
        const char *start, *end;
-       struct flag *flag;
+       const struct flag *flag;
        unsigned long set, clear;
        const char *failed;
 
@@ -1960,7 +1960,7 @@ static const wchar_t *
 ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp)
 {
        const wchar_t *start, *end;
-       struct flag *flag;
+       const struct flag *flag;
        unsigned long set, clear;
        const wchar_t *failed;
 
index 6b7b4726d6eab5246f54240186a651bd449f0d49..098881b678cd50517a7db2da2338c68394085d7f 100644 (file)
@@ -280,7 +280,7 @@ pack_bsdos(int n, unsigned long numbers[], const char **error)
 
                /* list of formats and pack functions */
                /* this list must be sorted lexically */
-static struct format {
+static const struct format {
        const char      *name;
        pack_t          *pack;
 } formats[] = {
index e2f8c6b70aebffe90159c578a0de00fa7641b5de..2cf0d453abdc2cc34f70a3afd3ce1de98a928256 100644 (file)
@@ -187,7 +187,7 @@ struct lzx_stream {
 #define CFDATA_cbData          4
 #define CFDATA_cbUncomp                6
 
-static const char *compression_name[] = {
+static const char * const compression_name[] = {
        "NONE",
        "MSZIP",
        "Quantum",
index d77a7c2e4766b15f868f4eb1abc095edaed530e8..b8ef4ae10eceda9fadadc4f664010407df6a76b9 100644 (file)
@@ -2477,7 +2477,7 @@ lzh_huffman_free(struct huffman *hf)
        free(hf->tree);
 }
 
-static char bitlen_tbl[0x400] = {
+static const char bitlen_tbl[0x400] = {
         7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
         7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
         7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
index 00d3250707a6e70c7b221df0078da175aae50dfb..1590187febe597daa09596f45c83e0f6187d02a2 100644 (file)
@@ -399,41 +399,41 @@ bid_keycmp(const char *p, const char *key, ssize_t len)
 static int
 bid_keyword(const char *p,  ssize_t len)
 {
-       static const char *keys_c[] = {
+       static const char * const keys_c[] = {
                "content", "contents", "cksum", NULL
        };
-       static const char *keys_df[] = {
+       static const char * const keys_df[] = {
                "device", "flags", NULL
        };
-       static const char *keys_g[] = {
+       static const char * const keys_g[] = {
                "gid", "gname", NULL
        };
-       static const char *keys_il[] = {
+       static const char * const keys_il[] = {
                "ignore", "inode", "link", NULL
        };
-       static const char *keys_m[] = {
+       static const char * const keys_m[] = {
                "md5", "md5digest", "mode", NULL
        };
-       static const char *keys_no[] = {
+       static const char * const keys_no[] = {
                "nlink", "nochange", "optional", NULL
        };
-       static const char *keys_r[] = {
+       static const char * const keys_r[] = {
                "resdevice", "rmd160", "rmd160digest", NULL
        };
-       static const char *keys_s[] = {
+       static const char * const keys_s[] = {
                "sha1", "sha1digest",
                "sha256", "sha256digest",
                "sha384", "sha384digest",
                "sha512", "sha512digest",
                "size", NULL
        };
-       static const char *keys_t[] = {
+       static const char * const keys_t[] = {
                "tags", "time", "type", NULL
        };
-       static const char *keys_u[] = {
+       static const char * const keys_u[] = {
                "uid", "uname", NULL
        };
-       const char **keys;
+       const char * const *keys;
        int i;
 
        switch (*p) {
index e62f99c8b9e83dcaeaca22473eb542764ea6a1f9..4c4f6fad47983d71462a3c924b723c68eab1bf59 100644 (file)
@@ -347,7 +347,7 @@ fake_crc32(unsigned long crc, const void *buff, size_t len)
        return 0;
 }
 
-static struct {
+static const struct {
        int id;
        const char * name;
 } compression_methods[] = {
index 964ea2bea1f3362e23af55ab3beb7d84fd6bc859..969a5603a49e4ad8f7e7268368c051b7470609c4 100644 (file)
@@ -53,7 +53,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string_sprintf.c 189435 2009-03-
 static void
 append_uint(struct archive_string *as, uintmax_t d, unsigned base)
 {
-       static const char *digits = "0123456789abcdef";
+       static const char digits[] = "0123456789abcdef";
        if (d >= base)
                append_uint(as, d/base, base);
        archive_strappend_char(as, digits[d % base]);
index a751868f4542ac474915146bc37d27a56799024f..bac9ba1cab1a82a9ab85cd4e5852ff9936b1d494 100644 (file)
@@ -193,7 +193,7 @@ archive_copy_error(struct archive *dest, struct archive *src)
 void
 __archive_errx(int retvalue, const char *msg)
 {
-       static const char *msg1 = "Fatal Internal Error in libarchive: ";
+       static const char msg1[] = "Fatal Internal Error in libarchive: ";
        size_t s;
 
        s = write(2, msg1, strlen(msg1));
@@ -221,8 +221,8 @@ __archive_errx(int retvalue, const char *msg)
 int
 __archive_mktemp(const char *tmpdir)
 {
-       static const wchar_t *prefix = L"libarchive_";
-       static const wchar_t *suffix = L"XXXXXXXXXX";
+       static const wchar_t prefix[] = L"libarchive_";
+       static const wchar_t suffix[] = L"XXXXXXXXXX";
        static const wchar_t num[] = {
                L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
                L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F',
index ad5dc832fdaed5e3d3daedbf2e6c6e32359f9640..08f518adec4bfae08d3fb76e36d9f9b4966367a2 100644 (file)
@@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$");
 #include "archive_private.h"
 
 /* A table that maps filter codes to functions. */
-static
+static const
 struct { int code; int (*setter)(struct archive *); } codes[] =
 {
        { ARCHIVE_FILTER_NONE,          archive_write_add_filter_none },
index eac4011cb2eec8fc4f23e4cfb10e82ae42677483..85a8d47534150a6bfb1d38d21e8c62361f796fbf 100644 (file)
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
 #include "archive_private.h"
 
 /* A table that maps names to functions. */
-static
+static const
 struct { const char *name; int (*setter)(struct archive *); } names[] =
 {
        { "b64encode",          archive_write_add_filter_b64encode },
index e6551859c0609cd46dc109f339a9d6894c0cf50e..15fd494a41973d705f7d6967fa32f88a2175ac16 100644 (file)
@@ -225,7 +225,7 @@ archive_filter_lz4_open(struct archive_write_filter *f)
        struct private_data *data = (struct private_data *)f->data;
        int ret;
        size_t required_size;
-       static size_t bkmap[] = { 64 * 1024, 256 * 1024, 1 * 1024 * 1024,
+       static size_t const bkmap[] = { 64 * 1024, 256 * 1024, 1 * 1024 * 1024,
                           4 * 1024 * 1024 };
        size_t pre_block_size;
 
index 55b5e8ecdf824ff9436289551db291e4c1f86b76..660f693f29d0f67b19e02d460e994bafe5e47f4a 100644 (file)
@@ -92,7 +92,7 @@ archive_write_add_filter_program(struct archive *_a, const char *cmd)
 {
        struct archive_write_filter *f = __archive_write_allocate_filter(_a);
        struct private_data *data;
-       static const char *prefix = "Program: ";
+       static const char prefix[] = "Program: ";
 
        archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
            ARCHIVE_STATE_NEW, "archive_write_add_filter_program");
index 744302d067756ce272bbd7739e39cd759be52bf8..0f706231add1ef8fb735efc586240ccbc333bcd7 100644 (file)
@@ -38,7 +38,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format.c 201168 2009-1
 #include "archive_private.h"
 
 /* A table that maps format codes to functions. */
-static
+static const
 struct { int code; int (*setter)(struct archive *); } codes[] =
 {
        { ARCHIVE_FORMAT_7ZIP,          archive_write_set_format_7zip },
index a2ce7c6cde4e8002e9b1d1b606f087794ae1829b..86e8621ef7b5653a08201a01e0e6dce70d5f5764 100644 (file)
@@ -41,7 +41,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 20116
 #include "archive_private.h"
 
 /* A table that maps names to functions. */
-static
+static const
 struct { const char *name; int (*setter)(struct archive *); } names[] =
 {
        { "7zip",       archive_write_set_format_7zip },
index adec9b265643d9e4431b4393d6a8a49783837c80..9fe21e4542a0476a6f285270ab22c1ac1bc6afd6 100644 (file)
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 20116
 #include "archive_private.h"
 
 /* A table that maps names to functions. */
-static
+static const
 struct { const char *name; int (*format)(struct archive *); int (*filter)(struct archive *);  } names[] =
 {
        { ".7z",        archive_write_set_format_7zip,            archive_write_add_filter_none},
index 8b6daf942b8eb0be03837f944b85766a2c4ad20c..edad072cf77d2438764e7ba187b490ec4ff95cc0 100644 (file)
@@ -354,7 +354,7 @@ static ssize_t
 _popul_ehdr(struct archive_string *tgt, size_t tsz, warc_essential_hdr_t hdr)
 {
        static const char _ver[] = "WARC/1.0\r\n";
-       static const char *_typ[LAST_WT] = {
+       static const char * const _typ[LAST_WT] = {
                NULL, "warcinfo", "metadata", "resource", NULL
        };
        char std_uuid[48U];