version 1.14, 2010/02/19 17:14:23 |
version 1.15, 2010/12/13 22:53:14 |
|
|
char * |
char * |
cmd_string_variable(const char *s, size_t *p) |
cmd_string_variable(const char *s, size_t *p) |
{ |
{ |
int ch, fch; |
int ch, fch; |
char *buf, *t; |
char *buf, *t; |
size_t len; |
size_t len; |
|
struct environ_entry *envent; |
|
|
#define cmd_string_first(ch) ((ch) == '_' || \ |
#define cmd_string_first(ch) ((ch) == '_' || \ |
((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z')) |
((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z')) |
|
|
buf = xrealloc(buf, 1, len + 1); |
buf = xrealloc(buf, 1, len + 1); |
buf[len] = '\0'; |
buf[len] = '\0'; |
|
|
if ((t = getenv(buf)) == NULL) { |
envent = environ_find(&global_environ, buf); |
xfree(buf); |
|
return (xstrdup("")); |
|
} |
|
xfree(buf); |
xfree(buf); |
return (xstrdup(t)); |
if (envent == NULL) |
|
return (xstrdup("")); |
|
return (xstrdup(envent->value)); |
|
|
error: |
error: |
if (buf != NULL) |
if (buf != NULL) |
|
|
char * |
char * |
cmd_string_expand_tilde(const char *s, size_t *p) |
cmd_string_expand_tilde(const char *s, size_t *p) |
{ |
{ |
struct passwd *pw; |
struct passwd *pw; |
char *home, *path, *username; |
struct environ_entry *envent; |
|
char *home, *path, *username; |
|
|
home = NULL; |
home = NULL; |
if (cmd_string_getc(s, p) == '/') { |
if (cmd_string_getc(s, p) == '/') { |
if ((home = getenv("HOME")) == NULL || *home == '\0') { |
envent = environ_find(&global_environ, "HOME"); |
if ((pw = getpwuid(getuid())) != NULL) |
if (envent != NULL && *envent->value != '\0') |
home = pw->pw_dir; |
home = envent->value; |
} |
else if ((pw = getpwuid(getuid())) != NULL) |
|
home = pw->pw_dir; |
} else { |
} else { |
cmd_string_ungetc(p); |
cmd_string_ungetc(p); |
if ((username = cmd_string_string(s, p, '/', 0)) == NULL) |
if ((username = cmd_string_string(s, p, '/', 0)) == NULL) |