aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2017-10-07 22:56:29 -0700
committerPaul Eggert2017-10-07 22:57:12 -0700
commit7c2c117c91eeef5e7bd70c98cc7e201007016b1e (patch)
treed1078dd11347fc4d39f97f3db518d2f677f590aa
parent2202952b8307f3a6407820280e94e4d979b7a122 (diff)
downloademacs-7c2c117c91eeef5e7bd70c98cc7e201007016b1e.tar.gz
emacs-7c2c117c91eeef5e7bd70c98cc7e201007016b1e.zip
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)
221} 221}
222 222
223/* Return the current working directory. The result should be freed 223/* Return the current working directory. The result should be freed
224 with 'free'. Return NULL on errors. */ 224 with 'free'. Return NULL (setting errno) on errors. If the
225char * 225 current directory is unreachable, return either NULL or a string
226emacs_get_current_dir_name (void) 226 beginning with '('. */
227
228static char *
229get_current_dir_name_or_unreachable (void)
227{ 230{
228# if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME 231# if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME
229# ifdef HYBRID_MALLOC 232# ifdef HYBRID_MALLOC
@@ -233,16 +236,9 @@ emacs_get_current_dir_name (void)
233# endif 236# endif
234 if (use_libc) 237 if (use_libc)
235 { 238 {
236 /* GNU/Linux get_current_dir_name can return a string starting 239 /* For an unreachable directory, this returns a string that starts
237 with "(unreachable)" (Bug#27871). */ 240 with "(unreachable)"; see Bug#27871. */
238 char *wd = get_current_dir_name (); 241 return get_current_dir_name ();
239 if (wd && ! (IS_DIRECTORY_SEP (*wd) || (*wd && IS_DEVICE_SEP (wd[1]))))
240 {
241 free (wd);
242 errno = ENOENT;
243 return NULL;
244 }
245 return wd;
246 } 242 }
247# endif 243# endif
248 244
@@ -294,6 +290,23 @@ emacs_get_current_dir_name (void)
294 return buf; 290 return buf;
295} 291}
296 292
293/* Return the current working directory. The result should be freed
294 with 'free'. Return NULL (setting errno) on errors; an unreachable
295 directory (e.g., its name starts with '(') counts as an error. */
296
297char *
298emacs_get_current_dir_name (void)
299{
300 char *dir = get_current_dir_name_or_unreachable ();
301 if (dir && *dir == '(')
302 {
303 free (dir);
304 errno = ENOENT;
305 return NULL;
306 }
307 return dir;
308}
309
297 310
298/* Discard pending input on all input descriptors. */ 311/* Discard pending input on all input descriptors. */
299 312