[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH] man: allow multiple paths in MANPATH
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2014-11-30 18:40:19
Message-ID: CAK1hOcOD3Vy0-1WUj=vwE3zCRC08Rwv9vooZ0fxVqrFppi0P7Q () mail ! gmail ! com
[Download RAW message or body]
On Thu, Nov 27, 2014 at 2:45 AM, Marcel Rodrigues <marcelgmr@gmail.com> wrote:
>> getenv() is not readonly.
>
>
> POSIX says that "[t]he application shall ensure that it does not modify the
> string pointed to by the getenv() function." I might be completely wrong but
> my impression is that in practice the libc will just give you a pointer to
> an entry in the environ static array, so if you mess with it, subsequent
> calls to getenv() in the same process with the same argument will be messed.
Fixing like this:
static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
{
if (path) while (*path) {
char *next_path;
char **path_element;
next_path = strchr(path, ':');
if (next_path) {
if (next_path == path) /* "::"? */
goto next;
*next_path = '\0';
}
/* Do we already have path? */
path_element = man_path_list;
if (path_element) while (*path_element) {
if (strcmp(*path_element, path) == 0)
goto skip;
path_element++;
}
man_path_list = xrealloc_vector(man_path_list, 4, *count_mp);
man_path_list[*count_mp] = xstrdup(path);
(*count_mp)++;
/* man_path_list is NULL terminated */
/* man_path_list[*count_mp] = NULL; - xrealloc_vector did it */
skip:
if (!next_path)
break;
/* "path" may be a result of getenv(), be nice and
don't mangle it */
*next_path = ':';
next:
path = next_path + 1;
}
return man_path_list;
}
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic