Don't trash original string when working with flags. #funwithflags

This commit is contained in:
Steve 2016-04-15 13:07:58 +01:00
parent 87048e4c85
commit 5e58f09fcf
1 changed files with 9 additions and 4 deletions

View File

@ -265,18 +265,21 @@ char *getFlagValues(char *prefix, long flags)
return flagStr;
}
long flagsToLong(char *flags, int *add)
long flagsToLong(char *in, int *add)
{
char *flag;
char *flag, *flags;
long total;
total = 0;
if (add)
{
*add = (flags[0] == '+');
*add = (in[0] == '+');
}
flags = malloc(strlen(in) + 1);
STRNCPY(flags, in, strlen(in) + 1);
flag = strtok(flags, "+");
while (flag)
{
@ -284,6 +287,8 @@ long flagsToLong(char *flags, int *add)
flag = strtok(NULL, "+");
}
free(flags);
return total;
}