* sysdeps/generic/dl-environ.c (unsetenv): Redo last fix without
strncmp, keeps the code smaller for a non-performance-critical case.
This commit is contained in:
parent
0d35c2426d
commit
68b68cb3a4
|
@ -1,5 +1,8 @@
|
||||||
2002-09-11 Roland McGrath <roland@redhat.com>
|
2002-09-11 Roland McGrath <roland@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/generic/dl-environ.c (unsetenv): Redo last fix without
|
||||||
|
strncmp, keeps the code smaller for a non-performance-critical case.
|
||||||
|
|
||||||
* sysdeps/generic/dl-environ.c (unsetenv): Rewritten using strncmp,
|
* sysdeps/generic/dl-environ.c (unsetenv): Rewritten using strncmp,
|
||||||
no longer wrongly matches arbitrary prefixes of NAME.
|
no longer wrongly matches arbitrary prefixes of NAME.
|
||||||
Reported by Jakub Jelinek <jakub@redhat.com>.
|
Reported by Jakub Jelinek <jakub@redhat.com>.
|
||||||
|
|
|
@ -57,23 +57,30 @@ extern char **__environ attribute_hidden;
|
||||||
int
|
int
|
||||||
unsetenv (const char *name)
|
unsetenv (const char *name)
|
||||||
{
|
{
|
||||||
const size_t len = strlen (name);
|
|
||||||
char **ep;
|
char **ep;
|
||||||
|
|
||||||
ep = __environ;
|
ep = __environ;
|
||||||
while (*ep != NULL)
|
while (*ep != NULL)
|
||||||
if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
|
{
|
||||||
{
|
size_t cnt = 0;
|
||||||
/* Found it. Remove this pointer by moving later ones back. */
|
|
||||||
char **dp = ep;
|
|
||||||
|
|
||||||
do
|
while ((*ep)[cnt] == name[cnt] && name[cnt] != '\0')
|
||||||
dp[0] = dp[1];
|
++cnt;
|
||||||
while (*dp++);
|
|
||||||
/* Continue the loop in case NAME appears again. */
|
if (name[cnt] == '\0' && (*ep)[cnt] == '=')
|
||||||
}
|
{
|
||||||
else
|
/* Found it. Remove this pointer by moving later ones to
|
||||||
++ep;
|
the front. */
|
||||||
|
char **dp = ep;
|
||||||
|
|
||||||
|
do
|
||||||
|
dp[0] = dp[1];
|
||||||
|
while (*dp++);
|
||||||
|
/* Continue the loop in case NAME appears again. */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++ep;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue