From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baSKh-0004ip-VW for qemu-devel@nongnu.org; Thu, 18 Aug 2016 14:46:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baSKZ-0002BR-IE for qemu-devel@nongnu.org; Thu, 18 Aug 2016 14:46:26 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56384) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baSKZ-0002BA-8j for qemu-devel@nongnu.org; Thu, 18 Aug 2016 14:46:19 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7IIiDbq037803 for ; Thu, 18 Aug 2016 14:46:18 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 24v7sk1yhm-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 18 Aug 2016 14:46:17 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Aug 2016 19:46:15 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 080EE2190056 for ; Thu, 18 Aug 2016 19:45:37 +0100 (BST) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u7IIkCsG32964644 for ; Thu, 18 Aug 2016 18:46:12 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u7IIkCbi013462 for ; Thu, 18 Aug 2016 12:46:12 -0600 From: Sascha Silbe Date: Thu, 18 Aug 2016 20:46:02 +0200 In-Reply-To: <1471545963-11720-1-git-send-email-silbe@linux.vnet.ibm.com> References: <1471545963-11720-1-git-send-email-silbe@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Message-Id: <1471545963-11720-2-git-send-email-silbe@linux.vnet.ibm.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 1/2] glib: add compatibility implementation for g_dir_make_tmp() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Paolo Bonzini Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Peter Maydell We're going to make use of g_dir_make_tmp() in test-logging. Provide a compatibility implementation of it for glib < 2.30. May behave differently in some edge cases (e.g. pattern only at the end of the template, the file name is not part of the error message), but good enough in practice. Signed-off-by: Sascha Silbe --- v1=E2=86=92v2: - new patch include/glib-compat.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index 01aa7b3..de64ac2 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -48,6 +48,27 @@ static inline gint64 qemu_g_get_monotonic_time(void) gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout); #endif =20 +#if !GLIB_CHECK_VERSION(2, 30, 0) +/* Not a 100% compatible implementation, but good enough for most + * cases. Placeholders are only supported at the end of the + * template. */ +static inline gchar *qemu_g_dir_make_tmp(gchar const *tmpl, GError **err= or) +{ + gchar const *template =3D tmpl ? tmpl : ".XXXXXX"; + gchar *path =3D g_build_filename(g_get_tmp_dir(), template, NULL); + + if (mkdtemp(path) !=3D NULL) { + return path; + } + /* Error occurred, clean up. */ + g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), + "mkdtemp() failed"); + g_free(path); + return NULL; +} +#define g_dir_make_tmp(tmpl, error) qemu_g_dir_make_tmp(tmpl, error) +#endif /* glib 2.30 */ + #if !GLIB_CHECK_VERSION(2, 31, 0) /* before glib-2.31, GMutex and GCond was dynamic-only (there was a sepa= rate * GStaticMutex, but it didn't work with condition variables). --=20 1.9.1