From: Ian Darwin Date: Fri, 19 Feb 1993 12:09:04 +0000 (+0000) Subject: Fix for broken symlink bug, from martin@d255s004.zfe.siemens.de. X-Git-Tag: FILE3_27~191 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40de11c5b44c9ca62e4a2f522b6782e8c07289cd;p=file Fix for broken symlink bug, from martin@d255s004.zfe.siemens.de. --- diff --git a/src/fsmagic.c b/src/fsmagic.c index fceb0545..684e118d 100644 --- a/src/fsmagic.c +++ b/src/fsmagic.c @@ -46,7 +46,7 @@ #ifndef lint static char *moduleid = - "@(#)$Id: fsmagic.c,v 1.21 1992/11/09 11:53:31 ian Exp $"; + "@(#)$Id: fsmagic.c,v 1.22 1993/02/19 12:09:04 ian Exp $"; #endif /* lint */ int @@ -112,11 +112,32 @@ struct stat *sb; buf[nch] = '\0'; /* readlink(2) forgets this */ /* If broken symlink, say so and quit early. */ - if (stat(buf, &tstatbuf) < 0) { + if (*buf == '/') { + if (stat(buf, &tstatbuf) < 0) { ckfprintf(stdout, "broken symbolic link to %s", buf); return 1; + } } + else { + char *tmp; + char buf2[BUFSIZ+BUFSIZ+4]; + + if ((tmp = strrchr(fn, '/')) == NULL) { + tmp = buf; /* in current directory anyway */ + } + else { + strcpy (buf2, fn); /* take directory part */ + buf2[tmp-fn+1] = '\0'; + strcat (buf2, buf); /* plus (relative) symlink */ + tmp = buf2; + } + if (stat(tmp, &tstatbuf) < 0) { + ckfprintf(stdout, + "broken symbolic link to %s", buf); + return 1; + } + } /* Otherwise, handle it. */ if (lflag) {