[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxl: add libxl_strdup convenience function



# HG changeset patch
# User Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
# Date 1279121983 -3600
# Node ID d0b384c3121eb545c49829b9c91e7050e71a3b5c
# Parent  14961eb33aacf8efba6ae8dff944b702ff945e5b
libxl: add libxl_strdup convenience function

Use in preference to libxl_sprintf(..., "%s", "...")

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/libxl/libxl.c          |   24 ++++++++++++------------
 tools/libxl/libxl_exec.c     |    2 +-
 tools/libxl/libxl_internal.c |   12 +++++++++++-
 tools/libxl/libxl_internal.h |    1 +
 4 files changed, 25 insertions(+), 14 deletions(-)

diff -r 14961eb33aac -r d0b384c3121e tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Jul 14 16:38:47 2010 +0100
+++ b/tools/libxl/libxl.c       Wed Jul 14 16:39:43 2010 +0100
@@ -1339,7 +1339,7 @@ int libxl_device_disk_add(struct libxl_c
                 flexarray_set(back, boffset++, "tapdisk-params");
                 flexarray_set(back, boffset++, libxl_sprintf(ctx, "%s:%s", 
device_disk_string_of_phystype(disk->phystype), disk->physpath));
                 flexarray_set(back, boffset++, "params");
-                flexarray_set(back, boffset++, libxl_sprintf(ctx, "%s", dev));
+                flexarray_set(back, boffset++, libxl_strdup(ctx, dev));
                 backend_type = "phy";
                 device_physdisk_major_minor(dev, &major, &minor);
                 flexarray_set(back, boffset++, "physical-device");
@@ -1467,7 +1467,7 @@ int libxl_device_nic_add(struct libxl_ct
                                                  nic->mac[0], nic->mac[1], 
nic->mac[2],
                                                  nic->mac[3], nic->mac[4], 
nic->mac[5]));
     flexarray_set(back, boffset++, "bridge");
-    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%s", nic->bridge));
+    flexarray_set(back, boffset++, libxl_strdup(ctx, nic->bridge));
     flexarray_set(back, boffset++, "handle");
     flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", nic->devid));
 
@@ -2020,13 +2020,13 @@ static int libxl_build_xenpv_qemu_args(s
 
     info->vnc = vfb->vnc;
     if (vfb->vnclisten)
-        info->vnclisten = libxl_sprintf(ctx, "%s", vfb->vnclisten);
+        info->vnclisten = libxl_strdup(ctx, vfb->vnclisten);
     info->vncdisplay = vfb->vncdisplay;
     info->vncunused = vfb->vncunused;
     if (vfb->vncpasswd)
         info->vncpasswd = vfb->vncpasswd;
     if (vfb->keymap)
-        info->keymap = libxl_sprintf(ctx, "%s", vfb->keymap);
+        info->keymap = libxl_strdup(ctx, vfb->keymap);
     info->sdl = vfb->sdl;
     info->opengl = vfb->opengl;
     for (i = 0; i < num_console; i++) {
@@ -2782,19 +2782,19 @@ const libxl_version_info* libxl_get_vers
     info->xen_version_major = xen_version >> 16;
     info->xen_version_minor = xen_version & 0xFF;
     xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra);
-    info->xen_version_extra = libxl_sprintf(ctx, "%s", u.xen_extra);
+    info->xen_version_extra = libxl_strdup(ctx, u.xen_extra);
 
     xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc);
-    info->compiler = libxl_sprintf(ctx, "%s", u.xen_cc.compiler);
-    info->compile_by = libxl_sprintf(ctx, "%s", u.xen_cc.compile_by);
-    info->compile_domain = libxl_sprintf(ctx, "%s", u.xen_cc.compile_domain);
-    info->compile_date = libxl_sprintf(ctx, "%s", u.xen_cc.compile_date);
+    info->compiler = libxl_strdup(ctx, u.xen_cc.compiler);
+    info->compile_by = libxl_strdup(ctx, u.xen_cc.compile_by);
+    info->compile_domain = libxl_strdup(ctx, u.xen_cc.compile_domain);
+    info->compile_date = libxl_strdup(ctx, u.xen_cc.compile_date);
 
     xc_version(ctx->xch, XENVER_capabilities, &u.xen_caps);
-    info->capabilities = libxl_sprintf(ctx, "%s", u.xen_caps);
+    info->capabilities = libxl_strdup(ctx, u.xen_caps);
 
     xc_version(ctx->xch, XENVER_changeset, &u.xen_chgset);
-    info->changeset = libxl_sprintf(ctx, "%s", u.xen_chgset);
+    info->changeset = libxl_strdup(ctx, u.xen_chgset);
 
     xc_version(ctx->xch, XENVER_platform_parameters, &u.p_parms);
     info->virt_start = u.p_parms.virt_start;
@@ -2802,7 +2802,7 @@ const libxl_version_info* libxl_get_vers
     info->pagesize = xc_version(ctx->xch, XENVER_pagesize, NULL);
 
     xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline);
-    info->commandline = libxl_sprintf(ctx, "%s", u.xen_commandline);
+    info->commandline = libxl_strdup(ctx, u.xen_commandline);
 
     return info;
 }
diff -r 14961eb33aac -r d0b384c3121e tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c  Wed Jul 14 16:38:47 2010 +0100
+++ b/tools/libxl/libxl_exec.c  Wed Jul 14 16:39:43 2010 +0100
@@ -100,7 +100,7 @@ int libxl_spawn_spawn(struct libxl_ctx *
     struct libxl_spawn_starting *for_spawn = starting->for_spawn;
 
     if (for_spawn) {
-        for_spawn->what = libxl_sprintf(ctx, "%s", what);
+        for_spawn->what = libxl_strdup(ctx, what);
         if (!for_spawn->what) return ERROR_NOMEM;
     }
 
diff -r 14961eb33aac -r d0b384c3121e tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c      Wed Jul 14 16:38:47 2010 +0100
+++ b/tools/libxl/libxl_internal.c      Wed Jul 14 16:39:43 2010 +0100
@@ -138,10 +138,20 @@ char *libxl_sprintf(struct libxl_ctx *ct
     return s;
 }
 
+char *libxl_strdup(struct libxl_ctx *ctx, const char *c)
+{
+    char *s = strdup(c);
+
+    if (s)
+        libxl_ptr_add(ctx, s);
+
+    return s;
+}
+
 char *libxl_dirname(struct libxl_ctx *ctx, const char *s)
 {
     char *c;
-    char *ptr = libxl_sprintf(ctx, "%s", s);
+    char *ptr = libxl_strdup(ctx, s);
 
     c = strrchr(ptr, '/');
     if (!c)
diff -r 14961eb33aac -r d0b384c3121e tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Wed Jul 14 16:38:47 2010 +0100
+++ b/tools/libxl/libxl_internal.h      Wed Jul 14 16:39:43 2010 +0100
@@ -111,6 +111,7 @@ void *libxl_zalloc(struct libxl_ctx *ctx
 void *libxl_zalloc(struct libxl_ctx *ctx, int bytes);
 void *libxl_calloc(struct libxl_ctx *ctx, size_t nmemb, size_t size);
 char *libxl_sprintf(struct libxl_ctx *ctx, const char *fmt, ...) 
PRINTF_ATTRIBUTE(2, 3);
+char *libxl_strdup(struct libxl_ctx *ctx, const char *c);
 char *libxl_dirname(struct libxl_ctx *ctx, const char *s);
 
 char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, 
int length);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.