string_m.c (4268f3b3e0d87bc090b7fe0f95fb52a2e904db25) string_m.c (59ba78ccae74a8a116e4784b4edb840dae61610d)
1/*-
2 * Copyright (c) 2001-2014 Devin Teske <dteske@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 105 unchanged lines hidden (view full) ---

114 rlen = replace ? strlen(replace) : 0;
115
116 /* Cases where no replacements need to be made */
117 if (slen == 0 || flen == 0 || slen < flen)
118 return (slen);
119
120 /* If replace is longer than find, we'll need to create a temp copy */
121 if (rlen > flen) {
1/*-
2 * Copyright (c) 2001-2014 Devin Teske <dteske@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 105 unchanged lines hidden (view full) ---

114 rlen = replace ? strlen(replace) : 0;
115
116 /* Cases where no replacements need to be made */
117 if (slen == 0 || flen == 0 || slen < flen)
118 return (slen);
119
120 /* If replace is longer than find, we'll need to create a temp copy */
121 if (rlen > flen) {
122 temp = strdup(source);
122 temp = malloc(slen + 1);
123 if (temp == NULL) /* could not allocate memory */
124 return (-1);
123 if (temp == NULL) /* could not allocate memory */
124 return (-1);
125 memcpy(temp, source, slen + 1);
125 } else
126 temp = source;
127
128 /* Reconstruct the string with the replacements */
129 p = source; t = temp; /* position elements */
130
131 while (*t != '\0') {
132 if (strncmp(t, find, flen) == 0) {

--- 176 unchanged lines hidden ---
126 } else
127 temp = source;
128
129 /* Reconstruct the string with the replacements */
130 p = source; t = temp; /* position elements */
131
132 while (*t != '\0') {
133 if (strncmp(t, find, flen) == 0) {

--- 176 unchanged lines hidden ---