chiark / gitweb /
util: use join() instead of asprintf() as an optimization
authorLennart Poettering <lennart@poettering.net>
Mon, 1 Aug 2011 00:39:22 +0000 (02:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 1 Aug 2011 00:39:22 +0000 (02:39 +0200)
src/conf-parser.c
src/load-dropin.c
src/manager.c
src/service.c
src/util.c

index a99c70596b0a52eb6aeeb7bc78d5af6691a5f232..3bb430e375183499889243ee9ef14169e141123a 100644 (file)
@@ -88,7 +88,8 @@ int config_item_perf_lookup(
         else {
                 char *key;
 
         else {
                 char *key;
 
-                if (asprintf(&key, "%s.%s", section, lvalue) < 0)
+                key = join(section, ".", lvalue, NULL);
+                if (!key)
                         return -ENOMEM;
 
                 p = lookup(key, strlen(key));
                         return -ENOMEM;
 
                 p = lookup(key, strlen(key));
index 984a47a297da5cfe521fb36a6e9fd03028886623..dbdc6a41df9a35ab09d133721cf60c23296e0d56 100644 (file)
@@ -50,7 +50,8 @@ static int iterate_dir(Unit *u, const char *path, UnitDependency dependency) {
                 if (ignore_file(de->d_name))
                         continue;
 
                 if (ignore_file(de->d_name))
                         continue;
 
-                if (asprintf(&f, "%s/%s", path, de->d_name) < 0) {
+                f = join(path, "/", de->d_name, NULL);
+                if (!f) {
                         r = -ENOMEM;
                         goto finish;
                 }
                         r = -ENOMEM;
                         goto finish;
                 }
index cdd618e148efa052adaba1cd179351f611bfa127..9e4bd51d5c28607ced180019dcb485e15ba52fbf 100644 (file)
@@ -560,7 +560,8 @@ static void manager_build_unit_path_cache(Manager *m) {
                         if (ignore_file(de->d_name))
                                 continue;
 
                         if (ignore_file(de->d_name))
                                 continue;
 
-                        if (asprintf(&p, "%s/%s", streq(*i, "/") ? "" : *i, de->d_name) < 0) {
+                        p = join(streq(*i, "/") ? "" : *i, "/", de->d_name, NULL);
+                        if (!p) {
                                 r = -ENOMEM;
                                 goto fail;
                         }
                                 r = -ENOMEM;
                                 goto fail;
                         }
index 5c17413a5906351978b705e155e0a0c508affbbc..4e3b6e719c5c6eac33d320a0f15d26ac5ba94ae8 100644 (file)
@@ -635,7 +635,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                 char *d = NULL;
 
                                 if (chkconfig_description)
                                 char *d = NULL;
 
                                 if (chkconfig_description)
-                                        asprintf(&d, "%s %s", chkconfig_description, j);
+                                        d = join(chkconfig_description, " ", j, NULL);
                                 else
                                         d = strdup(j);
 
                                 else
                                         d = strdup(j);
 
@@ -805,7 +805,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 char *d = NULL;
 
                                                 if (long_description)
                                                 char *d = NULL;
 
                                                 if (long_description)
-                                                        asprintf(&d, "%s %s", long_description, t);
+                                                        d = join(long_description, " ", t, NULL);
                                                 else
                                                         d = strdup(j);
 
                                                 else
                                                         d = strdup(j);
 
@@ -921,7 +921,8 @@ static int service_load_sysv_name(Service *s, const char *name) {
                 char *path;
                 int r;
 
                 char *path;
                 int r;
 
-                if (asprintf(&path, "%s/%s", *p, name) < 0)
+                path = join(*p, "/", name, NULL);
+                if (!path)
                         return -ENOMEM;
 
                 assert(endswith(path, ".service"));
                         return -ENOMEM;
 
                 assert(endswith(path, ".service"));
@@ -942,7 +943,8 @@ static int service_load_sysv_name(Service *s, const char *name) {
                 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
                         /* Try SUSE style boot.* init scripts */
 
                 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
                         /* Try SUSE style boot.* init scripts */
 
-                        if (asprintf(&path, "%s/boot.%s", *p, name) < 0)
+                        path = join(*p, "/boot.", name, NULL);
+                        if (!path)
                                 return -ENOMEM;
 
                         /* Drop .service suffix */
                                 return -ENOMEM;
 
                         /* Drop .service suffix */
@@ -956,7 +958,8 @@ static int service_load_sysv_name(Service *s, const char *name) {
                 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
                         /* Try Frugalware style rc.* init scripts */
 
                 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
                         /* Try Frugalware style rc.* init scripts */
 
-                        if (asprintf(&path, "%s/rc.%s", *p, name) < 0)
+                        path = join(*p, "/rc.", name, NULL);
+                        if (!path)
                                 return -ENOMEM;
 
                         /* Drop .service suffix */
                                 return -ENOMEM;
 
                         /* Drop .service suffix */
@@ -2987,7 +2990,6 @@ static int service_enumerate(Manager *m) {
                         struct dirent *de;
 
                         free(path);
                         struct dirent *de;
 
                         free(path);
-                        path = NULL;
                         path = join(*p, "/", rcnd_table[i].path, NULL);
                         if (!path) {
                                 r = -ENOMEM;
                         path = join(*p, "/", rcnd_table[i].path, NULL);
                         if (!path) {
                                 r = -ENOMEM;
@@ -3023,8 +3025,8 @@ static int service_enumerate(Manager *m) {
                                         continue;
 
                                 free(fpath);
                                         continue;
 
                                 free(fpath);
-                                fpath = NULL;
-                                if (asprintf(&fpath, "%s/%s/%s", *p, rcnd_table[i].path, de->d_name) < 0) {
+                                fpath = join(path, "/", de->d_name, NULL);
+                                if (!path) {
                                         r = -ENOMEM;
                                         goto finish;
                                 }
                                         r = -ENOMEM;
                                         goto finish;
                                 }
index b533b26dafc543a50abba861ef07c9f89c8cde9b..6382c01c556eb7d7f0e83f1de62338909b248f78 100644 (file)
@@ -809,7 +809,7 @@ int parse_env_file(
                 const char *separator, ...) {
 
         int r = 0;
                 const char *separator, ...) {
 
         int r = 0;
-        char *contents, *p;
+        char *contents = NULL, *p;
 
         assert(fname);
         assert(separator);
 
         assert(fname);
         assert(separator);
@@ -1266,8 +1266,6 @@ bool is_path(const char *p) {
 }
 
 char *path_make_absolute(const char *p, const char *prefix) {
 }
 
 char *path_make_absolute(const char *p, const char *prefix) {
-        char *r;
-
         assert(p);
 
         /* Makes every item in the list an absolute path by prepending
         assert(p);
 
         /* Makes every item in the list an absolute path by prepending
@@ -1276,10 +1274,7 @@ char *path_make_absolute(const char *p, const char *prefix) {
         if (path_is_absolute(p) || !prefix)
                 return strdup(p);
 
         if (path_is_absolute(p) || !prefix)
                 return strdup(p);
 
-        if (asprintf(&r, "%s/%s", prefix, p) < 0)
-                return NULL;
-
-        return r;
+        return join(prefix, "/", p, NULL);
 }
 
 char *path_make_absolute_cwd(const char *p) {
 }
 
 char *path_make_absolute_cwd(const char *p) {