Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    r8219374 rc0c48d14  
    3232}
    3333
    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 stop
    44      * 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 
    5934/* Return a "nice" version of the path.  Tilde expansion is done, and
    6035 * duplicate slashes are removed.  Caller must free the return.
     
    6742    /* Attempt tilde-expansion of the first component. Get the
    6843       tilde-prefix, which goes up to the next slash. */
     44    struct passwd *pw;
    6945    const char *end = strchr(in + 1, '/');
    7046    if (end == NULL)
    7147      end = in + strlen(in);
    7248
    73     /* Patch together a new path. Replace the ~ and tilde-prefix with
    74        the homedir, if available. */
    7549    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());
    7952    } else {
    8053      /* Someone else's home directory. */
    8154      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);
    8956      g_free(user);
    9057    }
     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    }
    9166  } else {
    92     out = g_strdup(in);
     67      out = g_strdup(in);
    9368  }
    9469
     
    413388    if (!g_path_is_absolute(link_path)) {
    414389      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);
    416394      g_free(last_dir);
    417395      g_free(link_path);
Note: See TracChangeset for help on using the changeset viewer.