permission: use g_strsplit() instead of strtok_r()
g_strsplit() is more portable than strtok_r().
This commit is contained in:
parent
6507bcccd3
commit
5b543e8fa6
@ -38,17 +38,18 @@ static GHashTable *permission_passwords;
|
|||||||
|
|
||||||
static unsigned permission_default;
|
static unsigned permission_default;
|
||||||
|
|
||||||
static unsigned parsePermissions(char *string)
|
static unsigned parsePermissions(const char *string)
|
||||||
{
|
{
|
||||||
unsigned permission = 0;
|
unsigned permission = 0;
|
||||||
char *temp;
|
gchar **tokens;
|
||||||
char *tok;
|
|
||||||
|
|
||||||
if (!string)
|
if (!string)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
temp = strtok_r(string, PERMISSION_SEPERATOR, &tok);
|
tokens = g_strsplit(string, PERMISSION_SEPERATOR, 0);
|
||||||
while (temp) {
|
for (unsigned i = 0; tokens[i] != NULL; ++i) {
|
||||||
|
char *temp = tokens[i];
|
||||||
|
|
||||||
if (strcmp(temp, PERMISSION_READ_STRING) == 0) {
|
if (strcmp(temp, PERMISSION_READ_STRING) == 0) {
|
||||||
permission |= PERMISSION_READ;
|
permission |= PERMISSION_READ;
|
||||||
} else if (strcmp(temp, PERMISSION_ADD_STRING) == 0) {
|
} else if (strcmp(temp, PERMISSION_ADD_STRING) == 0) {
|
||||||
@ -60,10 +61,10 @@ static unsigned parsePermissions(char *string)
|
|||||||
} else {
|
} else {
|
||||||
FATAL("unknown permission \"%s\"\n", temp);
|
FATAL("unknown permission \"%s\"\n", temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
temp = strtok_r(NULL, PERMISSION_SEPERATOR, &tok);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_strfreev(tokens);
|
||||||
|
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ void initPermissions(void)
|
|||||||
permission_default = 0;
|
permission_default = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
char *separator =
|
const char *separator =
|
||||||
strchr(param->value, PERMISSION_PASSWORD_CHAR);
|
strchr(param->value, PERMISSION_PASSWORD_CHAR);
|
||||||
|
|
||||||
if (separator == NULL)
|
if (separator == NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user