mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
* utilunix.c (tilde_expand): Preserve tilde if the username
could not be found. Don't ever return NULL. Change callers not to check for NULL.
This commit is contained in:
parent
e55f09f530
commit
42da92333f
@ -1,5 +1,9 @@
|
||||
2003-11-27 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* utilunix.c (tilde_expand): Preserve tilde if the username
|
||||
could not be found. Don't ever return NULL. Change callers not
|
||||
to check for NULL.
|
||||
|
||||
* dialog.c (do_select_widget): New function that it the only one
|
||||
calling dlg_focus() and dlg_unfocus(). Incorporate code from
|
||||
other functions that did it.
|
||||
|
@ -87,12 +87,6 @@ filename_completion_function (char *text, int state)
|
||||
users_dirname = dirname;
|
||||
{
|
||||
dirname = tilde_expand (dirname);
|
||||
if (!dirname){
|
||||
g_free (users_dirname);
|
||||
g_free (filename);
|
||||
users_dirname = filename = NULL;
|
||||
return NULL;
|
||||
}
|
||||
canonicalize_pathname (dirname);
|
||||
/* Here we should do something with variable expansion
|
||||
and `command`.
|
||||
@ -485,11 +479,6 @@ command_completion_function (char *text, int state)
|
||||
if (cur_path >= path_end)
|
||||
break;
|
||||
expanded = tilde_expand (*cur_path ? cur_path : ".");
|
||||
if (!expanded){
|
||||
g_free (path);
|
||||
path = NULL;
|
||||
return NULL;
|
||||
}
|
||||
p = canonicalize_pathname (expanded);
|
||||
cur_word = concat_dir_and_file (p, text);
|
||||
g_free (p);
|
||||
|
@ -253,8 +253,13 @@ int my_system (int flags, const char *shell, const char *command)
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
|
||||
/* Returns a newly allocated string, if directory does not exist, return 0 */
|
||||
char *tilde_expand (const char *directory)
|
||||
|
||||
/*
|
||||
* Perform tilde expansion if possible.
|
||||
* Always return a newly allocated string, even if it's unchanged.
|
||||
*/
|
||||
char *
|
||||
tilde_expand (const char *directory)
|
||||
{
|
||||
struct passwd *passwd;
|
||||
const char *p;
|
||||
@ -268,24 +273,24 @@ char *tilde_expand (const char *directory)
|
||||
p = strchr (directory, PATH_SEP);
|
||||
|
||||
/* d = "~" or d = "~/" */
|
||||
if (!(*directory) || (*directory == PATH_SEP)){
|
||||
if (!(*directory) || (*directory == PATH_SEP)) {
|
||||
passwd = getpwuid (geteuid ());
|
||||
p = (*directory == PATH_SEP) ? directory+1 : "";
|
||||
p = (*directory == PATH_SEP) ? directory + 1 : "";
|
||||
} else {
|
||||
if (!p){
|
||||
if (!p) {
|
||||
passwd = getpwnam (directory);
|
||||
} else {
|
||||
name = g_malloc (p - directory + 1);
|
||||
strncpy (name, directory, p - directory);
|
||||
name [p - directory] = 0;
|
||||
name[p - directory] = 0;
|
||||
passwd = getpwnam (name);
|
||||
g_free (name);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we can't figure the user name, return NULL */
|
||||
/* If we can't figure the user name, leave tilde unexpanded */
|
||||
if (!passwd)
|
||||
return 0;
|
||||
return g_strdup (directory);
|
||||
|
||||
return g_strconcat (passwd->pw_dir, PATH_SEP_STR, p, NULL);
|
||||
}
|
||||
|
11
src/wtools.c
11
src/wtools.c
@ -524,18 +524,17 @@ char *input_dialog (char *header, char *text, char *def_text)
|
||||
return input_dialog_help (header, text, "[Input Line Keys]", def_text);
|
||||
}
|
||||
|
||||
char *input_expand_dialog (char *header, char *text, char *def_text)
|
||||
char *
|
||||
input_expand_dialog (char *header, char *text, char *def_text)
|
||||
{
|
||||
char *result;
|
||||
char *expanded;
|
||||
|
||||
result = input_dialog (header, text, def_text);
|
||||
if (result){
|
||||
if (result) {
|
||||
expanded = tilde_expand (result);
|
||||
if (expanded){
|
||||
g_free (result);
|
||||
return expanded;
|
||||
}
|
||||
g_free (result);
|
||||
return expanded;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user