mirror of
git://sourceware.org/git/glibc.git
synced 2025-01-30 12:31:53 +08:00
iconvconfig: Make file handling more general purpose
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 <dj@redhat.com>
This commit is contained in:
parent
6a86bc0992
commit
0c78b0bb78
@ -644,37 +644,17 @@ add_module (char *rp, const char *directory)
|
|||||||
cost, need_ext);
|
cost, need_ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read a gconv-modules configuration file. */
|
||||||
/* Read the config file and add the data for this directory to that. */
|
static bool
|
||||||
static int
|
handle_file (const char *dir, const char *infile)
|
||||||
handle_dir (const char *dir)
|
|
||||||
{
|
{
|
||||||
char *cp;
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t linelen = 0;
|
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");
|
fp = fopen (infile, "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
{
|
return false;
|
||||||
error (0, errno, "cannot open `%s'", infile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No threads present. */
|
/* No threads present. */
|
||||||
__fsetlocking (fp, FSETLOCKING_BYCALLER);
|
__fsetlocking (fp, FSETLOCKING_BYCALLER);
|
||||||
@ -723,7 +703,42 @@ handle_dir (const char *dir)
|
|||||||
|
|
||||||
fclose (fp);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user