summaryrefslogtreecommitdiff
path: root/src/librc/librc-misc.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-03-17 13:25:56 +0000
committerRoy Marples <roy@marples.name>2008-03-17 13:25:56 +0000
commit4c1466642351ddb01cc7353601153a79326f18f7 (patch)
treecb9da1a90aa9480ef276626f40c556379222ec51 /src/librc/librc-misc.c
parent50a7697bf207e4919ce893bfc1604fd3a9d807de (diff)
downloadopenrc-4c1466642351ddb01cc7353601153a79326f18f7.tar.gz
openrc-4c1466642351ddb01cc7353601153a79326f18f7.tar.bz2
openrc-4c1466642351ddb01cc7353601153a79326f18f7.tar.xz
Punt the rc_strcatpaths function and use snprintf instead to save on expensive malloc calls.
Diffstat (limited to 'src/librc/librc-misc.c')
-rw-r--r--src/librc/librc-misc.c67
1 files changed, 9 insertions, 58 deletions
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index fac78e2..747a8fb 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -54,57 +54,6 @@ bool rc_yesno (const char *value)
}
librc_hidden_def(rc_yesno)
-char *rc_strcatpaths (const char *path1, const char *paths, ...)
-{
- va_list ap;
- size_t length;
- size_t i;
- char *p;
- char *path;
- char *pathp;
-
- if (! path1 || ! paths)
- return NULL;
-
- length = strlen (path1) + strlen (paths) + 1;
- if (*paths != '/')
- length ++;
-
- va_start (ap, paths);
- while ((p = va_arg (ap, char *)) != NULL) {
- if (*p != '/')
- length ++;
- length += strlen (p);
- }
- va_end (ap);
-
- pathp = path = xmalloc (length * sizeof (char));
- memset (path, 0, length);
- i = strlen (path1);
- memcpy (path, path1, i);
- pathp += i;
- if (*paths != '/')
- *pathp ++ = '/';
- i = strlen (paths);
- memcpy (pathp, paths, i);
- pathp += i;
-
- va_start (ap, paths);
- while ((p = va_arg (ap, char *)) != NULL) {
- if (*p != '/')
- *pathp ++= '/';
- i = strlen (p);
- memcpy (pathp, p, i);
- pathp += i;
- }
- va_end (ap);
-
- *pathp++ = 0;
-
- return path;
-}
-librc_hidden_def(rc_strcatpaths)
-
char *rc_getline (FILE *fp)
{
char *line = NULL;
@@ -138,13 +87,11 @@ RC_STRINGLIST *rc_config_list(const char *file)
char *buffer;
char *p;
char *token;
- RC_STRINGLIST *list;
+ RC_STRINGLIST *list = NULL;
if (!(fp = fopen(file, "r")))
return NULL;
- list = rc_stringlist_new();
-
while ((p = buffer = rc_getline(fp))) {
/* Strip leading spaces/tabs */
while ((*p == ' ') || (*p == '\t'))
@@ -159,6 +106,8 @@ RC_STRINGLIST *rc_config_list(const char *file)
if (token[strlen(token) - 1] == '\n')
token[strlen(token) - 1] = 0;
+ if (! list)
+ list = rc_stringlist_new();
rc_stringlist_add(list, token);
}
}
@@ -172,8 +121,8 @@ librc_hidden_def(rc_config_list)
RC_STRINGLIST *rc_config_load(const char *file)
{
- RC_STRINGLIST *list = NULL;
- RC_STRINGLIST *config = NULL;
+ RC_STRINGLIST *list;
+ RC_STRINGLIST *config;
char *token;
RC_STRING *line;
RC_STRING *cline;
@@ -183,9 +132,11 @@ RC_STRINGLIST *rc_config_load(const char *file)
char *newline;
char *p;
- config = rc_stringlist_new();
-
list = rc_config_list(file);
+ if (! list)
+ return NULL;
+
+ config = rc_stringlist_new();
TAILQ_FOREACH(line, list, entries) {
/* Get entry */
p = line->value;