Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | Upstream-Status: Pending |
| 2 | |
| 3 | Signed-off-by: Scott Garman <scott.a.garman@intel.com> |
| 4 | |
| 5 | diff -Naur man-1.6e.orig/catopen/catopen.c man-1.6e/catopen/catopen.c |
| 6 | --- man-1.6e.orig/catopen/catopen.c 2005-08-20 20:26:06.000000000 -0300 |
| 7 | +++ man-1.6e/catopen/catopen.c 2007-05-18 11:31:05.000000000 -0300 |
| 8 | @@ -9,22 +9,63 @@ |
| 9 | extern char *index (const char *, int); /* not always in <string.h> */ |
| 10 | extern char *my_malloc(int); /* in util.c */ |
| 11 | |
| 12 | +/* if the program has sgid/suid privileges then getenv doesn't return |
| 13 | + * NLSPATH; so we set here a good default value. |
| 14 | + */ |
| 15 | #ifndef DEFAULT_NLSPATH |
| 16 | # if __GLIBC__ >= 2 |
| 17 | -# define DEFAULT_NLSPATH "/usr/share/locale/%L/%N" |
| 18 | +# define DEFAULT_NLSPATH "/usr/share/locale/%L/%N:/usr/share/locale/%l_%t/%N:/usr/share/locale/%l/%N" |
| 19 | # else |
| 20 | # define DEFAULT_NLSPATH "/usr/lib/locale/%N/%L" |
| 21 | # endif |
| 22 | #endif |
| 23 | |
| 24 | -static nl_catd my_catopenpath(char *name, char *path); |
| 25 | +static nl_catd my_catopenpath(char *name, char *path, char *lang); |
| 26 | |
| 27 | static /* this source included in gripes.c */ |
| 28 | nl_catd |
| 29 | my_catopen(char *name, int oflag) { |
| 30 | - nl_catd fd; |
| 31 | + nl_catd fd = (nl_catd) -1; |
| 32 | + |
| 33 | + /* using first the my_catopenpath, which looks with LANGUAGE |
| 34 | + * and only if it fails ressort to catopen, it gives better i18n |
| 35 | + */ |
| 36 | + { |
| 37 | + char *nlspath, *lang, *s; |
| 38 | |
| 39 | - fd = catopen(name, oflag); |
| 40 | + /* |
| 41 | + * "If NLSPATH does not exist in the environment, or if a |
| 42 | + * message catalog cannot be opened in any of the paths specified |
| 43 | + * by NLSPATH, then an implementation defined default path is used" |
| 44 | + */ |
| 45 | + nlspath = getenv("NLSPATH"); |
| 46 | + if (!nlspath) |
| 47 | + nlspath = DEFAULT_NLSPATH; |
| 48 | + |
| 49 | + lang = getenv("LANGUAGE"); |
| 50 | + if (!lang) |
| 51 | + lang = getenv("LC_ALL"); |
| 52 | + if (!lang) |
| 53 | + lang = getenv("LC_MESSAGES"); |
| 54 | + if (!lang) |
| 55 | + lang = getenv("LANG"); |
| 56 | + if (!lang) |
| 57 | + lang = ""; |
| 58 | + |
| 59 | + while(*lang && (fd == (nl_catd) -1)) { |
| 60 | + s = index(lang, ':'); |
| 61 | + if (s) *s = 0; |
| 62 | + fd = my_catopenpath(name, nlspath, lang); |
| 63 | + if (s) lang=s+1; |
| 64 | + else lang = ""; |
| 65 | + } |
| 66 | + if (fd == (nl_catd) -1) |
| 67 | + fd = my_catopenpath(name, nlspath, "en"); |
| 68 | + } |
| 69 | + |
| 70 | + /* still not found, use the system catopen */ |
| 71 | + if (fd == (nl_catd) -1) |
| 72 | + fd = catopen(name, oflag); |
| 73 | |
| 74 | if (fd == (nl_catd) -1 && oflag) { |
| 75 | oflag = 0; |
| 76 | @@ -32,8 +73,6 @@ |
| 77 | } |
| 78 | |
| 79 | if (fd == (nl_catd) -1) { |
| 80 | - char *nlspath; |
| 81 | - |
| 82 | /* The libc catopen fails - let us see if we can do better */ |
| 83 | /* The quotes below are from X/Open, XPG 1987, Vol. 3. */ |
| 84 | |
| 85 | @@ -58,17 +97,6 @@ |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | - /* |
| 90 | - * "If NLSPATH does not exist in the environment, or if a |
| 91 | - * message catalog cannot be opened in any of the paths specified |
| 92 | - * by NLSPATH, then an implementation defined default path is used" |
| 93 | - */ |
| 94 | - |
| 95 | - nlspath = getenv("NLSPATH"); |
| 96 | - if (nlspath) |
| 97 | - fd = my_catopenpath(name, nlspath); |
| 98 | - if (fd == (nl_catd) -1) |
| 99 | - fd = my_catopenpath(name, DEFAULT_NLSPATH); |
| 100 | } |
| 101 | return fd; |
| 102 | } |
| 103 | @@ -90,15 +118,13 @@ |
| 104 | * |
| 105 | */ |
| 106 | static nl_catd |
| 107 | -my_catopenpath(char *name, char *nlspath) { |
| 108 | - int fd; |
| 109 | +my_catopenpath(char *name, char *nlspath, char *lang) { |
| 110 | nl_catd cfd = (nl_catd) -1; |
| 111 | - char *path0, *path, *s, *file, *lang, *lang_l, *lang_t, *lang_c; |
| 112 | + char *path0, *path, *s, *file, *lang_l, *lang_t, *lang_c; |
| 113 | int langsz, namesz, sz, lang_l_sz, lang_t_sz, lang_c_sz; |
| 114 | |
| 115 | namesz = strlen(name); |
| 116 | |
| 117 | - lang = getenv("LANG"); |
| 118 | if (!lang) |
| 119 | lang = ""; |
| 120 | langsz = strlen(lang); |
| 121 | @@ -194,14 +220,9 @@ |
| 122 | path = s+1; |
| 123 | } else |
| 124 | path = 0; |
| 125 | - fd = open(file, O_RDONLY); |
| 126 | - if (fd != -1) { |
| 127 | - /* we found the right catalog - but we don't know the |
| 128 | - type of nl_catd, so close it again and ask libc */ |
| 129 | - close(fd); |
| 130 | - cfd = catopen(file, 0); |
| 131 | - break; |
| 132 | - } |
| 133 | + cfd = catopen(file, 0); |
| 134 | + if (cfd != (nl_catd) -1) |
| 135 | + break; |
| 136 | } |
| 137 | |
| 138 | free(path0); |
| 139 | diff -Naur man-1.6e.orig/src/manpath.c man-1.6e/src/manpath.c |
| 140 | --- man-1.6e.orig/src/manpath.c 2006-08-03 18:18:33.000000000 -0300 |
| 141 | +++ man-1.6e/src/manpath.c 2007-05-18 11:02:48.000000000 -0300 |
| 142 | @@ -282,13 +282,14 @@ |
| 143 | /* We cannot use "lang = setlocale(LC_MESSAGES, NULL)" or so: |
| 144 | the return value of setlocale is an opaque string. */ |
| 145 | /* POSIX prescribes the order: LC_ALL, LC_MESSAGES, LANG */ |
| 146 | - if((lang = getenv("LC_ALL")) != NULL) |
| 147 | + /* LANGUAGE is GNU/Linux and overrules all */ |
| 148 | + if((lang = getenv("LANGUAGE")) != NULL) |
| 149 | split2(dir, lang, add_to_mandirlist_x, perrs); |
| 150 | - if((lang = getenv("LC_MESSAGES")) != NULL) |
| 151 | + else if((lang = getenv("LC_ALL")) != NULL) |
| 152 | split2(dir, lang, add_to_mandirlist_x, perrs); |
| 153 | - if((lang = getenv("LANG")) != NULL) |
| 154 | + else if((lang = getenv("LC_MESSAGES")) != NULL) |
| 155 | split2(dir, lang, add_to_mandirlist_x, perrs); |
| 156 | - if((lang = getenv("LANGUAGE")) != NULL) |
| 157 | + else if((lang = getenv("LANG")) != NULL) |
| 158 | split2(dir, lang, add_to_mandirlist_x, perrs); |
| 159 | add_to_mandirlist_x(dir, 0, perrs); |
| 160 | } |