debuggers.hg

changeset 22700:63fd6f886f49

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>
author Christoph Egger <Christoph.Egger@amd.com>
date Thu Jan 06 14:25:10 2011 +0000 (2011-01-06)
parents 7b4c82f07281
children 6874a9d26fd9
files tools/libxl/libxl_utils.c tools/libxl/libxl_utils.h tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/libxl_utils.c	Wed Jan 05 23:54:15 2011 +0000
     1.2 +++ b/tools/libxl/libxl_utils.c	Thu Jan 06 14:25:10 2011 +0000
     1.3 @@ -43,6 +43,20 @@ static struct schedid_name schedid_name[
     1.4      { NULL, -1 }
     1.5  };
     1.6  
     1.7 +const char *libxl_basename(const char *name)
     1.8 +{
     1.9 +    const char *filename;
    1.10 +    if (name == NULL)
    1.11 +        return strdup(".");
    1.12 +    if (name[0] == '\0')
    1.13 +        return strdup(".");
    1.14 +
    1.15 +    filename = strrchr(name, '/');
    1.16 +    if (filename)
    1.17 +        return strdup(filename+1);
    1.18 +    return strdup(name);
    1.19 +}
    1.20 +
    1.21  unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus)
    1.22  {
    1.23      /* 256 pages (1MB) per vcpu,
     2.1 --- a/tools/libxl/libxl_utils.h	Wed Jan 05 23:54:15 2011 +0000
     2.2 +++ b/tools/libxl/libxl_utils.h	Thu Jan 06 14:25:10 2011 +0000
     2.3 @@ -18,6 +18,7 @@
     2.4  
     2.5  #include "libxl.h"
     2.6  
     2.7 +const char *libxl_basename(const char *name); /* returns string from strdup */
     2.8  unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus);
     2.9  int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
    2.10  char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
     3.1 --- a/tools/libxl/xl_cmdimpl.c	Wed Jan 05 23:54:15 2011 +0000
     3.2 +++ b/tools/libxl/xl_cmdimpl.c	Thu Jan 06 14:25:10 2011 +0000
     3.3 @@ -5489,7 +5489,7 @@ int main_cpupoolcreate(int argc, char **
     3.4      int config_len = 0;
     3.5      XLU_Config *config;
     3.6      const char *buf;
     3.7 -    char *name;
     3.8 +    const char *name;
     3.9      const char *sched;
    3.10      uint32_t poolid;
    3.11      int schedid = -1;
    3.12 @@ -5581,7 +5581,7 @@ int main_cpupoolcreate(int argc, char **
    3.13      if (!xlu_cfg_get_string (config, "name", &buf))
    3.14          name = strdup(buf);
    3.15      else
    3.16 -        name = basename(filename);
    3.17 +        name = libxl_basename(filename);
    3.18      if (!libxl_name_to_cpupoolid(&ctx, name, &poolid)) {
    3.19          fprintf(stderr, "Pool name \"%s\" already exists\n", name);
    3.20          return -ERROR_FAIL;