From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 4 of 9] libxl: add libxl_strdup convenience function
Date: Mon, 12 Jul 2010 15:01:40 +0100 [thread overview]
Message-ID: <6c6961e09c5072548ece.1278943300@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1278943296@localhost.localdomain>
Use in preference to libxl_sprintf(..., "%s", "...")
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
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);
next prev parent reply other threads:[~2010-07-12 14:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-12 14:01 [PATCH 0 of 9] libxl/xl: support for domain 0 bootloader (e.g. pygrub) Ian Campbell
2010-07-12 14:01 ` [PATCH 1 of 9] pygrub: introduce easier to parse output format Ian Campbell
2010-07-12 14:01 ` [PATCH 2 of 9] xenconsole: do not exit if a pty device is missing Ian Campbell
2010-07-12 14:01 ` [PATCH 3 of 9] libxl: add printf attribute to libxl_xs_write and fixup resulting warnings Ian Campbell
2010-07-12 14:01 ` Ian Campbell [this message]
2010-07-12 14:01 ` [PATCH 5 of 9] libxl: fix typo Ian Campbell
2010-07-12 14:01 ` [PATCH 6 of 9] libxl/xl: exec xenconsole in current process, defer decision to fork to caller Ian Campbell
2010-07-12 14:01 ` [PATCH 7 of 9] libxl: support mapping files rather than carrying paths around Ian Campbell
2010-07-12 14:01 ` [PATCH 8 of 9] libxl: add function to attach/detach a disk to/from the local VM Ian Campbell
2010-07-12 14:01 ` [PATCH 9 of 9] libxl/xl: support running bootloader (e.g. pygrub) in domain 0 Ian Campbell
2010-07-13 18:23 ` [PATCH 0 of 9] libxl/xl: support for domain 0 bootloader (e.g. pygrub) Ian Jackson
2010-07-14 1:24 ` Zhigang Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c6961e09c5072548ece.1278943300@localhost.localdomain \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).