/*---------------------------------------------------------------------------* * platform_utils.c * * * * Copyright 2007, 2008 Nuance Communciations, Inc. * * * * Licensed under the Apache License, Version 2.0 (the 'License'); * * you may not use this file except in compliance with the License. * * * * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an 'AS IS' BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * * * *---------------------------------------------------------------------------*/ #ifndef NO_STDERR #include #endif #include #include "pmemory.h" #include "platform_utils.h" /* safe_strtok() Use this in place of regular strtok. which is dangerous because it modifies a global variable. This function does not. Returns the position in NULL terminated input_str where seps are found, and the length of the token Seps contains a NULL terminated string of separators Returns NULL if error If no more tokens left, token_len is 0 */ char * safe_strtok(char *input_str, char *seps, int * token_len) { int i, j, k, n, m; int sep_found; char *pos; m = strlen(seps); if (!m || !input_str) return NULL; n = strlen(input_str); pos = input_str; for (i=0, sep_found = 0; i