146 const char *tmp = str;
150 int oldlen = strlen(oldstr);
151 int newlen = strlen(newstr);
155 while ((tmp = strstr(tmp, oldstr)) != NULL && found != limit)
156 found++, tmp += oldlen;
158 length = strlen(str) + found * (newlen - oldlen);
159 if ((result = (
char *)
rtalloc(length + 1)) == NULL) {
160 rterror(
_(
"strreplace: Not enough memory"));
169 while ((limit-- > 0) && (tmp = strstr(tmp, oldstr)) != NULL) {
170 length = (tmp - str);
171 strncpy(result + reslen, str, length);
172 strcpy(result + (reslen += length), newstr);
178 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.