Changeset 396505be


Ignore:
Timestamp:
Jul 16, 2011, 12:28:10 AM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
99ac28a
Parents:
e59d775
git-author:
David Benjamin <davidben@mit.edu> (07/10/11 19:00:08)
git-committer:
David Benjamin <davidben@mit.edu> (07/16/11 00:28:10)
Message:
Use owl_global_get_homedir for ~ in owl_util_makepath

It's strange that ~/.zephyr.subs and ~/.owl/startup are computed
differently. We should use the same one. This also matches bash in that
~ prefers $HOME over passwd. If don't have a homedir at all, this
defaults to / instead of keeping the ~, but that won't happen and at
least it's consistent with existing behavior for zephyr dotfiles.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    r14c9e05 r396505be  
    227227                "\"");
    228228
    229   GString *g = g_string_new("");
    230   owl_string_appendf_quoted(g, "%q foo %q%q %s %", "hello", "world is", "can't");
     229  GString *quoted = g_string_new("");
     230  owl_string_appendf_quoted(quoted, "%q foo %q%q %s %", "hello", "world is", "can't");
    231231  FAIL_UNLESS("owl_string_appendf",
    232               !strcmp(g->str, "hello foo 'world is'\"can't\" %s %"));
    233   g_string_free(g, true);
     232              !strcmp(quoted->str, "hello foo 'world is'\"can't\" %s %"));
     233  g_string_free(quoted, true);
    234234
    235235
     
    275275
    276276  errno = 0;
    277   pw = getpwuid(getuid());
    278   if (pw) {
    279     home = pw->pw_dir;
    280   } else {
    281     /* Just make some noise so we notice. */
    282     home = "<WHAT>";
    283     fprintf(stderr, "getpwuid: %s", errno ? strerror(errno) : "No such user");
    284   }
     277  home = owl_global_get_homedir(&g);
    285278  s = owl_util_makepath("~");
    286279  FAIL_UNLESS("makepath ~", !strcmp(home, s));
  • util.c

    rdde1b4d r396505be  
    4242    /* Attempt tilde-expansion of the first component. Get the
    4343       tilde-prefix, which goes up to the next slash. */
    44     struct passwd *pw;
    4544    const char *end = strchr(in + 1, '/');
    4645    if (end == NULL)
    4746      end = in + strlen(in);
    4847
     48    /* Patch together a new path. Replace the ~ and tilde-prefix with
     49       the homedir, if available. */
    4950    if (end == in + 1) {
    50       /* My home directory. */
    51       pw = getpwuid(getuid());
     51      /* My home directory. Use the one in owl_global for consistency with
     52       * owl_zephyr_dotfile. */
     53      out = g_strconcat(owl_global_get_homedir(&g), end, NULL);
    5254    } else {
    5355      /* Someone else's home directory. */
    5456      char *user = g_strndup(in + 1, end - (in + 1));
    55       pw = getpwnam(user);
     57      struct passwd *pw = getpwnam(user);
    5658      g_free(user);
    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);
     59      if (pw) {
     60        out = g_strconcat(pw->pw_dir, end, NULL);
     61      } else {
     62        out = g_strdup(in);
     63      }
    6564    }
    6665  } else {
    67       out = g_strdup(in);
     66    out = g_strdup(in);
    6867  }
    6968
Note: See TracChangeset for help on using the changeset viewer.