wmifs: Convert strtok() calls to thread-safe strtok_r().

This commit is contained in:
Doug Torrance 2015-05-27 17:33:28 -05:00 committed by Carlos R. Mafra
parent 78ad4e4380
commit 8a960f1d3b

View file

@ -714,7 +714,7 @@ int get_statistics(char *devname, long *ip, long *op, long *is, long *os)
FILE *fp; FILE *fp;
char temp[BUFFER_SIZE]; char temp[BUFFER_SIZE];
char *p; char *p, *saveptr;
char *tokens = " |:\n"; char *tokens = " |:\n";
int input, output; int input, output;
int i; int i;
@ -762,7 +762,7 @@ int get_statistics(char *devname, long *ip, long *op, long *is, long *os)
i = 0; i = 0;
found = -1; found = -1;
p = strtok(temp, tokens); p = strtok_r(temp, tokens, &saveptr);
do { do {
if (!(strcmp(p, "packets"))) { if (!(strcmp(p, "packets"))) {
if (input == -1) if (input == -1)
@ -771,13 +771,13 @@ int get_statistics(char *devname, long *ip, long *op, long *is, long *os)
output = i; output = i;
} }
i++; i++;
p = strtok(NULL, tokens); p = strtok_r(NULL, tokens, &saveptr);
} while (input == -1 || output == -1); } while (input == -1 || output == -1);
while (fgets(temp, BUFFER_SIZE, fp)) { while (fgets(temp, BUFFER_SIZE, fp)) {
if (strstr(temp, devname)) { if (strstr(temp, devname)) {
found = 0; found = 0;
p = strtok(temp, tokens); p = strtok_r(temp, tokens, &saveptr);
i = 0; i = 0;
do { do {
if (i == input) { if (i == input) {
@ -789,7 +789,7 @@ int get_statistics(char *devname, long *ip, long *op, long *is, long *os)
output = -1; output = -1;
} }
i++; i++;
p = strtok(NULL, tokens); p = strtok_r(NULL, tokens, &saveptr);
} while (input != -1 || output != -1); } while (input != -1 || output != -1);
} }
} }
@ -856,10 +856,10 @@ int checknetdevs(void)
return -1; return -1;
} }
while (fgets(temp, BUFFER_SIZE, fd)) { while (fgets(temp, BUFFER_SIZE, fd)) {
char *p; char *p, *saveptr;
char *tokens = " :\t\n"; char *tokens = " :\t\n";
p = strtok(temp, tokens); p = strtok_r(temp, tokens, &saveptr);
if (p == NULL) { if (p == NULL) {
printf("Barfed on: %s", temp); printf("Barfed on: %s", temp);
break; break;