mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-29 07:58:28 +00:00
Improve test for unreachable dirs
* src/sysdep.c (get_current_dir_name_or_unreachable): New function, with most of the old contents of emacs_get_current_dir_name. (emacs_get_current_dir_name): Use it. Use a simpler test for unreachable directory strings, and also apply it to getcwd etc. (Bug#27871)
This commit is contained in:
parent
2202952b83
commit
7c2c117c91
39
src/sysdep.c
39
src/sysdep.c
@ -221,9 +221,12 @@ init_standard_fds (void)
|
||||
}
|
||||
|
||||
/* Return the current working directory. The result should be freed
|
||||
with 'free'. Return NULL on errors. */
|
||||
char *
|
||||
emacs_get_current_dir_name (void)
|
||||
with 'free'. Return NULL (setting errno) on errors. If the
|
||||
current directory is unreachable, return either NULL or a string
|
||||
beginning with '('. */
|
||||
|
||||
static char *
|
||||
get_current_dir_name_or_unreachable (void)
|
||||
{
|
||||
# if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME
|
||||
# ifdef HYBRID_MALLOC
|
||||
@ -233,16 +236,9 @@ emacs_get_current_dir_name (void)
|
||||
# endif
|
||||
if (use_libc)
|
||||
{
|
||||
/* GNU/Linux get_current_dir_name can return a string starting
|
||||
with "(unreachable)" (Bug#27871). */
|
||||
char *wd = get_current_dir_name ();
|
||||
if (wd && ! (IS_DIRECTORY_SEP (*wd) || (*wd && IS_DEVICE_SEP (wd[1]))))
|
||||
{
|
||||
free (wd);
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
return wd;
|
||||
/* For an unreachable directory, this returns a string that starts
|
||||
with "(unreachable)"; see Bug#27871. */
|
||||
return get_current_dir_name ();
|
||||
}
|
||||
# endif
|
||||
|
||||
@ -294,6 +290,23 @@ emacs_get_current_dir_name (void)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Return the current working directory. The result should be freed
|
||||
with 'free'. Return NULL (setting errno) on errors; an unreachable
|
||||
directory (e.g., its name starts with '(') counts as an error. */
|
||||
|
||||
char *
|
||||
emacs_get_current_dir_name (void)
|
||||
{
|
||||
char *dir = get_current_dir_name_or_unreachable ();
|
||||
if (dir && *dir == '(')
|
||||
{
|
||||
free (dir);
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
/* Discard pending input on all input descriptors. */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user