if (!(dir = mdir_name(sysfsPath)))
return -1;
- rport = g_strdup(last_component(dir));
+ rport = g_path_get_basename(dir);
if (!virFCIsCapableRport(rport))
goto cleanup;
#include <pciaccess.h>
#include <scsi/scsi.h>
-#include "dirname.h"
#include "node_device_conf.h"
#include "node_device_event.h"
#include "node_device_driver.h"
virNodeDeviceDefPtr def)
{
virNodeDevCapSCSIHostPtr scsi_host = &def->caps->data.scsi_host;
- char *filename = NULL;
+ g_autofree char *filename = NULL;
char *str;
- filename = last_component(def->sysfs_path);
+ filename = g_path_get_basename(def->sysfs_path);
if (!(str = STRSKIP(filename, "host")) ||
virStrToLong_ui(str, NULL, 0, &scsi_host->host) < 0) {
int ret = -1;
unsigned int tmp = 0;
virNodeDevCapSCSIPtr scsi = &def->caps->data.scsi;
- char *filename = NULL, *p = NULL;
+ g_autofree char *filename = NULL;
+ char *p = NULL;
- filename = last_component(def->sysfs_path);
+ filename = g_path_get_basename(def->sysfs_path);
if (virStrToLong_ui(filename, &p, 10, &scsi->host) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 10, &scsi->bus) < 0 || p == NULL ||
goto cleanup;
}
- data->type = g_strdup(last_component(canonicalpath));
+ data->type = g_path_get_basename(canonicalpath);
uuidstr = udev_device_get_sysname(dev);
if ((iommugrp = virMediatedDeviceGetIOMMUGroupNum(uuidstr)) < 0)
#include "virprobe.h"
#include "virprocess.h"
#include "virstring.h"
-#include "dirname.h"
#include "passfd.h"
#if WITH_SSH2
remoteAddr.len = sizeof(remoteAddr.data.un);
if (spawnDaemon) {
- const char *binname;
+ g_autofree char *binname = NULL;
if (spawnDaemon && !binary) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
goto cleanup;
}
- if (!(binname = last_component(binary)) || binname[0] == '\0') {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Cannot determine basename for binary '%s'"),
- binary);
- goto cleanup;
- }
-
+ binname = g_path_get_basename(binary);
rundir = virGetUserRuntimeDirectory();
if (virFileMakePathWithMode(rundir, 0700) < 0) {
#include <config.h>
#include <unistd.h>
-#include "dirname.h"
#include "virerror.h"
#include "virlog.h"
#include "storage_backend_disk.h"
unsigned int flags)
{
char *part_num = NULL;
- char *dev_name;
+ g_autofree char *dev_name = NULL;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *src_path = def->source.devices[0].path;
- char *srcname = last_component(src_path);
+ g_autofree char *srcname = g_path_get_basename(src_path);
bool isDevMapperDevice;
g_autofree char *devpath = NULL;
g_autoptr(virCommand) cmd = NULL;
* in both places */
isDevMapperDevice = virIsDevMapperDevice(vol->target.path);
if (isDevMapperDevice) {
- dev_name = last_component(vol->target.path);
+ dev_name = g_path_get_basename(vol->target.path);
} else {
if (virFileResolveLink(vol->target.path, &devpath) < 0) {
virReportSystemError(errno,
vol->target.path);
return -1;
}
- dev_name = last_component(devpath);
+ dev_name = g_path_get_basename(devpath);
}
VIR_DEBUG("dev_name=%s, srcname=%s", dev_name, srcname);
#include <sys/statvfs.h>
#include <sys/param.h>
#include <dirent.h>
-#include "dirname.h"
#ifdef __linux__
# include <sys/ioctl.h>
# include <linux/fs.h>
unsigned int flags)
{
int fd, mode = 0;
- char *base = last_component(path);
+ g_autofree char *base = g_path_get_basename(path);
bool noerror = (flags & VIR_STORAGE_VOL_OPEN_NOERROR);
if (g_lstat(path, sb) < 0) {
#include <config.h>
-#include "dirname.h"
#include "virmdev.h"
#include "virlog.h"
#include "virerror.h"
virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
{
g_autofree char *result_path = NULL;
+ g_autofree char *result_file = NULL;
g_autofree char *iommu_path = NULL;
g_autofree char *dev_path = virMediatedDeviceGetSysfsPath(uuidstr);
char *vfio_path = NULL;
return NULL;
}
- vfio_path = g_strdup_printf("/dev/vfio/%s", last_component(result_path));
+ result_file = g_path_get_basename(result_path);
+
+ vfio_path = g_strdup_printf("/dev/vfio/%s", result_file);
return vfio_path;
}
virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr)
{
g_autofree char *vfio_path = NULL;
- char *group_num_str = NULL;
+ g_autofree char *group_num_str = NULL;
unsigned int group_num = -1;
if (!(vfio_path = virMediatedDeviceGetIOMMUGroupDev(uuidstr)))
return -1;
- group_num_str = last_component(vfio_path);
+ group_num_str = g_path_get_basename(vfio_path);
ignore_value(virStrToLong_ui(group_num_str, NULL, 10, &group_num));
return group_num;
if (VIR_ALLOC(tmp) < 0)
return -1;
- tmp->id = g_strdup(last_component(sysfspath));
+ tmp->id = g_path_get_basename(sysfspath);
/* @name sysfs attribute is optional, so getting ENOENT is fine */
MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true);
#include <config.h>
-#include "dirname.h"
#include "virnetdev.h"
#include "viralloc.h"
#include "virnetlink.h"
{
char *subsys_link = NULL;
char *abs_path = NULL;
- char *subsys = NULL;
+ g_autofree char *subsys = NULL;
bool ret = false;
subsys_link = g_strdup_printf("%s/subsystem", devpath);
goto cleanup;
}
- subsys = last_component(abs_path);
+ subsys = g_path_get_basename(abs_path);
ret = STRPREFIX(subsys, "pci");
cleanup:
#include <sys/stat.h>
#include <unistd.h>
-#include "dirname.h"
#include "virlog.h"
#include "vircommand.h"
#include "virerror.h"
}
/* path = "/sys/bus/pci/drivers/${drivername}" */
- *name = g_strdup(last_component(*path));
+ *name = g_path_get_basename(*path);
/* name = "${drivername}" */
ret = 0;
g_autofree char *devName = NULL;
g_autofree char *devPath = NULL;
g_autofree char *groupPath = NULL;
- const char *groupNumStr;
+ g_autofree char *groupNumStr = NULL;
unsigned int groupNum;
devName = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain, addr->bus,
return -1;
}
- groupNumStr = last_component(groupPath);
+ groupNumStr = g_path_get_basename(groupPath);
if (virStrToLong_ui(groupNumStr, NULL, 10, &groupNum) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("device %s iommu_group symlink %s has "
{
g_autofree char *devPath = NULL;
g_autofree char *groupPath = NULL;
- char *groupDev = NULL;
+ g_autofree char *groupFile = NULL;
if (!(devPath = virPCIFile(dev->name, "iommu_group")))
return NULL;
dev->name, devPath);
return NULL;
}
- groupDev = g_strdup_printf("/dev/vfio/%s", last_component(groupPath));
+ groupFile = g_path_get_basename(groupPath);
- return groupDev;
+ return g_strdup_printf("/dev/vfio/%s", groupFile);
}
static int
virPCIGetDeviceAddressFromSysfsLink(const char *device_link)
{
virPCIDeviceAddressPtr bdf = NULL;
- char *config_address = NULL;
+ g_autofree char *config_address = NULL;
g_autofree char *device_path = NULL;
if (!virFileExists(device_link)) {
return NULL;
}
- config_address = last_component(device_path);
+ config_address = g_path_get_basename(device_path);
if (VIR_ALLOC(bdf) < 0)
return NULL;
#include "virlog.h"
#include "vircommand.h"
#include "virrandom.h"
-#include "dirname.h"
#include "virprocess.h"
#include "virstring.h"
static size_t testCounter;
static virBitmapPtr testBitmap;
-char *progname;
-
virArch virTestHostArch = VIR_ARCH_X86_64;
virArch
size_t noutputs = 0;
virLogOutputPtr output = NULL;
virLogOutputPtr *outputs = NULL;
+ g_autofree char *baseprogname = NULL;
+ const char *progname;
if (getenv("VIR_TEST_FILE_ACCESS"))
VIR_TEST_PRELOAD(VIR_TEST_MOCK("virtest"));
VIR_TEST_PRELOAD(lib);
va_end(ap);
- progname = last_component(argv[0]);
+ progname = baseprogname = g_path_get_basename(argv[0]);
if (STRPREFIX(progname, "lt-"))
progname += 3;
# define fprintf virFilePrintf
#endif
-extern char *progname;
-
/* Makefile.am provides these two definitions */
#if !defined(abs_srcdir) || !defined(abs_builddir)
# error Fix Makefile.am
# include "viralloc.h"
# include "virstring.h"
# include "virfile.h"
-# include "dirname.h"
static int (*real_access)(const char *path, int mode);
static int (*real_open)(const char *path, int flags, ...);
pci_driver_handle_change(int fd G_GNUC_UNUSED, const char *path)
{
int ret;
- const char *file = last_component(path);
+ g_autofree char *file = g_path_get_basename(path);
if (STREQ(file, "bind"))
ret = pci_driver_handle_bind(path);