Difference for common/utils.c from version 1.19 to 1.20


version 1.19 version 1.20
Line 1
 
Line 1
 /*  /*
  * static char *rcsid_utils_c =   * static char *rcsid_utils_c =
  *   "$Id: utils.c,v 1.19 2005/10/13 07:26:00 mwedel Exp $";   *   "$Id: utils.c,v 1.20 2005/10/17 13:08:26 qal21 Exp $";
  */   */
   
 /*  /*
Line 408
 
Line 408
     if (!strcmp(buf+strlen(buf)-EOL_SIZE,"\n"))      if (!strcmp(buf+strlen(buf)-EOL_SIZE,"\n"))
         buf[strlen(buf)-EOL_SIZE]='\0';              buf[strlen(buf)-EOL_SIZE]='\0';   
 }  }
   
   /**
    * Replace in string src all occurrences of key by replacement. The resulting
    * string is put into result; at most resultsize characters (including the
    * terminating null character) will be written to result.
    */
   void replace(const char *src, const char *key, const char *replacement, char *result, size_t resultsize)
   {
    size_t resultlen;
    size_t keylen;
   
    /* special case to prevent infinite loop if key==replacement=="" */
    if(strcmp(key, replacement) == 0)
    {
    snprintf(result, resultsize, "%s", src);
    return;
    }
   
    keylen = strlen(key);
   
    resultlen = 0;
    while(*src != '\0' && resultlen+1 < resultsize)
    {
    if(strncmp(src, key, keylen) == 0)
    {
    snprintf(result+resultlen, resultsize-resultlen, "%s", replacement);
    resultlen += strlen(result+resultlen);
    src += keylen;
    }
    else
    {
    result[resultlen++] = *src++;
    }
    }
    result[resultlen] = '\0';
   }


Legend:
line(s) removed in v.1.19 
line(s) changed
 line(s) added in v.1.20

File made using version 1.98 of cvs2html by leaf at 2011-07-21 17:19