Changes in util.c [8219374:c0c48d14]
Legend:
- Unmodified
- Added
- Removed
-
util.c
r8219374 rc0c48d14 32 32 } 33 33 34 CALLER_OWN char *owl_util_homedir_for_user(const char *name)35 {36 int err;37 struct passwd pw_buf;38 struct passwd *pw;39 40 char *pw_strbuf, *ret;41 long pw_strbuf_len = sysconf(_SC_GETPW_R_SIZE_MAX);42 if (pw_strbuf_len < 0) {43 /* If we really hate ourselves, we can be fancy and loop until we stop44 * getting ERANGE. For now just pick a random number. */45 owl_function_error("owl_util_homedir_for_user: Could not get _SC_GETPW_R_SIZE_MAX");46 pw_strbuf_len = 16384;47 }48 pw_strbuf = g_new0(char, pw_strbuf_len);49 err = getpwnam_r(name, &pw_buf, pw_strbuf, pw_strbuf_len, &pw);50 if (err) {51 owl_function_error("getpwuid_r: %s", strerror(err));52 /* Fall through; pw will be NULL. */53 }54 ret = pw ? g_strdup(pw->pw_dir) : NULL;55 g_free(pw_strbuf);56 return ret;57 }58 59 34 /* Return a "nice" version of the path. Tilde expansion is done, and 60 35 * duplicate slashes are removed. Caller must free the return. … … 67 42 /* Attempt tilde-expansion of the first component. Get the 68 43 tilde-prefix, which goes up to the next slash. */ 44 struct passwd *pw; 69 45 const char *end = strchr(in + 1, '/'); 70 46 if (end == NULL) 71 47 end = in + strlen(in); 72 48 73 /* Patch together a new path. Replace the ~ and tilde-prefix with74 the homedir, if available. */75 49 if (end == in + 1) { 76 /* My home directory. Use the one in owl_global for consistency with 77 * owl_zephyr_dotfile. */ 78 out = g_strconcat(owl_global_get_homedir(&g), end, NULL); 50 /* My home directory. */ 51 pw = getpwuid(getuid()); 79 52 } else { 80 53 /* Someone else's home directory. */ 81 54 char *user = g_strndup(in + 1, end - (in + 1)); 82 char *home = owl_util_homedir_for_user(user); 83 if (home) { 84 out = g_strconcat(home, end, NULL); 85 } else { 86 out = g_strdup(in); 87 } 88 g_free(home); 55 pw = getpwnam(user); 89 56 g_free(user); 90 57 } 58 59 /* Patch together a new path. Replace the ~ and tilde-prefix with 60 the homedir. */ 61 if (pw) { 62 out = g_strconcat(pw->pw_dir, end, NULL); 63 } else { 64 out = g_strdup(in); 65 } 91 66 } else { 92 out = g_strdup(in);67 out = g_strdup(in); 93 68 } 94 69 … … 413 388 if (!g_path_is_absolute(link_path)) { 414 389 char *last_dir = g_path_get_dirname(last_path); 415 char *tmp = g_build_filename(last_dir, link_path, NULL); 390 char *tmp = g_build_path(G_DIR_SEPARATOR_S, 391 last_dir, 392 link_path, 393 NULL); 416 394 g_free(last_dir); 417 395 g_free(link_path);
Note: See TracChangeset
for help on using the changeset viewer.