]> git.ozlabs.org Git - ccan/commitdiff
ciniparser: Make key arguments const
authorJon Griffiths <jon_p_griffiths@yahoo.com>
Wed, 24 Aug 2016 07:04:24 +0000 (19:04 +1200)
committerJon Griffiths <jon_p_griffiths@yahoo.com>
Mon, 29 Aug 2016 04:55:58 +0000 (16:55 +1200)
Keys are never modified and are likely to be literals in the
real world (as they are in the test cases).

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
ccan/ciniparser/ciniparser.c
ccan/ciniparser/ciniparser.h
ccan/ciniparser/dictionary.c
ccan/ciniparser/dictionary.h

index 2b60e409bd7ac7259d2e5245fd457e8087ed7472..527f83776e86428c5e283b76211291445ae7b4f9 100644 (file)
@@ -316,7 +316,7 @@ int ciniparser_getint(dictionary *d, const char *key, int notfound)
        return (int) strtol(str, NULL, 10);
 }
 
-double ciniparser_getdouble(dictionary *d, char *key, double notfound)
+double ciniparser_getdouble(dictionary *d, const char *key, double notfound)
 {
        char *str;
 
index f61b357627fe50582d7a212995c312e0033b4418..b61c1d6eaa48650dbe70c9de3a35c9abd0ac3cd0 100644 (file)
@@ -151,7 +151,7 @@ int ciniparser_getint(dictionary *d, const char *key, int notfound);
  * ini file is given as "section:key". If the key cannot be found,
  * the notfound value is returned.
  */
-double ciniparser_getdouble(dictionary *d, char *key, double notfound);
+double ciniparser_getdouble(dictionary *d, const char *key, double notfound);
 
 /**
  * @brief    Get the string associated to a key, convert to a boolean
index 4b24fb04484a1128cbc5bd9c7caf7295131cf80a..19dd6411cc9cceb3cabe311a079352f0836e74ed 100644 (file)
@@ -72,7 +72,7 @@ static void *mem_double(void *ptr, int size)
 
 /* The remaining exposed functions are documented in dictionary.h */
 
-unsigned dictionary_hash(char *key)
+unsigned dictionary_hash(const char *key)
 {
        int len;
        unsigned hash;
@@ -126,7 +126,7 @@ void dictionary_del(dictionary *d)
        return;
 }
 
-char *dictionary_get(dictionary *d, char *key, char *def)
+char *dictionary_get(dictionary *d, const char *key, char *def)
 {
        unsigned hash;
        int i;
@@ -146,7 +146,7 @@ char *dictionary_get(dictionary *d, char *key, char *def)
        return def;
 }
 
-int dictionary_set(dictionary *d, char *key, char *val)
+int dictionary_set(dictionary *d, const char *key, char *val)
 {
        int i;
        unsigned hash;
@@ -206,7 +206,7 @@ int dictionary_set(dictionary *d, char *key, char *val)
        return 0;
 }
 
-void dictionary_unset(dictionary *d, char *key)
+void dictionary_unset(dictionary *d, const char *key)
 {
        unsigned hash;
        int i;
index f831e39dc752086f96bfa52704c0c4493fc3ebb9..a94ea1a140e841931a95930eaf4d5d09ae4b12f2 100644 (file)
@@ -76,7 +76,7 @@ typedef struct _dictionary_ {
  * The key is stored anyway in the struct so that collision can be avoided
  * by comparing the key itself in last resort.
  */
-unsigned dictionary_hash(char *key);
+unsigned dictionary_hash(const char *key);
 
 /**
  * @brief Create a new dictionary object.
@@ -110,7 +110,7 @@ void dictionary_del(dictionary *vd);
  * dictionary. The returned character pointer points to data internal to the
  * dictionary object, you should not try to free it or modify it.
  */
-char *dictionary_get(dictionary *d, char *key, char *def);
+char *dictionary_get(dictionary *d, const char *key, char *def);
 
 /**
  * @brief Set a value in a dictionary.
@@ -136,7 +136,7 @@ char *dictionary_get(dictionary *d, char *key, char *def);
  *
  * This function returns non-zero in case of failure.
  */
-int dictionary_set(dictionary *vd, char *key, char *val);
+int dictionary_set(dictionary *vd, const char *key, char *val);
 
 /**
  * @brief Delete a key in a dictionary
@@ -147,7 +147,7 @@ int dictionary_set(dictionary *vd, char *key, char *val);
  * This function deletes a key in a dictionary. Nothing is done if the
  * key cannot be found.
  */
-void dictionary_unset(dictionary *d, char *key);
+void dictionary_unset(dictionary *d, const char *key);
 
 /**
  * @brief Dump a dictionary to an opened file pointer.