#include <string.h>
#include <assert.h>
-#include "sd-bus.h"
#include "path-util.h"
+#include "bus-label.h"
#include "util.h"
#include "unit-name.h"
#include "def.h"
}
char *unit_name_path_escape(const char *f) {
- char *p, *e;
+ _cleanup_free_ char *p;
assert(f);
path_kill_slashes(p);
- if (streq(p, "/") || streq(p, "")) {
- free(p);
+ if (streq(p, "/") || streq(p, ""))
return strdup("-");
- }
-
- e = unit_name_escape(p[0] == '/' ? p + 1 : p);
- free(p);
- return e;
+ return unit_name_escape(p[0] == '/' ? p + 1 : p);
}
char *unit_name_path_unescape(const char *f) {
}
char *unit_name_from_path(const char *path, const char *suffix) {
- char *p, *r;
+ _cleanup_free_ char *p = NULL;
assert(path);
assert(suffix);
if (!p)
return NULL;
- r = strappend(p, suffix);
- free(p);
-
- return r;
+ return strappend(p, suffix);
}
char *unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix) {
- char *p, *r;
+ _cleanup_free_ char *p = NULL;
assert(prefix);
assert(path);
if (!p)
return NULL;
- r = strjoin(prefix, "@", p, suffix, NULL);
- free(p);
-
- return r;
+ return strjoin(prefix, "@", p, suffix, NULL);
}
char *unit_name_to_path(const char *name) {
assert(name);
- e = sd_bus_label_escape(name);
+ e = bus_label_escape(name);
if (!e)
return NULL;
if (!e)
return -EINVAL;
- n = sd_bus_label_unescape(e);
+ n = bus_label_unescape(e);
if (!n)
return -ENOMEM;
/* We'll only escape the obvious characters here, to play
* safe. */
- r = new(char, strlen(name) * 4 + 1 + sizeof(".service")-1);
+ r = new(char, strlen(name) * 4 + strlen(".service") + 1);
if (!r)
return NULL;