Skip to content

Commit

Permalink
alternatives: isLink should return 0 in case of lstat error
Browse files Browse the repository at this point in the history
isLink returns non-zero value when a file is a symlink. However,
the old code also returned -1 when lsat failed.

(cherry picked from commit c55ba54)
  • Loading branch information
lnykryn authored and jamacku committed May 15, 2023
1 parent 001ecec commit 52d2562
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions alternatives.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 52d2562

Please sign in to comment.