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 D13393985025 for ; Tue, 8 Jun 2021 20:53:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D13393985025 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-39-w_wnQLXhNWWlsld38W_WUA-1; Tue, 08 Jun 2021 16:53:09 -0400 X-MC-Unique: w_wnQLXhNWWlsld38W_WUA-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 0FEAB106BB29; Tue, 8 Jun 2021 20:53:08 +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 D0DFB5D6D3; Tue, 8 Jun 2021 20:53:07 +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 158Kr6s4239388; Tue, 8 Jun 2021 16:53:06 -0400 From: DJ Delorie To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 1/5] iconvconfig: Make file handling more general purpose In-Reply-To: <20210607085221.43612-2-siddhesh@sourceware.org> Date: Tue, 08 Jun 2021 16:53:06 -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.3 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=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-List-Received-Date: Tue, 08 Jun 2021 20:53:21 -0000 Siddhesh Poyarekar via Libc-alpha writes: > diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c > - > -/* 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) Rename existing function. Keep "dir" as its used elsewhere in this function, not shown by the patch. Ok. > - 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"); This portion is moved to handle_dir (below). Ok. > fp = fopen (infile, "r"); > if (fp == NULL) > - { > - error (0, errno, "cannot open `%s'", infile); > - return 1; > - } > + return false; Error handling moved too, ok. > /* No threads present. */ > __fsetlocking (fp, FSETLOCKING_BYCALLER); > @@ -723,7 +703,42 @@ handle_dir (const char *dir) > > fclose (fp); > > - return 0; > + return true; > +} Likewise. > +/* 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; > } This looks a little weird as-is, but I realize further patches need it this way, so OK. Reviewed-by: DJ Delorie