libxl: Implement libxl_basename()

This patch implements libxl_basename() as a portable replacement
for GNU vs. POSIX basename.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
This commit is contained in:
Christoph Egger committed 2011-01-06 14:25:10 +00:00
1 parent f1bbc236c6
commit d8318dc19b
3 files changed
+17 -2

No files matched your search

+14
View File
@@ -43,6 +43,20 @@ static struct schedid_name schedid_name[] = {
{ NULL, -1 }
};
const char *libxl_basename(const char *name)
{
const char *filename;
if (name == NULL)
return strdup(".");
if (name[0] == '\0')
return strdup(".");
filename = strrchr(name, '/');
if (filename)
return strdup(filename+1);
return strdup(name);
}
unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus)
{
/* 256 pages (1MB) per vcpu,
+1
View File
@@ -18,6 +18,7 @@
#include "libxl.h"
const char *libxl_basename(const char *name); /* returns string from strdup */
unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus);
int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
+2 -2
View File
@@ -5489,7 +5489,7 @@ int main_cpupoolcreate(int argc, char **argv)
int config_len = 0;
XLU_Config *config;
const char *buf;
char *name;
const char *name;
const char *sched;
uint32_t poolid;
int schedid = -1;
@@ -5581,7 +5581,7 @@ int main_cpupoolcreate(int argc, char **argv)
if (!xlu_cfg_get_string (config, "name", &buf))
name = strdup(buf);
else
name = basename(filename);
name = libxl_basename(filename);
if (!libxl_name_to_cpupoolid(&ctx, name, &poolid)) {
fprintf(stderr, "Pool name \"%s\" already exists\n", name);
return -ERROR_FAIL;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.