From 2d11f8181b668445103f33bd092c97e9ef8e8ee6 Mon Sep 17 00:00:00 2001 From: Marcel Rodrigues Date: Sat, 4 Jun 2016 10:13:30 -0300 Subject: [PATCH] Check errors while trying to go to link target. --- rover.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rover.c b/rover.c index 63751db..c809e31 100644 --- a/rover.c +++ b/rover.c @@ -1090,6 +1090,22 @@ main(int argc, char *argv[]) ssize_t len = readlink(ENAME(ESEL), BUF1, BUFLEN-1); if (len == -1) continue; BUF1[len] = '\0'; + if (access(BUF1, F_OK) == -1) { + char *msg; + switch (errno) { + case EACCES: + msg = "Cannot access \"%s\"."; + break; + case ENOENT: + msg = "\"%s\" does not exist."; + break; + default: + msg = "Cannot navigate to \"%s\"."; + } + strcpy(BUF2, BUF1); /* message() uses BUF1. */ + message(RED, msg, BUF2); + continue; + } realpath(BUF1, CWD); len = strlen(CWD); if (CWD[len - 1] == '/') -- 2.11.4.GIT