[PATCH:xev 2/2] Use strncasecmp if available, instead of a tolower loop & strncmp
Peter Hutterer
peter.hutterer at who-t.net
Tue Jan 15 15:51:06 PST 2013
On Mon, Jan 14, 2013 at 11:29:46PM -0800, Alan Coopersmith wrote:
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
> configure.ac | 3 +++
> xev.c | 12 +++++++++---
> 2 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 0af7b2d..6016d62 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -26,6 +26,7 @@ AC_INIT([xev], [1.2.0],
> [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [xev])
> AC_CONFIG_SRCDIR([Makefile.am])
> AC_CONFIG_HEADERS([config.h])
> +AC_USE_SYSTEM_EXTENSIONS
>
> # Initialize Automake
> AM_INIT_AUTOMAKE([foreign dist-bzip2])
> @@ -37,6 +38,8 @@ m4_ifndef([XORG_MACROS_VERSION],
> XORG_MACROS_VERSION(1.8)
> XORG_DEFAULT_OPTIONS
>
> +AC_CHECK_FUNCS([strncasecmp])
> +
> # Checks for pkg-config packages
> PKG_CHECK_MODULES(XEV, [xrandr >= 1.2 x11 xproto >= 7.0.17])
>
> diff --git a/xev.c b/xev.c
> index 34a46aa..298c5c1 100644
> --- a/xev.c
> +++ b/xev.c
> @@ -32,6 +32,9 @@ from the X Consortium.
> * Author: Jim Fulton, MIT X Consortium
> */
>
> +#ifdef HAVE_CONFIG_H
> +# include "config.h"
> +#endif
> #include <stdio.h>
> #include <stdlib.h>
> #include <ctype.h>
> @@ -907,16 +910,19 @@ static int
> parse_backing_store (char *s)
> {
> size_t len = strlen (s);
> +#ifndef HAVE_STRNCASECMP
> char *cp;
>
> for (cp = s; *cp; cp++) {
> if (isascii (*cp) && isupper (*cp))
> *cp = tolower (*cp);
> }
> +#define strncasecmp strncmp
> +#endif
>
> - if (strncmp (s, "notuseful", len) == 0) return (NotUseful);
> - if (strncmp (s, "whenmapped", len) == 0) return (WhenMapped);
> - if (strncmp (s, "always", len) == 0) return (Always);
> + if (strncasecmp (s, "notuseful", len) == 0) return (NotUseful);
> + if (strncasecmp (s, "whenmapped", len) == 0) return (WhenMapped);
> + if (strncasecmp (s, "always", len) == 0) return (Always);
which systems do we support that don't have strncasecmp?
the man page suggests uppercase spelling "-bs {NotUseful,WhenMapped,Always}"
so this could break on those systems. maybe change the above to match the
spelling in the man page?
either way, both
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Cheers,
Peter
>
> usage ();
> }
> --
> 1.7.9.2
>
More information about the xorg-devel
mailing list