# HG changeset patch
# User Christoph Egger <Christoph.Egger@xxxxxxx>
# Date 1294323910 0
# Node ID 63fd6f886f49683de71bb3f687c52eb123adac6e
# Parent 7b4c82f07281ad9c48b652e2a305a7be607c5283
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@xxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
tools/libxl/libxl_utils.c | 14 ++++++++++++++
tools/libxl/libxl_utils.h | 1 +
tools/libxl/xl_cmdimpl.c | 4 ++--
3 files changed, 17 insertions(+), 2 deletions(-)
diff -r 7b4c82f07281 -r 63fd6f886f49 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Wed Jan 05 23:54:15 2011 +0000
+++ b/tools/libxl/libxl_utils.c Thu Jan 06 14:25:10 2011 +0000
@@ -42,6 +42,20 @@ static struct schedid_name schedid_name[
{ "credit2", XEN_SCHEDULER_CREDIT2 },
{ 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)
{
diff -r 7b4c82f07281 -r 63fd6f886f49 tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h Wed Jan 05 23:54:15 2011 +0000
+++ b/tools/libxl/libxl_utils.h Thu Jan 06 14:25:10 2011 +0000
@@ -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);
diff -r 7b4c82f07281 -r 63fd6f886f49 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Wed Jan 05 23:54:15 2011 +0000
+++ b/tools/libxl/xl_cmdimpl.c Thu Jan 06 14:25:10 2011 +0000
@@ -5489,7 +5489,7 @@ int main_cpupoolcreate(int argc, char **
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 **
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;
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|