summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorScott Moreau <oreaus@gmail.com>2012-01-27 13:25:49 -0700
committerKristian Høgsberg <krh@bitplanet.net>2012-01-27 15:34:27 -0500
commitfa1de6920331a1a91b08b8e6c55f91e99a3f82e5 (patch)
tree192d44cbd991ab7930743c488079509a93a26b27 /shared
parent765e27b9e2ebd69cfbab7f77fd2c8fbb5b43b8d6 (diff)
Implement CONFIG_KEY_UNSIGNED_INTEGER
strtol() does not work when trying to assign 32 bits of data into a regular signed int on 32 bit systems. Use corresponding strtoul() instead.
Diffstat (limited to 'shared')
-rw-r--r--shared/config-parser.c10
-rw-r--r--shared/config-parser.h7
2 files changed, 14 insertions, 3 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 3b8c5c2..10f6f12 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -32,6 +32,7 @@ handle_key(const struct config_key *key, const char *value)
{
char *end, *s;
int i, len;
+ unsigned int ui;
switch (key->type) {
case CONFIG_KEY_INTEGER:
@@ -43,6 +44,15 @@ handle_key(const struct config_key *key, const char *value)
*(int *)key->data = i;
return 0;
+ case CONFIG_KEY_UNSIGNED_INTEGER:
+ ui = strtoul(value, &end, 0);
+ if (*end != '\n') {
+ fprintf(stderr, "invalid integer: %s\n", value);
+ return -1;
+ }
+ *(unsigned int *)key->data = ui;
+ return 0;
+
case CONFIG_KEY_STRING:
len = strlen(value);
s = malloc(len);
diff --git a/shared/config-parser.h b/shared/config-parser.h
index 34f5c31..27f528d 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -24,9 +24,10 @@
#define CONFIGPARSER_H
enum config_key_type {
- CONFIG_KEY_INTEGER, /* typeof data = int */
- CONFIG_KEY_STRING, /* typeof data = char* */
- CONFIG_KEY_BOOLEAN /* typeof data = int */
+ CONFIG_KEY_INTEGER, /* typeof data = int */
+ CONFIG_KEY_UNSIGNED_INTEGER, /* typeof data = unsigned int */
+ CONFIG_KEY_STRING, /* typeof data = char* */
+ CONFIG_KEY_BOOLEAN /* typeof data = int */
};
struct config_key {