[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Code cleanup in load_module
From: |
Tim Rühsen |
Subject: |
[PATCH] Code cleanup in load_module |
Date: |
Wed, 8 Apr 2020 18:20:59 +0200 |
2020-04-08 Tim Rühsen <address@hidden>
* lib/pkl-tab.y (load_module): Code cleanup.
---
ChangeLog | 4 ++++
lib/pkl-tab.y | 46 ++++++++++++++++------------------------------
2 files changed, 20 insertions(+), 30 deletions(-)
diff --git a/lib/pkl-tab.y b/lib/pkl-tab.y
index 6a8f17f5..22708f46 100644
--- a/lib/pkl-tab.y
+++ b/lib/pkl-tab.y
@@ -224,41 +224,27 @@ load_module (struct pkl_parser *parser,
requested module. */
{
char *full_filename;
- char *saveptr = NULL;
- char *path = xstrdup (load_path); /* Modified by strtok. */
- char *dir = strtok_r (path, ":", &saveptr);
+ const char *s, *e;
- if (dir)
+ for (s = load_path, e = s; *e; s = e + 1)
{
- do
+ /* Ignore empty entries. */
+ if ((e = strchrnul (s, ':')) == s)
+ continue;
+
+ if (!strncmp (s, "%DATADIR%", e - s))
+ full_filename = pk_str_concat (PKGDATADIR, "/", filename, NULL);
+ else
+ asprintf (&full_filename, "%.*s/%s", (int) (e - s), s, filename);
+
+ if (pk_file_readable (full_filename) == NULL)
{
- /* Ignore empty entries. */
- if (*dir == '\0')
- continue;
-
- /* Substitute %...% marks. */
- if (STREQ (dir, "%DATADIR%"))
- dir = PKGDATADIR;
-
- /* Mount the full path and determine whether the resulting
- file is readable. */
- full_filename = alloca (strlen (dir)
- + 1 /* "/" */ + strlen (filename)
- + 1);
- strcpy (full_filename, dir);
- strcat (full_filename, "/");
- strcat (full_filename, filename);
-
- if (pk_file_readable (full_filename) == NULL)
- {
- module_filename = xstrdup (full_filename);
- break;
- }
+ module_filename = full_filename;
+ break;
}
- while ((dir = strtok_r (NULL, ":", &saveptr)) != NULL);
- }
- free (path);
+ free (full_filename);
+ }
}
if (module_filename == NULL)
--
2.26.0
- [PATCH] Code cleanup in load_module,
Tim Rühsen <=