printf(" Exit status is 0 on success, 1 on failure\n");
}
+/* using realpath() implies the paths must be resolved/exist
+ * so this will fail for dangling links
+ */
+int check_canonical(char *lname, char *checklink, int verbose)
+{
+ char *lname_canon;
+ char *checklink_canon;
+
+ lname_canon = realpath(lname, NULL);
+ if (lname_canon == NULL) {
+ if (verbose)
+ printf("%s: can't canonicalize: %s\n",
+ lname, strerror(errno));
+ return 1;
+ }
+
+ checklink_canon = realpath(checklink, NULL);
+ if (checklink_canon == NULL) {
+ if (verbose)
+ printf("%s: can't canonicalize: %s\n",
+ checklink, strerror(errno));
+ return 1;
+ }
+
+ if (strcmp(checklink_canon, lname_canon)) {
+ free(lname_canon);
+ free(checklink_canon);
+ return 1;
+ }
+ free(lname_canon);
+ free(checklink_canon);
+ return 0;
+}
+
int
main(int argc, char **argv)
{
}
lname[rc] = 0;
- if (strcmp(checklink, lname)) {
+
+ /* just in case, try to also match the canonicalized
+ * paths
+ */
+ if (strcmp(checklink, lname) &&
+ check_canonical(lname, checklink, verbose)) {
if (verbose)
printf("%s is a link to %s and not %s\n",
fname, lname, checklink);