From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2160D3851C2C for ; Tue, 22 Jun 2021 05:27:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2160D3851C2C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-301-0iDFlYg1P0CiR7-ejv6Pdw-1; Tue, 22 Jun 2021 01:27:35 -0400 X-MC-Unique: 0iDFlYg1P0CiR7-ejv6Pdw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 839C918414A1; Tue, 22 Jun 2021 05:27:34 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-111.rdu2.redhat.com [10.10.112.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51FBD5D6AD; Tue, 22 Jun 2021 05:27:34 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 15M5RWIm409498; Tue, 22 Jun 2021 01:27:33 -0400 From: DJ Delorie To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v2 4/6] iconvconfig: Use common gconv module parsing function In-Reply-To: <20210622051202.4155709-5-siddhesh@sourceware.org> Date: Tue, 22 Jun 2021 01:27:32 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jun 2021 05:27:42 -0000 Siddhesh Poyarekar via Libc-alpha writes: > Drop local copy of gconv file parsing and use the one in > gconv_parseconfdir.h instead. Now there is a single implementation of > configuration file parsing. > --- > iconv/iconvconfig.c | 128 +++++--------------------------------------- > 1 file changed, 13 insertions(+), 115 deletions(-) > > diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c > index c9607fb645..e69334d71c 100644 > --- a/iconv/iconvconfig.c > +++ b/iconv/iconvconfig.c > @@ -18,7 +18,6 @@ > > #include > #include > -#include > #include > #include > #include > @@ -34,10 +33,10 @@ > #include > #include > #include > -#include > #include > > #include "iconvconfig.h" > +#include Ok. > /* Get libc version number. */ > #include "../version.h" > @@ -568,7 +567,9 @@ new_module (const char *fromname, size_t fromlen, const char *toname, > > /* Add new module. */ > static void > -add_module (char *rp, const char *directory) > +add_module (char *rp, const char *directory, > + size_t dirlen __attribute__ ((__unused__)), > + int modcount __attribute__ ((__unused__))) Ok. > -/* Read a gconv-modules configuration file. */ > -static bool > -handle_file (const char *dir, const char *infile) > -{ > - FILE *fp; > - char *line = NULL; > - size_t linelen = 0; > - > - fp = fopen (infile, "r"); > - if (fp == NULL) > - return false; > - > - /* No threads present. */ > - __fsetlocking (fp, FSETLOCKING_BYCALLER); > - > - while (!feof_unlocked (fp)) > - { > - char *rp, *endp, *word; > - ssize_t n = __getdelim (&line, &linelen, '\n', fp); > - > - if (n < 0) > - /* An error occurred. */ > - break; > - > - rp = line; > - /* Terminate the line (excluding comments or newline) with a NUL > - byte to simplify the following code. */ > - endp = strchr (rp, '#'); > - if (endp != NULL) > - *endp = '\0'; > - else > - if (rp[n - 1] == '\n') > - rp[n - 1] = '\0'; > - > - while (isspace (*rp)) > - ++rp; > - > - /* If this is an empty line go on with the next one. */ > - if (rp == endp) > - continue; > - > - word = rp; > - while (*rp != '\0' && !isspace (*rp)) > - ++rp; > - > - if (rp - word == sizeof ("alias") - 1 > - && memcmp (word, "alias", sizeof ("alias") - 1) == 0) > - add_alias (rp); > - else if (rp - word == sizeof ("module") - 1 > - && memcmp (word, "module", sizeof ("module") - 1) == 0) > - add_module (rp, dir); > - /* else */ > - /* Otherwise ignore the line. */ > - } > - > - free (line); > - > - fclose (fp); > - > - return true; > -} > - Ok. > /* Read config files and add the data for this directory to cache. */ > static int > handle_dir (const char *dir) > { > - char *cp; > size_t dirlen = strlen (dir); > bool found = false; > > + /* Add the prefix before sending it off to the parser. */ > + char *fulldir = xmalloc (prefix_len + dirlen + 2); > + char *cp = mempcpy (mempcpy (fulldir, prefix, prefix_len), dir, dirlen); > + +2 for '/' and NUL, ok. > if (dir[dirlen - 1] != '/') > { > - char *newp = (char *) xmalloc (dirlen + 2); > - dir = memcpy (newp, dir, dirlen); > - newp[dirlen++] = '/'; > - newp[dirlen] = '\0'; > + *cp++ = '/'; > + *cp = '\0'; > + dirlen++; > } Ok. > - /* First, look for a gconv-modules file. */ > - char *buf = malloc (prefix_len + dirlen + sizeof "gconv-modules.d"); > - if (buf == NULL) > - goto out; > - > - cp = buf; > - if (dir[0] == '/') > - cp = mempcpy (cp, prefix, prefix_len); > - cp = mempcpy (cp, dir, dirlen); > - cp = stpcpy (cp, "gconv-modules"); > - > - found |= handle_file (dir, buf); > - > - /* Next, see if there is a gconv-modules.d directory containing configuration > - files and if it is non-empty. */ > - cp[0] = '.'; > - cp[1] = 'd'; > - cp[2] = '\0'; > - > - DIR *confdir = opendir (buf); > - if (confdir != NULL) > - { > - struct dirent *ent; > - while ((ent = readdir (confdir)) != NULL) > - { > - if (ent->d_type != DT_REG) > - continue; > - > - size_t len = strlen (ent->d_name); > - const char *suffix = ".conf"; > - > - if (len > strlen (suffix) > - && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) > - { > - char *conf; > - if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) > - continue; > - found |= handle_file (dir, conf); > - free (conf); > - } > - } > - closedir (confdir); > - } > + found = gconv_parseconfdir (fulldir, dirlen + prefix_len); Ok. > - free (buf); > + free (fulldir); > > -out: > if (!found) > { > error (0, errno, "failed to open gconv configuration files in `%s'", Ok. Reviewed-by: DJ Delorie