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.
This commit is contained in:
committed by
Kristian Høgsberg
parent
765e27b9e2
commit
fa1de69203
@@ -107,8 +107,8 @@ static int key_locking = 1;
|
|||||||
static const struct config_key shell_config_keys[] = {
|
static const struct config_key shell_config_keys[] = {
|
||||||
{ "background-image", CONFIG_KEY_STRING, &key_background_image },
|
{ "background-image", CONFIG_KEY_STRING, &key_background_image },
|
||||||
{ "background-type", CONFIG_KEY_STRING, &key_background_type },
|
{ "background-type", CONFIG_KEY_STRING, &key_background_type },
|
||||||
{ "panel-color", CONFIG_KEY_INTEGER, &key_panel_color },
|
{ "panel-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_panel_color },
|
||||||
{ "background-color", CONFIG_KEY_INTEGER, &key_background_color },
|
{ "background-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_background_color },
|
||||||
{ "locking", CONFIG_KEY_BOOLEAN, &key_locking },
|
{ "locking", CONFIG_KEY_BOOLEAN, &key_locking },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ handle_key(const struct config_key *key, const char *value)
|
|||||||
{
|
{
|
||||||
char *end, *s;
|
char *end, *s;
|
||||||
int i, len;
|
int i, len;
|
||||||
|
unsigned int ui;
|
||||||
|
|
||||||
switch (key->type) {
|
switch (key->type) {
|
||||||
case CONFIG_KEY_INTEGER:
|
case CONFIG_KEY_INTEGER:
|
||||||
@@ -43,6 +44,15 @@ handle_key(const struct config_key *key, const char *value)
|
|||||||
*(int *)key->data = i;
|
*(int *)key->data = i;
|
||||||
return 0;
|
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:
|
case CONFIG_KEY_STRING:
|
||||||
len = strlen(value);
|
len = strlen(value);
|
||||||
s = malloc(len);
|
s = malloc(len);
|
||||||
|
|||||||
@@ -24,9 +24,10 @@
|
|||||||
#define CONFIGPARSER_H
|
#define CONFIGPARSER_H
|
||||||
|
|
||||||
enum config_key_type {
|
enum config_key_type {
|
||||||
CONFIG_KEY_INTEGER, /* typeof data = int */
|
CONFIG_KEY_INTEGER, /* typeof data = int */
|
||||||
CONFIG_KEY_STRING, /* typeof data = char* */
|
CONFIG_KEY_UNSIGNED_INTEGER, /* typeof data = unsigned int */
|
||||||
CONFIG_KEY_BOOLEAN /* typeof data = int */
|
CONFIG_KEY_STRING, /* typeof data = char* */
|
||||||
|
CONFIG_KEY_BOOLEAN /* typeof data = int */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct config_key {
|
struct config_key {
|
||||||
|
|||||||
Reference in New Issue
Block a user