37 #include <sys/types.h>
45 if (!tosearch || !searchfor || !replacewith)
50 size_t tosearchlen = strlen(tosearch);
51 size_t replacewithlen = strlen(replacewith);
52 size_t templen = tosearchlen * replacewithlen;
54 if (tosearchlen == 0 || strlen(searchfor) == 0 || replacewithlen == 0)
59 bool is_potential_integer_overflow = (templen == SIZE_MAX) || (templen / tosearchlen != replacewithlen);
61 if (is_potential_integer_overflow)
68 const char *searching = tosearch;
74 scratch = strstr(searching, searchfor);
77 return strdup(tosearch);
82 strncat(temp, searching, scratch-searching);
83 strcat(temp, replacewith);
85 searching = scratch+strlen(searchfor);
86 scratch = strstr(searching, searchfor);
92 get_env(
const char *name,
const char *envp[])
97 const int namelen = strlen(name);
98 for (i = 0; envp[i]; ++i)
100 if (!strncmp(envp[i], name, namelen))
102 const char *cp = envp[i] + namelen;