[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] static const char *str -> static const char str[]



Make all the static constant strings as char arrays, so they can be
fully stored in read-only memory.
---
 align/scan.c                            | 2 +-
 builder/index-validate.c                | 2 +-
 cat/cat.c                               | 2 +-
 cat/filesystems.c                       | 2 +-
 cat/log.c                               | 2 +-
 cat/ls.c                                | 2 +-
 daemon/guestfsd.c                       | 2 +-
 df/main.c                               | 2 +-
 diff/diff.c                             | 2 +-
 edit/edit.c                             | 2 +-
 fish/config.c                           | 4 ++--
 fish/fish.c                             | 2 +-
 format/format.c                         | 2 +-
 fuse/guestmount.c                       | 2 +-
 fuse/guestunmount.c                     | 2 +-
 generator/daemon.ml                     | 2 +-
 generator/fish.ml                       | 2 +-
 inspector/inspector.c                   | 2 +-
 make-fs/make-fs.c                       | 2 +-
 p2v/main.c                              | 2 +-
 rescue/rescue.c                         | 2 +-
 src/appliance.c                         | 4 ++--
 test-tool/test-tool.c                   | 2 +-
 utils/boot-analysis/boot-analysis.c     | 2 +-
 utils/boot-benchmark/boot-benchmark.c   | 2 +-
 utils/qemu-boot/qemu-boot.c             | 2 +-
 utils/qemu-speed-test/qemu-speed-test.c | 2 +-
 27 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/align/scan.c b/align/scan.c
index e7327ea..9575eda 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -107,7 +107,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:P:qvVx";
+  static const char options[] = "a:c:d:P:qvVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "connect", 1, 0, 'c' },
diff --git a/builder/index-validate.c b/builder/index-validate.c
index 6a87d7a..967c2d3 100644
--- a/builder/index-validate.c
+++ b/builder/index-validate.c
@@ -48,7 +48,7 @@ int
 main (int argc, char *argv[])
 {
   enum { HELP_OPTION = CHAR_MAX + 1 };
-  static const char *options = "V";
+  static const char options[] = "V";
   static const struct option long_options[] = {
     { "help", 0, 0, HELP_OPTION },
     { "compat-1.24.0", 0, 0, 0 },
diff --git a/cat/cat.c b/cat/cat.c
index 4d671ca..9039f7f 100644
--- a/cat/cat.c
+++ b/cat/cat.c
@@ -88,7 +88,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:m:vVx";
+  static const char options[] = "a:c:d:m:vVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "connect", 1, 0, 'c' },
diff --git a/cat/filesystems.c b/cat/filesystems.c
index cfdac86..ab24f2d 100644
--- a/cat/filesystems.c
+++ b/cat/filesystems.c
@@ -137,7 +137,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:hlvVx";
+  static const char options[] = "a:c:d:hlvVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "all", 0, 0, 0 },
diff --git a/cat/log.c b/cat/log.c
index 6632f5a..bacd8b6 100644
--- a/cat/log.c
+++ b/cat/log.c
@@ -95,7 +95,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:vVx";
+  static const char options[] = "a:c:d:vVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "connect", 1, 0, 'c' },
diff --git a/cat/ls.c b/cat/ls.c
index f990737..59cb914 100644
--- a/cat/ls.c
+++ b/cat/ls.c
@@ -132,7 +132,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:hlm:RvVx";
+  static const char options[] = "a:c:d:hlm:RvVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "checksum", 2, 0, 0 },
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 15ec6ef..03d8f0a 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -141,7 +141,7 @@ usage (void)
 int
 main (int argc, char *argv[])
 {
-  static const char *options = "c:lnrtv?";
+  static const char options[] = "c:lnrtv?";
   static const struct option long_options[] = {
     { "help", 0, 0, '?' },
     { "channel", 1, 0, 'c' },
diff --git a/df/main.c b/df/main.c
index 23cdaee..d266cec 100644
--- a/df/main.c
+++ b/df/main.c
@@ -103,7 +103,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:hiP:vVx";
+  static const char options[] = "a:c:d:hiP:vVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "connect", 1, 0, 'c' },
diff --git a/diff/diff.c b/diff/diff.c
index 7469d65..72f197f 100644
--- a/diff/diff.c
+++ b/diff/diff.c
@@ -144,7 +144,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:A:c:d:D:hvVx";
+  static const char options[] = "a:A:c:d:D:hvVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "all", 0, 0, 0 },
diff --git a/edit/edit.c b/edit/edit.c
index eb9dfbd..8a0c00c 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -103,7 +103,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:b:c:d:e:m:vVx";
+  static const char options[] = "a:b:c:d:e:m:vVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "backup", 1, 0, 'b' },
diff --git a/fish/config.c b/fish/config.c
index 0c3471a..8f10ad4 100644
--- a/fish/config.c
+++ b/fish/config.c
@@ -45,8 +45,8 @@
 #ifdef HAVE_LIBCONFIG
 
 #define GLOBAL_CONFIG_FILENAME "libguestfs-tools.conf"
-static const char *home_filename = /* $HOME/ */ ".libguestfs-tools.rc";
-static const char *etc_filename = "/etc/" GLOBAL_CONFIG_FILENAME;
+static const char home_filename[] = /* $HOME/ */ ".libguestfs-tools.rc";
+static const char etc_filename[] = "/etc/" GLOBAL_CONFIG_FILENAME;
 
 static void
 read_config_from_file (const char *filename)
diff --git a/fish/fish.c b/fish/fish.c
index d2cf359..2ce2039 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -183,7 +183,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:Df:h::im:nN:rvVwx";
+  static const char options[] = "a:c:d:Df:h::im:nN:rvVwx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "cmd-help", 2, 0, 'h' },
diff --git a/format/format.c b/format/format.c
index 2dbaa4d..5933aeb 100644
--- a/format/format.c
+++ b/format/format.c
@@ -104,7 +104,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:vVx";
+  static const char options[] = "a:vVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "filesystem", 1, 0, 0 },
diff --git a/fuse/guestmount.c b/fuse/guestmount.c
index a5a5d37..3308058 100644
--- a/fuse/guestmount.c
+++ b/fuse/guestmount.c
@@ -149,7 +149,7 @@ main (int argc, char *argv[])
   /* The command line arguments are broadly compatible with (a subset
    * of) guestfish.  Thus we have to deal mainly with -a, -m and --ro.
    */
-  static const char *options = "a:c:d:im:no:rvVwx";
+  static const char options[] = "a:c:d:im:no:rvVwx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "connect", 1, 0, 'c' },
diff --git a/fuse/guestunmount.c b/fuse/guestunmount.c
index ba753ef..c686f40 100644
--- a/fuse/guestunmount.c
+++ b/fuse/guestunmount.c
@@ -76,7 +76,7 @@ main (int argc, char *argv[])
 {
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "qvV";
+  static const char options[] = "qvV";
   static const struct option long_options[] = {
     { "fd", 1, 0, 0 },
     { "help", 0, 0, HELP_OPTION },
diff --git a/generator/daemon.ml b/generator/daemon.ml
index cb8b6ba..31ca764 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -535,7 +535,7 @@ cleanup_free_mountable (mountable_t *mountable)
   List.iter (
     function
     | typ, cols ->
-        pr "static const char *lvm_%s_cols = \"%s\";\n"
+        pr "static const char lvm_%s_cols[] = \"%s\";\n"
           typ (String.concat "," (List.map fst cols));
         pr "\n";
 
diff --git a/generator/fish.ml b/generator/fish.ml
index 980f55f..cc869d3 100644
--- a/generator/fish.ml
+++ b/generator/fish.ml
@@ -107,7 +107,7 @@ let generate_fish_cmds () =
   pr "#include \"cmds-gperf.h\"\n";
   pr "\n";
   pr "/* Valid suffixes allowed for numbers.  See Gnulib xstrtol function. */\n";
-  pr "static const char *xstrtol_suffixes = \"0kKMGTPEZY\";\n";
+  pr "static const char xstrtol_suffixes[] = \"0kKMGTPEZY\";\n";
   pr "\n";
   pr "/* Return these errors from run_* functions. */\n";
   pr "#define RUN_ERROR -1\n";
diff --git a/inspector/inspector.c b/inspector/inspector.c
index d8e455e..4c027df 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -105,7 +105,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:vVx";
+  static const char options[] = "a:c:d:vVx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "connect", 1, 0, 'c' },
diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
index 8ece991..2f91370 100644
--- a/make-fs/make-fs.c
+++ b/make-fs/make-fs.c
@@ -51,7 +51,7 @@ static const char *format = "raw", *label = NULL,
   *partition = NULL, *size_str = NULL, *type = "ext2";
 
 enum { HELP_OPTION = CHAR_MAX + 1 };
-static const char *options = "F:s:t:Vvx";
+static const char options[] = "F:s:t:Vvx";
 static const struct option long_options[] = {
   { "debug", 0, 0, 'v' }, /* for compat with Perl tool */
   { "floppy", 0, 0, 0 },
diff --git a/p2v/main.c b/p2v/main.c
index 35f0b59..6a63df4 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -55,7 +55,7 @@ static void find_all_interfaces (void);
 static int cpuinfo_flags (void);
 
 enum { HELP_OPTION = CHAR_MAX + 1 };
-static const char *options = "Vv";
+static const char options[] = "Vv";
 static const struct option long_options[] = {
   { "help", 0, 0, HELP_OPTION },
   { "cmdline", 1, 0, 0 },
diff --git a/rescue/rescue.c b/rescue/rescue.c
index 8012112..37b82f6 100644
--- a/rescue/rescue.c
+++ b/rescue/rescue.c
@@ -98,7 +98,7 @@ main (int argc, char *argv[])
 
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
-  static const char *options = "a:c:d:m:rvVwx";
+  static const char options[] = "a:c:d:m:rvVwx";
   static const struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "append", 1, 0, 0 },
diff --git a/src/appliance.c b/src/appliance.c
index d293c2b..5748af5 100644
--- a/src/appliance.c
+++ b/src/appliance.c
@@ -38,8 +38,8 @@
 #include "guestfs-internal.h"
 
 /* Old-style appliance is going to be obsoleted. */
-static const char *kernel_name = "vmlinuz." host_cpu;
-static const char *initrd_name = "initramfs." host_cpu ".img";
+static const char kernel_name[] = "vmlinuz." host_cpu;
+static const char initrd_name[] = "initramfs." host_cpu ".img";
 
 static int build_appliance (guestfs_h *g, char **kernel, char **initrd, char **appliance);
 static int find_path (guestfs_h *g, int (*pred) (guestfs_h *g, const char *pelem, void *data), void *data, char **pelem);
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
index ad1601c..a5297ba 100644
--- a/test-tool/test-tool.c
+++ b/test-tool/test-tool.c
@@ -78,7 +78,7 @@ main (int argc, char *argv[])
   bindtextdomain (PACKAGE, LOCALEBASEDIR);
   textdomain (PACKAGE);
 
-  static const char *options = "t:V?";
+  static const char options[] = "t:V?";
   static const struct option long_options[] = {
     { "help", 0, 0, '?' },
     { "qemu", 1, 0, 0 },
diff --git a/utils/boot-analysis/boot-analysis.c b/utils/boot-analysis/boot-analysis.c
index 1b491c4..2b042d9 100644
--- a/utils/boot-analysis/boot-analysis.c
+++ b/utils/boot-analysis/boot-analysis.c
@@ -118,7 +118,7 @@ int
 main (int argc, char *argv[])
 {
   enum { HELP_OPTION = CHAR_MAX + 1 };
-  static const char *options = "m:v";
+  static const char options[] = "m:v";
   static const struct option long_options[] = {
     { "help", 0, 0, HELP_OPTION },
     { "append", 1, 0, 0 },
diff --git a/utils/boot-benchmark/boot-benchmark.c b/utils/boot-benchmark/boot-benchmark.c
index 05cab50..fb946de 100644
--- a/utils/boot-benchmark/boot-benchmark.c
+++ b/utils/boot-benchmark/boot-benchmark.c
@@ -79,7 +79,7 @@ int
 main (int argc, char *argv[])
 {
   enum { HELP_OPTION = CHAR_MAX + 1 };
-  static const char *options = "m:";
+  static const char options[] = "m:";
   static const struct option long_options[] = {
     { "help", 0, 0, HELP_OPTION },
     { "append", 1, 0, 0 },
diff --git a/utils/qemu-boot/qemu-boot.c b/utils/qemu-boot/qemu-boot.c
index 61d2ff0..2703014 100644
--- a/utils/qemu-boot/qemu-boot.c
+++ b/utils/qemu-boot/qemu-boot.c
@@ -93,7 +93,7 @@ int
 main (int argc, char *argv[])
 {
   enum { HELP_OPTION = CHAR_MAX + 1 };
-  static const char *options = "in:P:vx";
+  static const char options[] = "in:P:vx";
   static const struct option long_options[] = {
     { "help", 0, 0, HELP_OPTION },
     { "ignore", 0, 0, 'i' },
diff --git a/utils/qemu-speed-test/qemu-speed-test.c b/utils/qemu-speed-test/qemu-speed-test.c
index 375a9a4..f26d71c 100644
--- a/utils/qemu-speed-test/qemu-speed-test.c
+++ b/utils/qemu-speed-test/qemu-speed-test.c
@@ -92,7 +92,7 @@ int
 main (int argc, char *argv[])
 {
   enum { HELP_OPTION = CHAR_MAX + 1 };
-  static const char *options = "t:";
+  static const char options[] = "t:";
   static const struct option long_options[] = {
     { "help", 0, 0, HELP_OPTION },
     { "time", 1, 0, 't' },
-- 
2.7.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]