|
|
179894 |
commit 0c78b0bb78d87a7de18726a033d88904f158f0fe
|
|
|
179894 |
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
|
179894 |
Date: Mon Jun 7 14:22:17 2021 +0530
|
|
|
179894 |
|
|
|
179894 |
iconvconfig: Make file handling more general purpose
|
|
|
179894 |
|
|
|
179894 |
Split out configuration file handling code from handle_dir into its
|
|
|
179894 |
own function so that it can be reused for multiple configuration
|
|
|
179894 |
files.
|
|
|
179894 |
|
|
|
179894 |
Reviewed-by: DJ Delorie <dj@redhat.com>
|
|
|
179894 |
|
|
|
179894 |
diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c
|
|
|
179894 |
index b6fef1553cbbdd3d..2b3c587bc77cfdcd 100644
|
|
|
179894 |
--- a/iconv/iconvconfig.c
|
|
|
179894 |
+++ b/iconv/iconvconfig.c
|
|
|
179894 |
@@ -644,37 +644,17 @@ add_module (char *rp, const char *directory)
|
|
|
179894 |
cost, need_ext);
|
|
|
179894 |
}
|
|
|
179894 |
|
|
|
179894 |
-
|
|
|
179894 |
-/* Read the config file and add the data for this directory to that. */
|
|
|
179894 |
-static int
|
|
|
179894 |
-handle_dir (const char *dir)
|
|
|
179894 |
+/* Read a gconv-modules configuration file. */
|
|
|
179894 |
+static bool
|
|
|
179894 |
+handle_file (const char *dir, const char *infile)
|
|
|
179894 |
{
|
|
|
179894 |
- char *cp;
|
|
|
179894 |
FILE *fp;
|
|
|
179894 |
char *line = NULL;
|
|
|
179894 |
size_t linelen = 0;
|
|
|
179894 |
- size_t dirlen = strlen (dir);
|
|
|
179894 |
-
|
|
|
179894 |
- if (dir[dirlen - 1] != '/')
|
|
|
179894 |
- {
|
|
|
179894 |
- char *newp = (char *) xmalloc (dirlen + 2);
|
|
|
179894 |
- dir = memcpy (newp, dir, dirlen);
|
|
|
179894 |
- newp[dirlen++] = '/';
|
|
|
179894 |
- newp[dirlen] = '\0';
|
|
|
179894 |
- }
|
|
|
179894 |
-
|
|
|
179894 |
- char infile[prefix_len + dirlen + sizeof "gconv-modules"];
|
|
|
179894 |
- cp = infile;
|
|
|
179894 |
- if (dir[0] == '/')
|
|
|
179894 |
- cp = mempcpy (cp, prefix, prefix_len);
|
|
|
179894 |
- strcpy (mempcpy (cp, dir, dirlen), "gconv-modules");
|
|
|
179894 |
|
|
|
179894 |
fp = fopen (infile, "r");
|
|
|
179894 |
if (fp == NULL)
|
|
|
179894 |
- {
|
|
|
179894 |
- error (0, errno, "cannot open `%s'", infile);
|
|
|
179894 |
- return 1;
|
|
|
179894 |
- }
|
|
|
179894 |
+ return false;
|
|
|
179894 |
|
|
|
179894 |
/* No threads present. */
|
|
|
179894 |
__fsetlocking (fp, FSETLOCKING_BYCALLER);
|
|
|
179894 |
@@ -723,7 +703,42 @@ handle_dir (const char *dir)
|
|
|
179894 |
|
|
|
179894 |
fclose (fp);
|
|
|
179894 |
|
|
|
179894 |
- return 0;
|
|
|
179894 |
+ return true;
|
|
|
179894 |
+}
|
|
|
179894 |
+
|
|
|
179894 |
+/* Read config files and add the data for this directory to cache. */
|
|
|
179894 |
+static int
|
|
|
179894 |
+handle_dir (const char *dir)
|
|
|
179894 |
+{
|
|
|
179894 |
+ char *cp;
|
|
|
179894 |
+ size_t dirlen = strlen (dir);
|
|
|
179894 |
+ bool found = false;
|
|
|
179894 |
+
|
|
|
179894 |
+ if (dir[dirlen - 1] != '/')
|
|
|
179894 |
+ {
|
|
|
179894 |
+ char *newp = (char *) xmalloc (dirlen + 2);
|
|
|
179894 |
+ dir = memcpy (newp, dir, dirlen);
|
|
|
179894 |
+ newp[dirlen++] = '/';
|
|
|
179894 |
+ newp[dirlen] = '\0';
|
|
|
179894 |
+ }
|
|
|
179894 |
+
|
|
|
179894 |
+ char infile[prefix_len + dirlen + sizeof "gconv-modules"];
|
|
|
179894 |
+ cp = infile;
|
|
|
179894 |
+ if (dir[0] == '/')
|
|
|
179894 |
+ cp = mempcpy (cp, prefix, prefix_len);
|
|
|
179894 |
+ strcpy (mempcpy (cp, dir, dirlen), "gconv-modules");
|
|
|
179894 |
+
|
|
|
179894 |
+ found |= handle_file (dir, infile);
|
|
|
179894 |
+
|
|
|
179894 |
+ if (!found)
|
|
|
179894 |
+ {
|
|
|
179894 |
+ error (0, errno, "failed to open gconv configuration file in `%s'",
|
|
|
179894 |
+ dir);
|
|
|
179894 |
+ error (0, 0,
|
|
|
179894 |
+ "ensure that the directory contains a valid gconv-modules file.");
|
|
|
179894 |
+ }
|
|
|
179894 |
+
|
|
|
179894 |
+ return found ? 0 : 1;
|
|
|
179894 |
}
|
|
|
179894 |
|
|
|
179894 |
|