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

[PATCH 06/14] tools/libs: stat: Use const whenever we point to literal strings



From: Julien Grall <jgrall@xxxxxxxxxx>

literal strings are not meant to be modified. So we should use const
char * rather than char * when we want to store a pointer to them.

Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 tools/libs/stat/xenstat_linux.c |  4 ++--
 tools/libs/stat/xenstat_qmp.c   | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index c00b26d4d898..875a0617ade8 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -66,7 +66,7 @@ static const char PROCNETDEV_HEADER[] =
 
 /* We need to get the name of the bridge interface for use with bonding 
interfaces */
 /* Use excludeName parameter to avoid adding bridges we don't care about, eg. 
virbr0 */
-static void getBridge(char *excludeName, char *result, size_t resultLen)
+static void getBridge(const char *excludeName, char *result, size_t resultLen)
 {
        struct dirent *de;
        DIR *d;
@@ -113,7 +113,7 @@ static int parseNetDevLine(char *line, char *iface, 
unsigned long long *rxBytes,
        int num = 19;
 
        /* Regular exception to parse all the information from /proc/net/dev 
line */
-       char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ 
]*)[ ]*([^ ]*)"
+       const char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ 
]*([^ ]*)[ ]*([^ ]*)"
                        "[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ 
]*)[ ]*([^ ]*)[ ]*"
                        "([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)";
 
diff --git a/tools/libs/stat/xenstat_qmp.c b/tools/libs/stat/xenstat_qmp.c
index 0c5748ba68b3..2205a041313b 100644
--- a/tools/libs/stat/xenstat_qmp.c
+++ b/tools/libs/stat/xenstat_qmp.c
@@ -38,7 +38,7 @@
 
 #include <yajl/yajl_tree.h>
 
-static unsigned char *qmp_query(int, char *);
+static unsigned char *qmp_query(int, const char *);
 
 enum query_blockstats {
     QMP_STATS_RETURN  = 0,
@@ -80,7 +80,7 @@ enum query_block {
 static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int 
qfd)
 {
        char *tmp, *file = NULL;
-       char *query_block_cmd = "{ \"execute\": \"query-block\" }";
+       const char *query_block_cmd = "{ \"execute\": \"query-block\" }";
        static const char *const qblock[] = {
                [ QMP_BLOCK_RETURN  ] = "return",
                [ QMP_BLOCK_DEVICE  ] = "device",
@@ -264,7 +264,7 @@ done:
 }
 
 /* Write a command via the QMP. Returns number of bytes written */
-static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
+static size_t qmp_write(int qfd, const char *cmd, size_t cmd_len)
 {
        size_t pos = 0;
        ssize_t res;
@@ -317,7 +317,7 @@ static int qmp_read(int qfd, unsigned char **qstats)
 }
 
 /* With the given cmd, query QMP for requested data. Returns allocated buffer 
containing data or NULL */
-static unsigned char *qmp_query(int qfd, char *cmd)
+static unsigned char *qmp_query(int qfd, const char *cmd)
 {
        unsigned char *qstats = NULL;
        int n;
@@ -385,8 +385,8 @@ static int qmp_connect(char *path)
 */
 static void read_attributes_qdisk_dom(xenstat_node *node, domid_t domain)
 {
-       char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
-       char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }";
+       const char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
+       const char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" 
}";
        unsigned char *qmp_stats, *val;
        char path[80];
        int qfd;
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.