* If the path is *potentially* a path to remote share, we do not
* call GetLongPathName, because if the remote server is unreachable,
* that function could hang. We sacrifice two things by doing so:
- * 1. The UNC path could refer to the local host and we incorrectly
+ * 1. The UNC path could refer to the local host and we incorrectly
* assume remote.
* 2. We do not resolve 8.3 names for remote paths.
*/
* for use as a seed to hash functions.
*
* Results:
- * Canonicalized UTF-8 pathname suitable for use in hashing.
+ * Canonicalized UTF-8 pathname suitable for use in hashing.
*
* Side effects:
* None.
{
char *ret = NULL;
char *cpath = Util_GetCanonicalPath(path);
-
+
if (cpath != NULL) {
ret = Unicode_FoldCase(cpath);
free(cpath);
- }
+ }
return ret;
}
* encoding. Hence, the use of WideCharToMultiByte().
*
* Results:
- * An allocated string in legacy encoding (MBCS when applicable).
+ * An allocated string in legacy encoding (MBCS when applicable).
* NULL on failure.
- *
+ *
* Side effects:
* None.
*
{
char *ret = NULL;
char *cpath = Util_GetCanonicalPath(path);
-
+
if (cpath != NULL) {
char *apath = NULL;
int retlen;
WCHAR *wcpath = Unicode_GetAllocUTF16(cpath);
/* First get the length of multibyte string */
- int alen = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wcpath, -1,
+ int alen = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wcpath, -1,
NULL, 0, NULL, NULL);
if (alen > 0) {
/* Now get the converted string */
ret = Util_SafeMalloc(alen);
- retlen = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wcpath, -1,
+ retlen = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wcpath, -1,
ret, alen, NULL, NULL);
if (retlen != alen) {
free(ret);
free(cpath);
free(wcpath);
}
-
+
return ret;
}
ret = UtilGetLegacyEncodedString(cpath);
free(cpath);
}
-
+
return ret;
}
#endif
* Util_CanonicalPathsIdentical --
*
* Utility function to compare two paths that have already been made
- * canonical. This function exists to mask platform differences in
+ * canonical. This function exists to mask platform differences in
* path case-sensitivity.
*
* XXX: This implementation makes assumptions about the host filesystem's
*
* UtilIsAlphaOrNum --
*
- * Checks if character is a numeric digit or a letter of the
+ * Checks if character is a numeric digit or a letter of the
* english alphabet.
*
* Results:
*
* UtilGetHomeDirectory --
*
- * Unicode wrapper for posix getpwnam call for working directory.
+ * Retrieves the home directory for a user, given their passwd struct.
*
* Results:
- * Returns initial working directory or NULL if it fails.
+ * Returns user's home directory or NULL if it fails.
*
* Side effects:
- * None.
+ * None.
*
*-----------------------------------------------------------------------------
*/
static char *
-UtilGetHomeDirectory(const char *name) // IN: user name
+UtilGetHomeDirectory(struct passwd *pwd) // IN/OPT: user passwd struct
{
- char *dir;
- struct passwd *pwd;
-
- ASSERT(name);
-
- pwd = Posix_Getpwnam(name);
if (pwd && pwd->pw_dir) {
- dir = Util_SafeStrdup(pwd->pw_dir);
+ return Util_SafeStrdup(pwd->pw_dir);
} else {
- dir = NULL;
+ return NULL;
}
- endpwent();
-
- return dir;
}
*
* UtilGetLoginName --
*
- * Unicode wrapper for posix getpwnam call for working directory.
+ * Retrieves the login name for a user, given their passwd struct.
*
* Results:
* Returns user's login name or NULL if it fails.
*
* Side effects:
- * None.
+ * None.
*
*-----------------------------------------------------------------------------
*/
static char *
-UtilGetLoginName(int uid) //IN: user id
+UtilGetLoginName(struct passwd *pwd) // IN/OPT: user passwd struct
{
- char *name;
- struct passwd *pwd;
-
- pwd = Posix_Getpwuid(uid);
if (pwd && pwd->pw_name) {
- name = Util_SafeStrdup(pwd->pw_name);
+ return Util_SafeStrdup(pwd->pw_name);
} else {
- name = NULL;
+ return NULL;
}
- endpwent();
-
- return name;
}
*/
static Unicode
-UtilDoTildeSubst(Unicode user) // IN - name of user
+UtilDoTildeSubst(ConstUnicode user) // IN: name of user
{
Unicode str = NULL;
+ struct passwd *pwd = NULL;
if (*user == '\0') {
+#if defined(__APPLE__)
+ /*
+ * The HOME environment variable is not always set on Mac OS.
+ * (was bug 841728)
+ */
+ pwd = Posix_Getpwuid(getuid());
+ if (pwd == NULL) {
+ Log("Could not get passwd for current user.\n");
+ }
+#else // !defined(__APPLE__)
str = Unicode_Duplicate(Posix_Getenv("HOME"));
if (str == NULL) {
Log("Could not expand environment variable HOME.\n");
}
+#endif // !defined(__APPLE__)
} else {
- str = UtilGetHomeDirectory(user);
+ pwd = Posix_Getpwnam(user);
+ if (pwd == NULL) {
+ Log("Could not get passwd for user '%s'.\n", user);
+ }
+ }
+ if (str == NULL && pwd != NULL) {
+ str = UtilGetHomeDirectory(pwd);
+ endpwent();
if (str == NULL) {
- Log("Could not get information for user '%s'.\n", user);
+ Log("Could not get home directory for user.\n");
}
}
return str;
/*
* quick exit
*/
- if (!Unicode_StartsWith(fileName, "~") &&
+ if (!Unicode_StartsWith(fileName, "~") &&
Unicode_Find(fileName, "$") == UNICODE_INDEX_NOT_FOUND) {
return copy;
}
expand = Util_SafeStrdup(buf);
} else if (strcasecmp(cp + 1, "USER") == 0) {
#if !defined(_WIN32)
- int uid = getuid();
- expand = UtilGetLoginName(uid);
+ struct passwd *pwd = Posix_Getpwuid(getuid());
+ expand = UtilGetLoginName(pwd);
+ endpwent();
#else
DWORD n = ARRAYSIZE(bufW);
if (GetUserNameW(bufW, &n)) {