From patchwork Tue Jun 22 05:12:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1495450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ImTVBi1/; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G8F3T4vF6z9sTD for ; Tue, 22 Jun 2021 15:15:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 471E53947414 for ; Tue, 22 Jun 2021 05:15:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 471E53947414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624338947; bh=hCWJMFebNmWBc1EotrR3qHXldCT4cHrSmDxmPcq+9Ik=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ImTVBi1/j4AxShCmxELetLeLZ82SnnL3rhqV+qiy5VrlnNCZ9ft3n6bIYv9N0j5Mn HajssfkMGsmQXx1Y7yFM4wuAgr0u5lXnwA81fpMIuAdDlZ3QSj4gICeZBdO6bgCUq3 fP4pl2QS7JDx6bkfEV/GFoIJV/x744+SqusMJQs8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by sourceware.org (Postfix) with ESMTPS id 1CA82393D012 for ; Tue, 22 Jun 2021 05:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1CA82393D012 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id C91C2121CC6 for ; Tue, 22 Jun 2021 05:12:32 +0000 (UTC) Received: from pdx1-sub0-mail-a46.g.dreamhost.com (100-96-11-21.trex.outbound.svc.cluster.local [100.96.11.21]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 5AB1C12205C for ; Tue, 22 Jun 2021 05:12:32 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a46.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.11.21 (trex/6.3.3); Tue, 22 Jun 2021 05:12:32 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Continue-Share: 2e49c655155cf2b6_1624338752593_1487323750 X-MC-Loop-Signature: 1624338752592:277842953 X-MC-Ingress-Time: 1624338752592 Received: from pdx1-sub0-mail-a46.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a46.g.dreamhost.com (Postfix) with ESMTP id 1DC84880B4 for ; Mon, 21 Jun 2021 22:12:32 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a46.g.dreamhost.com (Postfix) with ESMTPSA id 27EE07F50D for ; Mon, 21 Jun 2021 22:12:30 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a46 To: libc-alpha@sourceware.org Subject: [PATCH v2 4/6] iconvconfig: Use common gconv module parsing function Date: Tue, 22 Jun 2021 10:42:00 +0530 Message-Id: <20210622051202.4155709-5-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210622051202.4155709-1-siddhesh@sourceware.org> References: <20210622051202.4155709-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3492.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham 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-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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. Reviewed-by: DJ Delorie --- 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 /* 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__))) { /* We expect now 1. `from' name @@ -646,131 +647,28 @@ add_module (char *rp, const char *directory) cost, need_ext); } -/* 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; -} - /* 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); + if (dir[dirlen - 1] != '/') { - char *newp = (char *) xmalloc (dirlen + 2); - dir = memcpy (newp, dir, dirlen); - newp[dirlen++] = '/'; - newp[dirlen] = '\0'; + *cp++ = '/'; + *cp = '\0'; + dirlen++; } - /* 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); - free (buf); + free (fulldir); -out: if (!found) { error (0, errno, "failed to open gconv configuration files in `%s'",