Don't trash original string when working with flags. #funwithflags
This commit is contained in:
parent
87048e4c85
commit
5e58f09fcf
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue