From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1Gfy-0006To-NH for qemu-devel@nongnu.org; Tue, 14 Aug 2012 08:56:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1Gft-0005pP-BC for qemu-devel@nongnu.org; Tue, 14 Aug 2012 08:56:50 -0400 Received: from e06smtp14.uk.ibm.com ([195.75.94.110]:53295) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1Gft-0005p3-2t for qemu-devel@nongnu.org; Tue, 14 Aug 2012 08:56:45 -0400 Received: from /spool/local by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Aug 2012 13:56:43 +0100 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7ECuZJ413041840 for ; Tue, 14 Aug 2012 12:56:35 GMT Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7ECues3019138 for ; Tue, 14 Aug 2012 06:56:41 -0600 From: Stefan Hajnoczi Date: Tue, 14 Aug 2012 13:56:28 +0100 Message-Id: <1344948988-8627-7-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1344948988-8627-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1344948988-8627-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 6/6] trace/simple: Replace asprintf by g_strdup_printf List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Stefan Weil , qemu-devel@nongnu.org, Stefan Hajnoczi From: Stefan Weil 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 Signed-off-by: Stefan Weil Signed-off-by: Stefan Hajnoczi --- 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