qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Stefan Weil <sw@weilnetz.de>,
	qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 6/6] trace/simple: Replace asprintf by g_strdup_printf
Date: Tue, 14 Aug 2012 13:56:28 +0100	[thread overview]
Message-ID: <1344948988-8627-7-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1344948988-8627-1-git-send-email-stefanha@linux.vnet.ibm.com>

From: Stefan Weil <sw@weilnetz.de>

asprintf is not available for all hosts. g_strdup_printf is
more portable and simplifies the code because if does not
need error handling.

The static variable does not need an explicit assignment to be NULL.

Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 trace/simple.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/trace/simple.c b/trace/simple.c
index 8e175ec..d83681b 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -55,7 +55,7 @@ static unsigned int trace_idx;
 static unsigned int writeout_idx;
 static uint64_t dropped_events;
 static FILE *trace_fp;
-static char *trace_file_name = NULL;
+static char *trace_file_name;
 
 /* * Trace buffer entry */
 typedef struct {
@@ -329,18 +329,12 @@ bool st_set_trace_file(const char *file)
 {
     st_set_trace_file_enabled(false);
 
-    free(trace_file_name);
+    g_free(trace_file_name);
 
     if (!file) {
-        if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()) < 0) {
-            trace_file_name = NULL;
-            return false;
-        }
+        trace_file_name = g_strdup_printf(CONFIG_TRACE_FILE, getpid());
     } else {
-        if (asprintf(&trace_file_name, "%s", file) < 0) {
-            trace_file_name = NULL;
-            return false;
-        }
+        trace_file_name = g_strdup_printf("%s", file);
     }
 
     st_set_trace_file_enabled(true);
-- 
1.7.10.4

  parent reply	other threads:[~2012-08-14 12:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14 12:56 [Qemu-devel] [PULL 0/6 1.2] Tracing patches for QEMU 1.2 Stefan Hajnoczi
2012-08-14 12:56 ` [Qemu-devel] [PATCH 1/6] trace: rename TraceRecordHeader to TraceLogHeader Stefan Hajnoczi
2012-08-14 12:56 ` [Qemu-devel] [PATCH 2/6] trace: remove unnecessary write_to_buffer() typecasting Stefan Hajnoczi
2012-08-14 12:56 ` [Qemu-devel] [PATCH 3/6] trace: drop unused TraceBufferRecord->next_tbuf_idx field Stefan Hajnoczi
2012-08-14 12:56 ` [Qemu-devel] [PATCH 4/6] trace: avoid pointer aliasing in trace_record_finish() Stefan Hajnoczi
2012-08-14 12:56 ` [Qemu-devel] [PATCH 5/6] trace/simple: Fix compiler warning for 32 bit hosts Stefan Hajnoczi
2012-08-14 12:56 ` Stefan Hajnoczi [this message]
2012-08-14 18:44 ` [Qemu-devel] [PULL 0/6 1.2] Tracing patches for QEMU 1.2 Anthony Liguori
2012-08-15  7:46   ` Stefan Hajnoczi

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=1344948988-8627-7-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /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).