From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMe9P-0005ji-7j for qemu-devel@nongnu.org; Wed, 27 Aug 2014 10:24:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMe9K-00070N-42 for qemu-devel@nongnu.org; Wed, 27 Aug 2014 10:24:39 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:38497 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMe9J-000705-Jb for qemu-devel@nongnu.org; Wed, 27 Aug 2014 10:24:34 -0400 Date: Wed, 27 Aug 2014 16:23:45 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140827142345.GE31176@irqsave.net> References: <1409137736-827-1-git-send-email-stefanha@redhat.com> <1409137736-827-6-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1409137736-827-6-git-send-email-stefanha@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 5/6] block: sort formats alphabetically in bdrv_iterate_format() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Peter Maydell , Riku Voipio , qemu-devel@nongnu.org, Markus Armbruster , Gerd Hoffmann , Andreas Faerber The Wednesday 27 Aug 2014 =E0 12:08:55 (+0100), Stefan Hajnoczi wrote : > Format names are best consumed in alphabetical order. This makes > human-readable output easy to produce. >=20 > bdrv_iterate_format() already has an array of format strings. Sort the= m > before invoking the iteration callback. >=20 > Signed-off-by: Stefan Hajnoczi > --- > block.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) >=20 > diff --git a/block.c b/block.c > index e9380f6..1df13ac 100644 > --- a/block.c > +++ b/block.c > @@ -3744,11 +3744,17 @@ const char *bdrv_get_format_name(BlockDriverSta= te *bs) > return bs->drv ? bs->drv->format_name : NULL; > } > =20 > +static int qsort_strcmp(const void *a, const void *b) > +{ > + return strcmp(a, b); > +} > + > void bdrv_iterate_format(void (*it)(void *opaque, const char *name), > void *opaque) > { > BlockDriver *drv; > int count =3D 0; > + int i; > const char **formats =3D NULL; > =20 > QLIST_FOREACH(drv, &bdrv_drivers, list) { > @@ -3762,10 +3768,16 @@ void bdrv_iterate_format(void (*it)(void *opaqu= e, const char *name), > if (!found) { > formats =3D g_renew(const char *, formats, count + 1); > formats[count++] =3D drv->format_name; > - it(opaque, drv->format_name); > } > } > } > + > + qsort(formats, count, sizeof(formats[0]), qsort_strcmp); We are lucky this is not using qsort_r which was added in 2008 after RHEL= 5 release :) Reviewed-by: Beno=EEt Canet > + > + for (i =3D 0; i < count; i++) { > + it(opaque, formats[i]); > + } > + > g_free(formats); > } > =20 > --=20 > 1.9.3 >=20 >=20