157 {
158 const char *tmp =
str;
160 int found = 0;
161 int length, reslen;
162 int oldlen = strlen(oldstr);
163 int newlen = strlen(newstr);
164 int limit = (
count != NULL && *
count > 0) ? *count : -1;
165
167 while ((tmp = strstr(tmp, oldstr)) != NULL && found != limit)
168 found++, tmp += oldlen;
169
170 length = (int)strlen(
str) + found * (newlen - oldlen);
172 rterror(
_(
"strreplace: Not enough memory"));
173 found = -1;
174 }
175 else {
177 limit = found;
178 reslen = 0;
179
180
181 while ((limit-- > 0) && (tmp = strstr(tmp, oldstr)) != NULL) {
182 length = (tmp -
str);
184 strcpy(
result + (reslen += length), newstr);
185
186 reslen += newlen;
187 tmp += oldlen;
189 }
191 }
192
193 if (count != NULL) *
count = found;
195}
char result[OUT_DOUBLE_BUFFER_SIZE]
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.