libxl: Implement libxl_basename()
PATCH 1/1 libxl: Implement libxl_basename()
Hi!
This patch implements libxl_basename() as a portable replacement for GNU vs. POSIX basename.
Signed-off-by Christoph Egger <[email protected]>
P.S. This patch requires 'libxl: constify libxl_create_cpupool()' to compile.
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
tools/libxl/libxl_utils.c +14 -0
@@ -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,
tools/libxl/libxl_utils.h +1 -0
@@ -18,6 +18,7 @@#include "libxl.h" +const char *libxl_basename (const char *name);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);
tools/libxl/xl_cmdimpl.c +2 -2
@@ -5365,7 +5365,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 ;
@@ -5455,7 +5455,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-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Christoph Egger writes ("[Xen-devel] [PATCH][TOOLS] libxl: Implement libxl_basename()"):
Quoted 2 lines
This patch implements
libxl_basename()as a portable replacement for GNU vs. POSIX basename.
Thanks, I have applied this. I added a comment to the declaration of libxl_basename saying it returns a string from strdup, which may not be what the next user would expect.
Ian.