| 892 | //========================================================================== |
| 893 | |
| 894 | FString NicePath(const char *path) |
| 895 | { |
| 896 | #ifdef _WIN32 |
| 897 | if (*path == '\0') |
| 898 | { |
| 899 | return FString("."); |
| 900 | } |
| 901 | return ExpandEnvVars(path); |
| 902 | #else |
| 903 | if (path == NULL || *path == '\0') |
| 904 | { |
| 905 | return FString(""); |
| 906 | } |
| 907 | if (*path != '~') |
| 908 | { |
| 909 | return ExpandEnvVars(path); |
| 910 | } |
| 911 | |
| 912 | passwd *pwstruct; |
| 913 | const char *slash; |
| 914 | |
| 915 | if (path[1] == '/' || path[1] == '\0') |
| 916 | { // Get my home directory |
| 917 | pwstruct = getpwuid(getuid()); |
| 918 | slash = path + 1; |
| 919 | } |
| 920 | else |
| 921 | { // Get somebody else's home directory |
| 922 | slash = strchr(path, '/'); |
| 923 | if (slash == NULL) |
| 924 | { |
| 925 | slash = path + strlen(path); |
| 926 | } |
| 927 | FString who(path, slash - path); |
| 928 | pwstruct = getpwnam(who.GetChars()); |
| 929 | } |
| 930 | if (pwstruct == NULL) |
| 931 | { |
| 932 | return ExpandEnvVars(path); |
| 933 | } |
| 934 | FString where(pwstruct->pw_dir); |
| 935 | if (*slash != '\0') |
| 936 | { |
| 937 | where += ExpandEnvVars(slash); |
| 938 | } |
| 939 | return where; |
| 940 | #endif |
| 941 | } |
| 942 | |
| 943 | |
| 944 | //========================================================================== |