man: don't skip default path which appears in config file
authorRon Yorston <rmy@pobox.com>
Fri, 22 Mar 2019 16:25:32 +0000 (16:25 +0000)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 26 Mar 2019 16:46:21 +0000 (17:46 +0100)
If the MANPATH environment variable isn't set a provisional default
path of /usr/man is placed in man_path_list.  This is only used if a
configuration file doesn't contain an alternative path.

If a configuration file lists the default path first:

   MANPATH /usr/man:/usr/share/man

add_MANPATH() sees that the default entry is already present and skips
it.  As a result man_path_list only contains the second and subsequent
components of the configured MANPATH.

In such cases the path should not be skipped.

function                                             old     new   delta
add_MANPATH                                          170     183     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/man.c

index 01155c8f095c1c28f7ae8917f285e05efd6c911c..9884325b7b3eae713ddb0d4f69e562369b06ae98 100644 (file)
@@ -209,8 +209,12 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
                /* Do we already have path? */
                path_element = man_path_list;
                if (path_element) while (*path_element) {
-                       if (strcmp(*path_element, path) == 0)
+                       if (strcmp(*path_element, path) == 0) {
+                               /* Have path but haven't counted it, must be default */
+                               if (*count_mp == 0)
+                                       break;
                                goto skip;
+                       }
                        path_element++;
                }
                man_path_list = xrealloc_vector(man_path_list, 4, *count_mp);