!g_ascii_isdigit(de->d_name[4]))
continue;
- looppath = g_strdup_printf("/dev/%s", de->d_name);
+ looppath = g_build_filename("/dev", de->d_name, NULL);
VIR_DEBUG("Checking up on device %s", looppath);
if ((fd = open(looppath, O_RDWR)) < 0) {
{
g_autofree char *path = NULL;
- path = g_strdup_printf(SYSFS_BLOCK_DIR "/%s/pid", dev_name);
+ path = g_build_filename(SYSFS_BLOCK_DIR, dev_name, "pid", NULL);
if (!virFileExists(path)) {
if (errno == ENOENT)
return NULL;
if (rv == 0)
- return g_strdup_printf("/dev/%s", de->d_name);
+ return g_build_filename("/dev", de->d_name, NULL);
}
}
if (direrr < 0)
g_autofree char *filepath = NULL;
GStatBuf sb;
- filepath = g_strdup_printf("%s/%s", dir, de->d_name);
+ filepath = g_build_filename(dir, de->d_name, NULL);
if (g_lstat(filepath, &sb) < 0) {
virReportSystemError(errno, _("Cannot access '%s'"),
checkLink);
return -1;
}
- candidate = g_strdup_printf("%s/%s", directory, checkLink);
+ candidate = g_build_filename(directory, checkLink, NULL);
return virFileLinkPointsTo(candidate, checkDest);
}
return NULL;
for (pathiter = paths; *pathiter; pathiter++) {
- g_autofree char *fullpath = g_strdup_printf("%s/%s", *pathiter, file);
+ g_autofree char *fullpath = g_build_filename(*pathiter, file, NULL);
if (virFileIsExecutable(fullpath))
return g_steal_pointer(&fullpath);
}
char *ret = NULL;
const char *envval = envname ? getenv(envname) : NULL;
const char *path;
+ g_autofree char *fullFilename = NULL;
if (!prefix)
prefix = "";
else
path = installdir;
- ret = g_strdup_printf("%s/%s%s%s", path, prefix, filename, suffix);
+ fullFilename = g_strdup_printf("%s%s%s", prefix, filename, suffix);
+ ret = g_build_filename(path, fullFilename, NULL);
VIR_DEBUG("Resolved '%s' to '%s'", filename, ret);
return ret;
while ((direrr = virDirRead(dir, &ent, name)) > 0) {
g_autofree char *path = NULL;
- path = g_strdup_printf("%s/%s", name, ent->d_name);
+ path = g_build_filename(name, ent->d_name, NULL);
if (!virFileIsRegular(path))
continue;
char *path;
if (ext == NULL) {
- path = g_strdup_printf("%s/%s", dir, name);
+ path = g_build_filename(dir, name, NULL);
} else {
- path = g_strdup_printf("%s/%s%s", dir, name, ext);
+ g_autofree char *extName = g_strdup_printf("%s%s", name, ext);
+ path = g_build_filename(dir, extName, NULL);
}
return path;
} else {
g_autofree char *buf = g_get_current_dir();
- *abspath = g_strdup_printf("%s/%s", buf, path);
+ *abspath = g_build_filename(buf, path, NULL);
}
return 0;