static void str_replace(char *str, const char *from, const char *to, int maxlen) { char *pstr = str; int fromlen = strlen(from); int tolen = strlen(to); while (*pstr != '\0' && pstr - str < maxlen) { if (strncmp(pstr, from, fromlen) != 0) { *pstr++; continue; } memmove(pstr + tolen, pstr + fromlen, maxlen - ((pstr + tolen) - str) - 1); memcpy(pstr, to, tolen); pstr += tolen; } }