From: Baptiste Daroussin Date: Wed, 5 Jul 2023 12:53:29 +0000 (+0200) Subject: subscription: reduce code duplication X-Git-Tag: RELEASE_1_4_0rc1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f24cc95e55fe743d33474bdd7cc05f952dfdf05;p=thirdparty%2Fmlmmj.git subscription: reduce code duplication --- diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index 30f71f7b..566a985e 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -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