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.
  • Loading branch information
lnykryn committed Apr 13, 2023
1 parent bd9b978 commit b3da913
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 b3da913

Please sign in to comment.