From patchwork Mon Aug 13 19:51:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 177041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3B2572C008D for ; Tue, 14 Aug 2012 05:51:35 +1000 (EST) Received: from localhost ([::1]:38582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10fl-0004w8-A2 for incoming@patchwork.ozlabs.org; Mon, 13 Aug 2012 15:51:33 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10fZ-0004m1-Hq for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:51:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T10fW-00055x-Ai for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:51:21 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:46547) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10fW-00055t-4R for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:51:18 -0400 Received: from localhost (v220110690675601.yourvserver.net.local [127.0.0.1]) by v220110690675601.yourvserver.net (Postfix) with ESMTP id 938BB72800C2; Mon, 13 Aug 2012 21:51:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at weilnetz.de Received: from v220110690675601.yourvserver.net ([127.0.0.1]) by localhost (v220110690675601.yourvserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bZzfudnxM3Jh; Mon, 13 Aug 2012 21:51:17 +0200 (CEST) Received: by v220110690675601.yourvserver.net (Postfix, from userid 1000) id 4AEE272800CC; Mon, 13 Aug 2012 21:51:17 +0200 (CEST) From: Stefan Weil To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2012 21:51:16 +0200 Message-Id: <1344887476-22308-1-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 1.7.10 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 78.47.199.172 Cc: Stefan Weil , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] trace/simple: Replace asprintf by g_strdup_printf X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- trace/simple.c | 14 ++++---------- 1 files changed, 4 insertions(+), 10 deletions(-) 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);