Changeset 561 in MondoRescue for trunk/mondo/mondo/common/libmondo-string.c


Ignore:
Timestamp:
May 20, 2006, 5:51:21 PM (18 years ago)
Author:
bcornec
Message:

merge -r 542:560 $SVN_M/branches/stable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-string.c

    r507 r561  
    22   $Id$
    33*/
    4 
    54
    65/**
     
    11391138}
    11401139
     1140
     1141/* New functions safe from a memory manageemnt point of view */
     1142/* Developped by Andree Leidenfrost */
     1143
     1144char *mr_strtok(char *instr, const char *delims, int *lastpos) {
     1145
     1146char *token = NULL;
     1147char *strptr = NULL;
     1148size_t pos1 = 0;
     1149size_t pos2 = 0;
     1150
     1151if (strlen(instr) <= *lastpos) {
     1152    *lastpos = 0;
     1153    return token;
     1154}
     1155
     1156strptr = instr + *lastpos;
     1157pos2 = strspn(strptr, delims);
     1158strptr += pos2;
     1159pos1 = strcspn(strptr, delims);
     1160token = malloc(sizeof(*token)*(pos1+1));
     1161strncpy(token, strptr, pos1);
     1162*lastpos = *lastpos + pos1 + pos2 + 1;
     1163
     1164return token;
     1165}
    11411166/* @} - end of stringGroup */
Note: See TracChangeset for help on using the changeset viewer.