*/
len = strlen(cgroup) + strlen(file) + 3;
fnam = alloca(len);
- ret = snprintf(fnam, len, "%s%s/%s", *cgroup == '/' ? "." : "", cgroup, file);
+ ret = snprintf(fnam, len, "%s%s/%s", dot_or_empty(cgroup), cgroup, file);
if (ret < 0 || (size_t)ret >= len)
return false;
*/
len = strlen(cg) + 2;
dirnam = alloca(len);
- snprintf(dirnam, len, "%s%s", *cg == '/' ? "." : "", cg);
+ snprintf(dirnam, len, "%s%s", dot_or_empty(cg), cg);
if (mkdirat(cfd, dirnam, 0755) < 0)
return -errno;
*/
len = strlen(cg) + 2;
dirnam = alloca(len);
- snprintf(dirnam, len, "%s%s", *cg == '/' ? "." : "", cg);
+ snprintf(dirnam, len, "%s%s", dot_or_empty(cg), cg);
fd = openat(cfd, dirnam, O_DIRECTORY);
if (fd < 0)
*/
len = strlen(file) + 2;
pathname = alloca(len);
- snprintf(pathname, len, "%s%s", *file == '/' ? "." : "", file);
+ snprintf(pathname, len, "%s%s", dot_or_empty(file), file);
if (fchmodat(cfd, pathname, mode, 0) < 0)
return false;
return true;
*/
len = strlen(file) + 2;
pathname = alloca(len);
- snprintf(pathname, len, "%s%s", *file == '/' ? "." : "", file);
+ snprintf(pathname, len, "%s%s", dot_or_empty(file), file);
if (fchownat(cfd, pathname, uid, gid, 0) < 0)
return -errno;
*/
len = strlen(cgroup) + strlen("cgroup.procs") + 3;
pathname = alloca(len);
- snprintf(pathname, len, "%s%s/cgroup.procs", *cgroup == '/' ? "." : "", cgroup);
+ snprintf(pathname, len, "%s%s/cgroup.procs", dot_or_empty(cgroup), cgroup);
fd = openat(cfd, pathname, O_WRONLY);
if (fd < 0)
/* Make sure we pass a relative path to *at() family of functions. */
len = strlen(cgroup) + 1 /* . */ + 1 /* \0 */;
cg = alloca(len);
- ret = snprintf(cg, len, "%s%s", *cgroup == '/' ? "." : "", cgroup);
+ ret = snprintf(cg, len, "%s%s", dot_or_empty(cgroup), cgroup);
if (ret < 0 || (size_t)ret >= len) {
lxcfs_error("Pathname too long under %s\n", cgroup);
return false;
*/
len = strlen(cgroup) + strlen(file) + 3;
fnam = alloca(len);
- ret = snprintf(fnam, len, "%s%s/%s", *cgroup == '/' ? "." : "", cgroup, file);
+ ret = snprintf(fnam, len, "%s%s/%s", dot_or_empty(cgroup), cgroup, file);
if (ret < 0 || (size_t)ret >= len)
return false;
if (file)
len += strlen(file) + 1;
fnam = alloca(len);
- snprintf(fnam, len, "%s%s%s%s", *cgroup == '/' ? "." : "", cgroup,
+ snprintf(fnam, len, "%s%s%s%s", dot_or_empty(cgroup), cgroup,
file ? "/" : "", file ? file : "");
ret = fstatat(cfd, fnam, &sb, 0);
*/
len = strlen(cgroup) + strlen(f) + 3;
fnam = alloca(len);
- ret = snprintf(fnam, len, "%s%s/%s", *cgroup == '/' ? "." : "", cgroup, f);
+ ret = snprintf(fnam, len, "%s%s/%s", dot_or_empty(cgroup), cgroup, f);
if (ret < 0 || (size_t)ret >= len)
return false;
path = malloc(length);
} while (!path);
- ret = snprintf(path, length, "%s%s", *(f->cg) == '/' ? "." : "", f->cg);
+ ret = snprintf(path, length, "%s%s", dot_or_empty(f->cg), f->cg);
if (ret < 0 || ret > length - 1) {
/* snprintf failed, ignore the node.*/
lxcfs_error("Refresh node %s failed for snprintf().\n", f->cg);
if (!h)
return false;
- path = must_make_path(*cgroup == '/' ? "." : "", cgroup, file, NULL);
+ path = must_make_path(dot_or_empty(cgroup), cgroup, file, NULL);
*value = readat_file(h->fd, path);
return *value != NULL;
}
ret = CGROUP2_SUPER_MAGIC;
}
- path = must_make_path(*cgroup == '/' ? "." : "", cgroup, file, NULL);
+ path = must_make_path(dot_or_empty(cgroup), cgroup, file, NULL);
*value = readat_file(h->fd, path);
if (!*value)
ret = -1;
ret = CGROUP2_SUPER_MAGIC;
*value = NULL;
- path = must_make_path(*cgroup == '/' ? "." : "", cgroup, NULL);
+ path = must_make_path(dot_or_empty(cgroup), cgroup, NULL);
cgroup_fd = openat_safe(h->fd, path);
if (cgroup_fd < 0) {
return -1;