diff mbox

trace/simple: Replace asprintf by g_strdup_printf

Message ID 1344887476-22308-1-git-send-email-sw@weilnetz.de
State Accepted
Headers show

Commit Message

Stefan Weil Aug. 13, 2012, 7:51 p.m. UTC
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>
---
 trace/simple.c |   14 ++++----------
 1 files changed, 4 insertions(+), 10 deletions(-)

Comments

Stefan Hajnoczi Aug. 14, 2012, 12:30 p.m. UTC | #1
On Mon, Aug 13, 2012 at 09:51:16PM +0200, Stefan Weil wrote:
> 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>
> ---
>  trace/simple.c |   14 ++++----------
>  1 files changed, 4 insertions(+), 10 deletions(-)

Thanks, applied to the tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan
diff mbox

Patch

diff --git a/trace/simple.c b/trace/simple.c
index b700ea3..92a8ea3 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 {
@@ -332,18 +332,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);