From: Baptiste Daroussin Date: Mon, 26 Dec 2022 15:35:43 +0000 (+0100) Subject: fgetlistaddr: add a filedescriptor only version of getlistaddr X-Git-Tag: RELEASE_1_4_0_a2~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aea01bced4882dfe7c19772785e01219d3a8419f;p=thirdparty%2Fmlmmj.git fgetlistaddr: add a filedescriptor only version of getlistaddr which reduces memory manipulation --- diff --git a/include/getlistaddr.h b/include/getlistaddr.h index cee8177d..3d11ae79 100644 --- a/include/getlistaddr.h +++ b/include/getlistaddr.h @@ -25,5 +25,6 @@ #define GETLISTADDR_H char *getlistaddr(const char *listdir); +char *fgetlistaddr(int fd); #endif /* GETLISTADDR_H */ diff --git a/src/getlistaddr.c b/src/getlistaddr.c index 3daa3f23..1d5bb9e3 100644 --- a/src/getlistaddr.c +++ b/src/getlistaddr.c @@ -1,6 +1,6 @@ -/* Copyright (C) 2002, 2003 Mads Martin Joergensen - * - * $Id$ +/* + * Copyright (C) 2002, 2003 Mads Martin Joergensen + * Copyright (C) 2022 Baptiste Daroussin * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -33,6 +33,33 @@ #include "mygetline.h" #include "strgen.h" +char * +fgetlistaddr(int fd) +{ + char *tmpstr; + int listnamefd; + + if ((listnamefd = openat(fd, "listaddress", O_RDONLY|O_CLOEXEC)) < 0) { + log_error(LOG_ARGS, "Could not open 'control/listaddress'"); + exit(EXIT_FAILURE); + } + tmpstr = mygetline(listnamefd); + if (tmpstr == NULL) { + log_error(LOG_ARGS, "FATAL. Could not get listaddress " + "in control/listaddress"); + exit(EXIT_FAILURE); + } + if (strchr(tmpstr, '@') == NULL) { + log_error(LOG_ARGS, "FATAL. No @ sign in listaddress"); + exit(EXIT_FAILURE); + } + + chomp(tmpstr); + close(listnamefd); + + return (tmpstr); +} + char *getlistaddr(const char *listdir) { char *tmpstr;