Issue #1454 - Remove usage of non re-entrant strtok()

Thanks to Jaroslav Kysela <perex@perex.cz> for providing the initial fix.
This commit is contained in:
Adam Sutton 2012-12-13 20:57:09 +00:00
parent 3a54bc7f16
commit 86fac417c2
4 changed files with 13 additions and 12 deletions

View file

@ -634,7 +634,7 @@ static void _xmltv_load_grabbers ( void )
size_t i, p, n; size_t i, p, n;
char *outbuf; char *outbuf;
char name[1000]; char name[1000];
char *tmp, *path; char *tmp, *tmp2, *path;
/* Load data */ /* Load data */
outlen = spawn_and_store_stdout(XMLTV_FIND, NULL, &outbuf); outlen = spawn_and_store_stdout(XMLTV_FIND, NULL, &outbuf);
@ -668,7 +668,7 @@ static void _xmltv_load_grabbers ( void )
NULL NULL
}; };
path = strdup(tmp); path = strdup(tmp);
tmp = strtok(path, ":"); tmp = strtok_r(path, ":", &tmp2);
while (tmp) { while (tmp) {
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
@ -691,7 +691,7 @@ static void _xmltv_load_grabbers ( void )
} }
closedir(dir); closedir(dir);
} }
tmp = strtok(NULL, ":"); tmp = strtok_r(NULL, ":", &tmp2);
} }
free(path); free(path);
} }

View file

@ -214,12 +214,13 @@ fb_dir *fb_opendir ( const char *path )
/* Bundle */ /* Bundle */
#if ENABLE_BUNDLE #if ENABLE_BUNDLE
char *tmp1 = strdup(path); char *tmp1, *tmp2, *tmp3;
char *tmp2 = strtok(tmp1, "/"); *tmp1 = strdup(path);
*tmp2 = strtok_r(tmp1, "/", &tmp3);
filebundle_entry_t *fb = filebundle_root; filebundle_entry_t *fb = filebundle_root;
while (fb && tmp2) { while (fb && tmp2) {
if (fb->type == FB_DIR && !strcmp(fb->name, tmp2)) { if (fb->type == FB_DIR && !strcmp(fb->name, tmp2)) {
tmp2 = strtok(NULL, "/"); tmp2 = strtok_r(NULL, "/", &tmp3);
if (tmp2) fb = fb->d.child; if (tmp2) fb = fb->d.child;
} else { } else {
fb = fb->next; fb = fb->next;

View file

@ -53,13 +53,13 @@ find_exec ( const char *name, char *out, size_t len )
{ {
int ret = 0; int ret = 0;
char bin[512]; char bin[512];
char *path, *tmp; char *path, *tmp, *tmp2;
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
struct stat st; struct stat st;
if (!(path = getenv("PATH"))) return 0; if (!(path = getenv("PATH"))) return 0;
path = strdup(path); path = strdup(path);
tmp = strtok(path, ":"); tmp = strtok_r(path, ":", &tmp2);
while (tmp && !ret) { while (tmp && !ret) {
if ((dir = opendir(tmp))) { if ((dir = opendir(tmp))) {
while ((de = readdir(dir))) { while ((de = readdir(dir))) {
@ -73,7 +73,7 @@ find_exec ( const char *name, char *out, size_t len )
} }
closedir(dir); closedir(dir);
} }
tmp = strtok(NULL, ":"); tmp = strtok_r(NULL, ":", &tmp2);
} }
free(path); free(path);
return ret; return ret;

View file

@ -352,7 +352,7 @@ extjs_channels_update(htsmsg_t *in)
if((s = htsmsg_get_str(c, "epggrabsrc")) != NULL) { if((s = htsmsg_get_str(c, "epggrabsrc")) != NULL) {
char *tmp = strdup(s); char *tmp = strdup(s);
char *sptr = NULL; char *sptr, *sptr2;
char *modecid = strtok_r(tmp, ",", &sptr); char *modecid = strtok_r(tmp, ",", &sptr);
char *modid, *ecid; char *modid, *ecid;
epggrab_module_t *mod; epggrab_module_t *mod;
@ -377,8 +377,8 @@ extjs_channels_update(htsmsg_t *in)
/* Add new */ /* Add new */
while (modecid) { while (modecid) {
modid = strtok(modecid, "|"); modid = strtok_r(modecid, "|", &sptr2);
ecid = strtok(NULL, "|"); ecid = strtok_r(NULL, "|", &sptr2);
modecid = strtok_r(NULL, ",", &sptr); modecid = strtok_r(NULL, ",", &sptr);
if (!(mod = epggrab_module_find_by_id(modid))) if (!(mod = epggrab_module_find_by_id(modid)))