linkup

Simple symlink farmer
git clone https://git.sinitax.com/sinitax/linkup
Log | Files | Refs | LICENSE | sfeed.txt

commit c7d235f4c0cdadaea467d737d04efa6178eee67a
parent 02748101b3fb3a8a8aaaacc5c4e1e62dd0ea45fc
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sat, 22 Oct 2022 17:17:15 +0200

Null terminate result of readlink

Diffstat:
Mlinkup.c | 15++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/linkup.c b/linkup.c @@ -33,12 +33,10 @@ normalize(const char *src, char *dst) char *end; int len; - /* only for absolute paths */ - end = dst; tok = src; *end = '\0'; - while (1) { + do { sep = strchr(tok, '/'); len = sep ? sep - tok : strlen(tok); if (!len || !strncmp(tok, ".", len)) @@ -55,18 +53,19 @@ normalize(const char *src, char *dst) } next: tok = sep + 1; - if (!sep) break; - } + } while (sep); } void realparent(int dirfd, const char *dirpath, const char *file, char *parent) { - char tmpbuf[PATH_MAX]; + char tmpbuf[PATH_MAX+1]; + ssize_t len; char *sep; - if (readlinkat(dirfd, file, tmpbuf, PATH_MAX) < 0) + if ((len = readlinkat(dirfd, file, tmpbuf, PATH_MAX)) == -1) err(1, "readlink"); + tmpbuf[len] = '\0'; if (tmpbuf[0] != '/') { /* relative path */ strncpy(parent, tmpbuf, PATH_MAX); @@ -82,7 +81,6 @@ void do_install(const char *spath, const char *dpath) { char spbuf[PATH_MAX], dpbuf[PATH_MAX]; - char tmpbuf[PATH_MAX]; struct dirent *ent; struct stat attr; DIR *sdir, *ddir; @@ -161,7 +159,6 @@ do_uninstall(const char *spath, const char *dpath) continue; realparent(dirfd(ddir), dpath, ent->d_name, dpbuf); - if (!strcmp(dpbuf, spath)) unlinkat(dirfd(ddir), ent->d_name, 0); }