From patchwork Mon Jun 7 08:52:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43736 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E85F3835818 for ; Mon, 7 Jun 2021 08:53:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E85F3835818 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623056028; bh=vbNAxmGqg5GlEHtaqySveRvFHP/Mc/r5bgxlNvxcP4o=; 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=BcqdwUmFbwS5o9JDG/tRlfhsyxGnw5xVE9QjrC8XIPFdD7Snf+k32df8BWrwIJ/P7 08oka2AVwswmsoujLxpH2wFqVLh0pd7aL5qk1lAABBvqY/SvRYPcT92bkFmGMP51Tl IvdF6MllwUKbqspyuDmDKnimUjchhIyLBfAFsHRA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from quail.birch.relay.mailchannels.net (quail.birch.relay.mailchannels.net [23.83.209.151]) by sourceware.org (Postfix) with ESMTPS id 31B5F3857020 for ; Mon, 7 Jun 2021 08:52:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 31B5F3857020 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 7F7BF343068; Mon, 7 Jun 2021 08:52:40 +0000 (UTC) Received: from pdx1-sub0-mail-a36.g.dreamhost.com (100-96-11-18.trex.outbound.svc.cluster.local [100.96.11.18]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 096AD3425E0; Mon, 7 Jun 2021 08:52:40 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a36.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.11.18 (trex/6.3.1); Mon, 07 Jun 2021 08:52:40 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Trade-Left: 7ad1e43e0ff15306_1623055960261_165238195 X-MC-Loop-Signature: 1623055960261:429711976 X-MC-Ingress-Time: 1623055960261 Received: from pdx1-sub0-mail-a36.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a36.g.dreamhost.com (Postfix) with ESMTP id BD5E77F257; Mon, 7 Jun 2021 08:52:39 +0000 (UTC) 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-a36.g.dreamhost.com (Postfix) with ESMTPSA id AC30282BC8; Mon, 7 Jun 2021 08:52:37 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a36 To: libc-alpha@sourceware.org Subject: [PATCH 1/5] iconvconfig: Make file handling more general purpose Date: Mon, 7 Jun 2021 14:22:17 +0530 Message-Id: <20210607085221.43612-2-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210607085221.43612-1-siddhesh@sourceware.org> References: <20210607085221.43612-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Split out configuration file handling code from handle_dir into its own function so that it can be reused for multiple configuration files. Reviewed-by: DJ Delorie --- iconv/iconvconfig.c | 65 ++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index e04dd8a2e1..f5aba636d7 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -644,37 +644,17 @@ add_module (char *rp, const char *directory) cost, need_ext); } - -/* Read the config file and add the data for this directory to that. */ -static int -handle_dir (const char *dir) +/* Read a gconv-modules configuration file. */ +static bool +handle_file (const char *dir, const char *infile) { - char *cp; FILE *fp; char *line = NULL; size_t linelen = 0; - size_t dirlen = strlen (dir); - - if (dir[dirlen - 1] != '/') - { - char *newp = (char *) xmalloc (dirlen + 2); - dir = memcpy (newp, dir, dirlen); - newp[dirlen++] = '/'; - newp[dirlen] = '\0'; - } - - char infile[prefix_len + dirlen + sizeof "gconv-modules"]; - cp = infile; - if (dir[0] == '/') - cp = mempcpy (cp, prefix, prefix_len); - strcpy (mempcpy (cp, dir, dirlen), "gconv-modules"); fp = fopen (infile, "r"); if (fp == NULL) - { - error (0, errno, "cannot open `%s'", infile); - return 1; - } + return false; /* No threads present. */ __fsetlocking (fp, FSETLOCKING_BYCALLER); @@ -723,7 +703,42 @@ handle_dir (const char *dir) fclose (fp); - return 0; + 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; + + if (dir[dirlen - 1] != '/') + { + char *newp = (char *) xmalloc (dirlen + 2); + dir = memcpy (newp, dir, dirlen); + newp[dirlen++] = '/'; + newp[dirlen] = '\0'; + } + + char infile[prefix_len + dirlen + sizeof "gconv-modules"]; + cp = infile; + if (dir[0] == '/') + cp = mempcpy (cp, prefix, prefix_len); + strcpy (mempcpy (cp, dir, dirlen), "gconv-modules"); + + found |= handle_file (dir, infile); + + if (!found) + { + error (0, errno, "failed to open gconv configuration file in `%s'", + dir); + error (0, 0, + "ensure that the directory contains a valid gconv-modules file."); + } + + return found ? 0 : 1; }