summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-10-07 22:56:29 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-10-07 22:57:12 -0700
commit7c2c117c91eeef5e7bd70c98cc7e201007016b1e (patch)
treed1078dd11347fc4d39f97f3db518d2f677f590aa
parent2202952b8307f3a6407820280e94e4d979b7a122 (diff)
downloademacs-7c2c117c91eeef5e7bd70c98cc7e201007016b1e.tar.gz
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)
-rw-r--r--src/sysdep.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 8291a606bea..c3484920d0c 100644
--- a/src/sysdep.c
+++ b/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. */