]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
subscription: reduce code duplication
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 5 Jul 2023 12:53:29 +0000 (14:53 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 5 Jul 2023 12:53:29 +0000 (14:53 +0200)
src/subscriberfuncs.c

index 30f71f7b093737198d5d5acbdc596700289b9f5b..566a985e6c1d816d34e159941287e04b32d87dd2 100644 (file)
@@ -155,9 +155,7 @@ char *
 get_subcookie_content(int listfd, bool unsub, const char *param)
 {
        int dfd, fd;
-       FILE *f;
        char *line = NULL;
-       size_t linecap = 0;
 
        dfd = openat(listfd, unsub ? "unsubconf" : "subconf", O_DIRECTORY|O_CLOEXEC);
        if (dfd == -1) {
@@ -169,18 +167,12 @@ get_subcookie_content(int listfd, bool unsub, const char *param)
                close(dfd);
                return (NULL);
        }
-       f = fdopen(fd, "r");
-       if (getline(&line, &linecap, f) > 0) {
-               chomp(line);
-               fclose(f);
+       line = readlf(fd, true);
+       if (line != NULL)
                unlinkat(dfd, param, 0);
-               close(dfd);
-               return (line);
-       }
        close(dfd);
-       fclose(f);
 
-       return (NULL);
+       return (line);
 }
 
 void