From 48f9c5a79df7431c60aee74ddea0d4a47384a373 Mon Sep 17 00:00:00 2001
From: sin <sin@2f30.org>
Date: Wed, 22 Oct 2014 17:25:25 +0100
Subject: [PATCH] Test if we can back out/enter directories

---
 noice.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/noice.c b/noice.c
index 90fc3bd..9a9fc6a 100644
--- a/noice.c
+++ b/noice.c
@@ -615,6 +615,10 @@ nochange:
 			/* There is no going back */
 			if (strcmp(path, "/") == 0)
 				goto nochange;
+			if (testopendir(path) == 0) {
+				printwarn();
+				goto nochange;
+			}
 			dir = xdirname(path);
 			free(path);
 			path = dir;
@@ -642,6 +646,10 @@ nochange:
 
 			switch (sb.st_mode & S_IFMT) {
 			case S_IFDIR:
+				if (testopendir(path) == 0) {
+					printwarn();
+					goto nochange;
+				}
 				free(path);
 				path = xrealpath(name);
 				/* Reset filter */
@@ -745,7 +753,7 @@ main(int argc, char *argv[])
 	}
 
 	/* Test initial path */
-	if (!testopendir(ipath))
+	if (testopendir(ipath) == 0)
 		printerr(1, ipath);
 
 	/* Set locale before curses setup */