/* SPDX-License-Identifier: LGPL-2.1+ */
/***
- This file is part of systemd.
-
Copyright 2010 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
}
int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret) {
- char *s;
+ UnitType type;
assert(prefix);
assert(suffix);
assert(ret);
+ if (suffix[0] != '.')
+ return -EINVAL;
+
+ type = unit_type_from_string(suffix + 1);
+ if (type < 0)
+ return -EINVAL;
+
+ return unit_name_build_from_type(prefix, instance, type, ret);
+}
+
+int unit_name_build_from_type(const char *prefix, const char *instance, UnitType type, char **ret) {
+ const char *ut;
+ char *s;
+
+ assert(prefix);
+ assert(type >= 0);
+ assert(type < _UNIT_TYPE_MAX);
+ assert(ret);
+
if (!unit_prefix_is_valid(prefix))
return -EINVAL;
if (instance && !unit_instance_is_valid(instance))
return -EINVAL;
- if (!unit_suffix_is_valid(suffix))
- return -EINVAL;
+ ut = unit_type_to_string(type);
if (!instance)
- s = strappend(prefix, suffix);
+ s = strjoin(prefix, ".", ut);
else
- s = strjoin(prefix, "@", instance, suffix);
+ s = strjoin(prefix, "@", instance, ".", ut);
if (!s)
return -ENOMEM;
if (!p)
return -ENOMEM;
- path_kill_slashes(p);
+ path_simplify(p, false);
- if (STR_IN_SET(p, "/", ""))
+ if (empty_or_root(p))
s = strdup("-");
else {
if (!path_is_normalized(p))
return 1;
}
-int slice_build_subslice(const char *slice, const char*name, char **ret) {
+int slice_build_subslice(const char *slice, const char *name, char **ret) {
char *subslice;
assert(slice);