[PATCH:xf86-input-mouse] Use asprintf (or Xprintf on old servers) instead of strdup+sprintf

Patrik Jakobsson patrik.r.jakobsson at gmail.com
Sat Jan 4 11:35:06 PST 2014


On Thu, Oct 24, 2013 at 7:56 AM, Alan Coopersmith
<alan.coopersmith at oracle.com> wrote:
> On 10/21/13 03:02 PM, Peter Hutterer wrote:
>>
>> On Sat, Oct 19, 2013 at 09:51:31PM -0700, Alan Coopersmith wrote:
>>>
>>>
>>> +/* Xorg >= 1.10 provides an asprintf() implementation even if libc
>>> doesn't */
>>> +#include "xorgVersion.h"
>>> +#if defined(HAVE_ASPRINTF) || \
>>> +    (XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,9,99,901,0))
>>
>>
>> use 1.10.0 as version here. let's not worry about release candidates here
>> and
>> it will make the code easier to read.
>
>
> Okay - I'd just copied & pasted that from one of the other drivers using the
> server provided asprintf.
>
>
>> if Xprintf is an API that we still support, already uses
>> asprintf anyway why not use just that and ditch the #ifdef's?
>
>
> Because it's marked deprecated so causes warnings.   I don't remember how
> long
> we said we'd keep Xprintf - probably could drop it in one of these ABI
> breaking
> releases, since it's been a couple years now.

Hi
asprintf needs _GNU_SOURCE to be defined or you'll get an implicit declaration
and build failure. I fixed it with:

diff --git a/src/mouse.c b/src/mouse.c
index 2da2b4d..6678d24 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -47,6 +47,10 @@
 #include "config.h"
 #endif

+#if defined(HAVE_ASPRINTF)
+# define _GNU_SOURCE
+#endif
+
 #include <xorg-server.h>
 #include <math.h>
 #include <string.h>


Thanks
Patrik


More information about the xorg-devel mailing list