| 860 | } |
| 861 | |
| 862 | char * |
| 863 | translate_path_variables(const char *str, char *buf) |
| 864 | { |
| 865 | const char *src; |
| 866 | char evar[BUFSZ], *dest, *envp, *eptr = (char *) 0; |
| 867 | boolean in_evar; |
| 868 | size_t ccount, ecount, destcount, slen = str ? strlen(str) : 0; |
| 869 | |
| 870 | if (!slen || !buf) { |
| 871 | if (buf) |
| 872 | *buf = '\0'; |
| 873 | return buf; |
| 874 | } |
| 875 | |
| 876 | dest = buf; |
| 877 | src = str; |
| 878 | in_evar = FALSE; |
| 879 | destcount = ecount = 0; |
| 880 | for (ccount = 0; |
| 881 | ccount < slen && destcount < (BUFSZ - 1) && ecount < (BUFSZ - 1); |
| 882 | ++ccount, ++src) { |
| 883 | if (*src == '%') { |
| 884 | if (in_evar) { |
| 885 | *eptr = '\0'; |
| 886 | envp = nh_getenv(evar); |
| 887 | if (envp) { |
| 888 | size_t elen = strlen(envp); |
| 889 | |
| 890 | if ((elen + destcount) < (size_t) (BUFSZ - 1)) { |
| 891 | Strcpy(dest, envp); |
| 892 | dest += elen; |
| 893 | destcount += elen; |
| 894 | } |
| 895 | } |
| 896 | } else { |
| 897 | eptr = evar; |
| 898 | ecount = 0; |
| 899 | } |
| 900 | in_evar = !in_evar; |
| 901 | continue; |
| 902 | } |
| 903 | if (in_evar) { |
| 904 | *eptr++ = *src; |
| 905 | ecount++; |
| 906 | } else { |
| 907 | *dest++ = *src; |
| 908 | destcount++; |
| 909 | } |
| 910 | } |
| 911 | *dest = '\0'; |
| 912 | return buf; |
| 913 | } |
| 914 | |
| 915 | DISABLE_WARNING_UNREACHABLE_CODE |
| 916 | |