Skip to content

Commit 982edca

Browse files
committed
libnml,emc: strtok -> strtok_r
1 parent 6bf6287 commit 982edca

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

src/emc/rs274ngc/interp_remap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,12 @@ int Interp::parse_remap(const char *inistring, int lineno)
368368
if ((s = strchr(iniline, '#')) != NULL) {
369369
*s = '\0';
370370
}
371-
s = strtok((char *) iniline, " \t");
371+
char* safeptr;
372+
s = strtok_r((char *) iniline, " \t", &safeptr);
372373

373374
while( s != NULL && argc < MAX_REMAPOPTS - 1) {
374375
argv[argc++] = s;
375-
s = strtok( NULL, " \t" );
376+
s = strtok_r( NULL, " \t", &safeptr);
376377
}
377378
if (argc == MAX_REMAPOPTS) {
378379
Error("parse_remap: too many arguments (max %d)", MAX_REMAPOPTS);

src/emc/rs274ngc/rs274ngc_pre.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,8 @@ int Interp::init()
975975
}
976976

977977
rtapi_strxcpy(tmpdirs,inistring);
978-
nextdir = strtok(tmpdirs,":"); // first token
978+
char *safeptr;
979+
nextdir = strtok_r(tmpdirs,":",&safeptr); // first token
979980
dct = 0;
980981
while (1) {
981982
char tmp_path[PATH_MAX];
@@ -996,7 +997,7 @@ int Interp::init()
996997
logDebug("too many entries in SUBROUTINE_PATH, max=%d", MAX_SUB_DIRS);
997998
break;
998999
}
999-
nextdir = strtok(NULL,":");
1000+
nextdir = strtok_r(NULL,":",&safeptr);
10001001
if (nextdir == NULL) break; // no more tokens
10011002
}
10021003
}

src/emc/task/emctask.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ int emcTaskInit()
147147
}
148148
strncpy(tmpdirs, inistring, sizeof(tmpdirs));
149149

150-
nextdir = strtok(tmpdirs,":"); // first token
150+
char* safeptr;
151+
nextdir = strtok_r(tmpdirs,":", &safeptr); // first token
151152
dct = 1;
152153
while (dct < MAX_M_DIRS) {
153154
if (nextdir == NULL) break; // no more tokens
@@ -157,7 +158,7 @@ int emcTaskInit()
157158
return -1;
158159
}
159160
strncpy(mdir[dct], nextdir, sizeof(mdir[dct]));
160-
nextdir = strtok(NULL,":");
161+
nextdir = strtok_r(NULL,":",&safeptr);
161162
dct++;
162163
}
163164
dmax=dct;

src/emc/tooldata/tooldata_common.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ int tooldata_read_entry(const char *input_line,
9393
orientation = empty.orientation;
9494
offset = empty.offset;
9595

96-
buff = strtok(work_line, ";");
96+
char* safeptr;
97+
buff = strtok_r(work_line, ";", &safeptr);
9798
if (strlen(buff) <=1) {
9899
//fprintf(stderr,"skip blankline %s\n",__FILE__);
99100
return 0;
100101
}
101-
comment = strtok(NULL, "\n");
102+
comment = strtok_r(NULL, "\n", &safeptr);
102103

103-
token = strtok(buff, " ");
104+
token = strtok_r(buff, " ", &safeptr);
104105
while (token != NULL) {
105106
switch (toupper(token[0])) {
106107
case 'T':
@@ -188,7 +189,7 @@ int tooldata_read_entry(const char *input_line,
188189
valid = 0;
189190
break;
190191
}
191-
token = strtok(NULL, " ");
192+
token = strtok_r(NULL, " ", &safeptr);
192193
} // while token
193194

194195
if (valid) {

src/emc/tooldata/tooldata_db.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ int tooldata_db_init(char progname_plus_args[],int random_toolchanger)
242242
if (getenv( (char*)"DB_SHOW") ) {db_show = 1;}
243243
int child_argc = 0;
244244
char* child_argv[MAX_DB_PROGRAM_ARGS] = {0};
245-
char* token = strtok(progname_plus_args, " ");
245+
char* safeptr;
246+
char* token = strtok_r(progname_plus_args, " ", &safeptr);
246247
while (token != NULL) {
247248
child_argv[child_argc] = token;
248249
child_argc++;
@@ -251,7 +252,7 @@ int tooldata_db_init(char progname_plus_args[],int random_toolchanger)
251252
,MAX_DB_PROGRAM_ARGS);
252253
return -1;
253254
}
254-
token = strtok(NULL, " ");
255+
token = strtok_r(NULL, " ", &safeptr);
255256
}
256257
snprintf(db_childname,sizeof(db_childname),"%s",child_argv[0]);
257258
is_random_toolchanger = random_toolchanger;

src/libnml/rcs/rcs_print.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,10 @@ int separate_words(char **_dest, int _max, char *_src)
275275
return -1;
276276
}
277277
rtapi_strxcpy(word_buffer, _src);
278-
_dest[0] = strtok(word_buffer, " \n\r\t");
278+
char* safeptr;
279+
_dest[0] = strtok_r(word_buffer, " \n\r\t", &safeptr);
279280
for (i = 0; NULL != _dest[i] && i < _max - 1; i++) {
280-
_dest[i + 1] = strtok(NULL, " \n\r\t");
281+
_dest[i + 1] = strtok_r(NULL, " \n\r\t", &safeptr);
281282
}
282283
if (_dest[_max - 1] == NULL && i == _max - 1) {
283284
i--;

0 commit comments

Comments
 (0)