From b3da913dfa6ffd1ef0f380363c9bf3791ddc7aad Mon Sep 17 00:00:00 2001 From: Lukas Nykryn Date: Sun, 9 Apr 2023 15:12:53 +0200 Subject: [PATCH] alternatives: isLink should return 0 in case of lstat error isLink returns non-zero value when a file is a symlink. However, the old code also returned -1 when lsat failed. --- alternatives.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/alternatives.c b/alternatives.c index 22ff2b41..13047e52 100644 --- a/alternatives.c +++ b/alternatives.c @@ -484,13 +484,10 @@ static int readConfig(struct alternativeSet *set, const char *title, static int isLink(char *path) { struct stat sbuf; - int rc = 0; - rc = lstat(path, &sbuf); - if (!rc) { - rc = S_ISLNK(sbuf.st_mode); - } - return rc; + if (lstat(path, &sbuf)) + return 0; + return !!S_ISLNK(sbuf.st_mode); } static int facilityBelongsToUs(char *facility, const char *altDir) {