149 const char *tmp =
str;
153 int oldlen = strlen(oldstr);
154 int newlen = strlen(newstr);
158 while ((tmp = strstr(tmp, oldstr)) != NULL && found != limit)
159 found++, tmp += oldlen;
161 length = strlen(
str) + found * (newlen - oldlen);
162 if ((result = (
char *)
rtalloc(length + 1)) == NULL) {
163 rterror(
_(
"strreplace: Not enough memory"));
172 while ((limit-- > 0) && (tmp = strstr(tmp, oldstr)) != NULL) {
173 length = (tmp -
str);
174 strncpy(result + reslen,
str, length);
175 strcpy(result + (reslen += length), newstr);
181 strcpy(result + reslen,
str);
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.