WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 4 of 9] libxl: add libxl_strdup convenience function

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 4 of 9] libxl: add libxl_strdup convenience function
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Mon, 12 Jul 2010 15:01:40 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Mon, 12 Jul 2010 07:07:57 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1278943296@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Use in preference to libxl_sprintf(..., "%s", "...")

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 8545cbf7f513 -r 6c6961e09c50 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Mon Jul 12 14:56:37 2010 +0100
+++ b/tools/libxl/libxl.c       Mon Jul 12 14:56:37 2010 +0100
@@ -1339,7 +1339,7 @@
                 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 @@
                                                  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 @@
 
     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 @@
     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 @@
     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 8545cbf7f513 -r 6c6961e09c50 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c  Mon Jul 12 14:56:37 2010 +0100
+++ b/tools/libxl/libxl_exec.c  Mon Jul 12 14:56:37 2010 +0100
@@ -100,7 +100,7 @@
     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 8545cbf7f513 -r 6c6961e09c50 tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c      Mon Jul 12 14:56:37 2010 +0100
+++ b/tools/libxl/libxl_internal.c      Mon Jul 12 14:56:37 2010 +0100
@@ -138,10 +138,20 @@
     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 8545cbf7f513 -r 6c6961e09c50 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Mon Jul 12 14:56:37 2010 +0100
+++ b/tools/libxl/libxl_internal.h      Mon Jul 12 14:56:37 2010 +0100
@@ -111,6 +111,7 @@
 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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel