summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--admin/ChangeLog5
-rwxr-xr-xadmin/merge-gnulib2
-rw-r--r--configure.in1
-rw-r--r--lib-src/ChangeLog7
-rw-r--r--lib-src/etags.c61
-rw-r--r--lib/gnulib.mk14
-rw-r--r--lwlib/ChangeLog6
-rw-r--r--lwlib/lwlib.c28
-rw-r--r--m4/gnulib-comp.m47
-rw-r--r--src/ChangeLog7
-rw-r--r--src/dispextern.h12
-rw-r--r--src/nsfns.m5
-rw-r--r--src/nsterm.m5
-rw-r--r--src/xfaces.c24
15 files changed, 73 insertions, 120 deletions
diff --git a/ChangeLog b/ChangeLog
index 359035e5800..b85855511bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2012-07-06 Paul Eggert <eggert@cs.ucla.edu>
+ Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+ This is safer than strcasecmp, which has unspecified behavior
+ outside the POSIX locale and in practice sometimes does not work
+ in multibyte locales. Similarly for c_strncasecmp and strncasecmp.
+ * configure.in (strcasecmp, strncasecmp): Remove checks.
+ * lib/c-ctype.c, lib/c-ctype.h, lib/c-strcase.h, lib/c-strcasecmp.c:
+ * lib/c-strncasecmp.c: New files, taken from gnulib.
+ * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
+
Merge from gnulib, incorporating:
2012-07-06 timespec-sub: avoid duplicate include
Reported by Juanma Barranquero.
diff --git a/admin/ChangeLog b/admin/ChangeLog
index 4563f2e6618..53b6143c82c 100644
--- a/admin/ChangeLog
+++ b/admin/ChangeLog
@@ -1,3 +1,8 @@
+2012-07-06 Paul Eggert <eggert@cs.ucla.edu>
+
+ Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+ * merge-gnulib (GNULIB_MODULES): Add c-strcase.
+
2012-07-05 Dmitry Antipov <dmantipov@yandex.ru>
* coccinelle/xzalloc.cocci: Semantic patch to convert
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index d33807551d6..727b701cfe0 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -26,7 +26,7 @@
GNULIB_URL=git://git.savannah.gnu.org/gnulib.git
GNULIB_MODULES='
- alloca-opt
+ alloca-opt c-strcase
careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512
dtoastr dtotimespec dup2
filemode getloadavg getopt-gnu gettime gettimeofday
diff --git a/configure.in b/configure.in
index dde8bcca855..1a43aed7540 100644
--- a/configure.in
+++ b/configure.in
@@ -2707,7 +2707,6 @@ gai_strerror mkstemp getline getdelim fsync sync \
difftime posix_memalign \
getpwent endpwent getgrent endgrent \
touchlock \
-strcasecmp strncasecmp \
cfmakeraw cfsetspeed copysign __executable_start)
dnl Cannot use AC_CHECK_FUNCS
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 11f2a688cd2..56f1551e8ba 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,10 @@
+2012-07-06 Paul Eggert <eggert@cs.ucla.edu>
+
+ Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+ * etags.c: Include c-strcase.h.
+ (etags_strcasecmp, etags_strncasecmp): Remove.
+ All uses replaced with c_strcasecmp and c_strncasecmp.
+
2012-07-06 Andreas Schwab <schwab@linux-m68k.org>
* make-docfile.c (write_globals): Warn about duplicate function
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 2e05e37e80f..5bdf3402e55 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -144,6 +144,7 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <c-strcase.h>
#include <assert.h>
#ifdef NDEBUG
@@ -174,9 +175,9 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
#endif
#define streq(s,t) (assert ((s)!=NULL || (t)!=NULL), !strcmp (s, t))
-#define strcaseeq(s,t) (assert ((s)!=NULL && (t)!=NULL), !etags_strcasecmp (s, t))
+#define strcaseeq(s,t) (assert ((s)!=NULL && (t)!=NULL), !c_strcasecmp (s, t))
#define strneq(s,t,n) (assert ((s)!=NULL || (t)!=NULL), !strncmp (s, t, n))
-#define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !etags_strncasecmp (s, t, n))
+#define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !c_strncasecmp (s, t, n))
#define CHARS 256 /* 2^sizeof(char) */
#define CHAR(x) ((unsigned int)(x) & (CHARS - 1))
@@ -375,16 +376,6 @@ static char *savenstr (const char *, int);
static char *savestr (const char *);
static char *etags_strchr (const char *, int);
static char *etags_strrchr (const char *, int);
-#ifdef HAVE_STRCASECMP
-#define etags_strcasecmp(x,y) strcasecmp ((x), (y))
-#else
-static int etags_strcasecmp (const char *, const char *);
-#endif
-#ifdef HAVE_STRNCASECMP
-#define etags_strncasecmp(x,y,z) strncasecmp ((x), (y), (z))
-#else
-static int etags_strncasecmp (const char *, const char *, int);
-#endif
static char *etags_getcwd (void);
static char *relative_filename (char *, char *);
static char *absolute_filename (char *, char *);
@@ -6314,52 +6305,6 @@ etags_strchr (register const char *sp, register int c)
return NULL;
}
-#ifndef HAVE_STRCASECMP
-/*
- * Compare two strings, ignoring case for alphabetic characters.
- *
- * Same as BSD's strcasecmp, included for portability.
- */
-static int
-etags_strcasecmp (register const char *s1, register const char *s2)
-{
- while (*s1 != '\0'
- && (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) == lowcase (*s2)
- : *s1 == *s2))
- s1++, s2++;
-
- return (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) - lowcase (*s2)
- : *s1 - *s2);
-}
-#endif /* HAVE_STRCASECMP */
-
-#ifndef HAVE_STRNCASECMP
-/*
- * Compare two strings, ignoring case for alphabetic characters.
- * Stop after a given number of characters
- *
- * Same as BSD's strncasecmp, included for portability.
- */
-static int
-etags_strncasecmp (register const char *s1, register const char *s2, register int n)
-{
- while (*s1 != '\0' && n-- > 0
- && (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) == lowcase (*s2)
- : *s1 == *s2))
- s1++, s2++;
-
- if (n < 0)
- return 0;
- else
- return (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) - lowcase (*s2)
- : *s1 - *s2);
-}
-#endif /* HAVE_STRCASECMP */
-
/* Skip spaces (end of string is not space), return new pointer. */
static char *
skip_spaces (char *cp)
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 20aa19d93a5..6e2bf89786c 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -21,7 +21,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdarg stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timespec-add timespec-sub utimens warnings
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdarg stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timespec-add timespec-sub utimens warnings
MOSTLYCLEANFILES += core *.stackdump
@@ -64,6 +64,18 @@ EXTRA_DIST += allocator.h
## end gnulib module allocator
+## begin gnulib module c-ctype
+
+libgnu_a_SOURCES += c-ctype.h c-ctype.c
+
+## end gnulib module c-ctype
+
+## begin gnulib module c-strcase
+
+libgnu_a_SOURCES += c-strcase.h c-strcasecmp.c c-strncasecmp.c
+
+## end gnulib module c-strcase
+
## begin gnulib module careadlinkat
libgnu_a_SOURCES += careadlinkat.c
diff --git a/lwlib/ChangeLog b/lwlib/ChangeLog
index 7f87c5d8e6a..ab1212441bb 100644
--- a/lwlib/ChangeLog
+++ b/lwlib/ChangeLog
@@ -1,3 +1,9 @@
+2012-07-06 Paul Eggert <eggert@cs.ucla.edu>
+
+ Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+ * lwlib.c: Include c-strcase.h.
+ (lwlib_strcasecmp): Remove. All uses replaced with c_strcasecmp.
+
2012-06-26 Paul Eggert <eggert@cs.ucla.edu>
Clean out last vestiges of the old HAVE_CONFIG_H stuff.
diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c
index d436b18d222..5820be8d7a4 100644
--- a/lwlib/lwlib.c
+++ b/lwlib/lwlib.c
@@ -24,6 +24,7 @@ Boston, MA 02110-1301, USA. */
#include <setjmp.h>
#include <lisp.h>
+#include <c-strcase.h>
#include <sys/types.h>
#include <stdio.h>
@@ -112,31 +113,6 @@ safe_strdup (const char *s)
return result;
}
-#ifdef HAVE_STRCASECMP
-#define lwlib_strcasecmp(x,y) strcasecmp ((x), (y))
-#else
-
-/* Like strcmp but ignore differences in case. */
-
-static int
-lwlib_strcasecmp (const char *s1, const char *s2)
-{
- while (1)
- {
- int c1 = *s1++;
- int c2 = *s2++;
- if (isupper (c1))
- c1 = tolower (c1);
- if (isupper (c2))
- c2 = tolower (c2);
- if (c1 != c2)
- return (c1 > c2 ? 1 : -1);
- if (c1 == 0)
- return 0;
- }
-}
-#endif /* HAVE_STRCASECMP */
-
static void
safe_free_str (char *s)
{
@@ -733,7 +709,7 @@ find_in_table (const char *type, const widget_creation_entry *table)
{
const widget_creation_entry* cur;
for (cur = table; cur->type; cur++)
- if (!lwlib_strcasecmp (type, cur->type))
+ if (!c_strcasecmp (type, cur->type))
return cur->function;
return NULL;
}
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 17ece1cfe35..824c8bbffc8 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -40,6 +40,8 @@ AC_DEFUN([gl_EARLY],
AC_REQUIRE([gl_PROG_AR_RANLIB])
# Code from module alloca-opt:
# Code from module allocator:
+ # Code from module c-ctype:
+ # Code from module c-strcase:
# Code from module careadlinkat:
# Code from module clock-time:
# Code from module crypto/md5:
@@ -518,6 +520,11 @@ AC_DEFUN([gl_FILE_LIST], [
lib/alloca.in.h
lib/allocator.c
lib/allocator.h
+ lib/c-ctype.c
+ lib/c-ctype.h
+ lib/c-strcase.h
+ lib/c-strcasecmp.c
+ lib/c-strncasecmp.c
lib/careadlinkat.c
lib/careadlinkat.h
lib/dosname.h
diff --git a/src/ChangeLog b/src/ChangeLog
index 96458770122..3f8cbdff476 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,12 @@
2012-07-06 Paul Eggert <eggert@cs.ucla.edu>
+ Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+ * dispextern.h, nsfns.m, nsterm.m: Include <c-strcase.h>.
+ * dispextern.h (xstrcasecmp): Rewrite using c_strcasecmp.
+ * nsfns.m (x_get_string_resource): Use c_strncasecmp, not strncasecmp.
+ * nsterm.m (ns_default): Use c_strcasecmp, not strcasecmp.
+ * xfaces.c (xstrcasecmp) [!HAVE_STRCASECMP]: Remove.
+
* xfont.c (compare_font_names): Redo to omit the need for casts.
2012-07-06 Andreas Schwab <schwab@linux-m68k.org>
diff --git a/src/dispextern.h b/src/dispextern.h
index 4672d108e93..7d9f913e4f1 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -46,6 +46,13 @@ typedef struct {
#include "msdos.h"
#endif
+#include <c-strcase.h>
+static inline int
+xstrcasecmp (char const *a, char const *b)
+{
+ return c_strcasecmp (a, b);
+}
+
#ifdef HAVE_X_WINDOWS
typedef struct x_display_info Display_Info;
typedef XImage * XImagePtr;
@@ -3198,11 +3205,6 @@ void unload_color (struct frame *, unsigned long);
char *choose_face_font (struct frame *, Lisp_Object *, Lisp_Object,
int *);
void prepare_face_for_display (struct frame *, struct face *);
-#ifdef HAVE_STRCASECMP
-#define xstrcasecmp(x,y) strcasecmp ((x), (y))
-#else
-int xstrcasecmp (const char *, const char *);
-#endif
int lookup_named_face (struct frame *, Lisp_Object, int);
int lookup_basic_face (struct frame *, int);
int smaller_face (struct frame *, int, int);
diff --git a/src/nsfns.m b/src/nsfns.m
index 5303a5ec313..47943e5d98a 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -33,6 +33,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
#include <signal.h>
#include <math.h>
#include <setjmp.h>
+#include <c-strcase.h>
#include "lisp.h"
#include "blockinput.h"
@@ -2226,8 +2227,8 @@ x_get_string_resource (XrmDatabase rdb, char *name, char *class)
res = ns_get_defaults_value (toCheck);
return !res ? NULL :
- (!strncasecmp (res, "YES", 3) ? "true" :
- (!strncasecmp (res, "NO", 2) ? "false" : res));
+ (!c_strncasecmp (res, "YES", 3) ? "true" :
+ (!c_strncasecmp (res, "NO", 2) ? "false" : res));
}
diff --git a/src/nsterm.m b/src/nsterm.m
index ae536638c33..1cd4c1c4271 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -36,6 +36,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
#include <signal.h>
#include <unistd.h>
#include <setjmp.h>
+#include <c-strcase.h>
#include "lisp.h"
#include "blockinput.h"
@@ -3848,9 +3849,9 @@ ns_default (const char *parameter, Lisp_Object *result,
{
double f;
char *pos;
- if (strcasecmp (value, "YES") == 0)
+ if (c_strcasecmp (value, "YES") == 0)
*result = yesval;
- else if (strcasecmp (value, "NO") == 0)
+ else if (c_strcasecmp (value, "NO") == 0)
*result = noval;
else if (is_float && (f = strtod (value, &pos), pos != value))
*result = make_float (f);
diff --git a/src/xfaces.c b/src/xfaces.c
index a1062a44232..bc42cb4312a 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -715,30 +715,6 @@ x_free_gc (struct frame *f, GC gc)
}
#endif /* HAVE_NS */
-#ifndef HAVE_STRCASECMP
-/* Like strcasecmp/stricmp. Used to compare parts of font names which
- are in ISO8859-1. */
-
-int
-xstrcasecmp (const char *s1, const char *s2)
-{
- while (*s1 && *s2)
- {
- unsigned char b1 = *s1;
- unsigned char b2 = *s2;
- unsigned char c1 = tolower (b1);
- unsigned char c2 = tolower (b2);
- if (c1 != c2)
- return c1 < c2 ? -1 : 1;
- ++s1, ++s2;
- }
-
- if (*s1 == 0)
- return *s2 == 0 ? 0 : -1;
- return 1;
-}
-#endif /* HAVE_STRCASECMP */
-
/* If FRAME is nil, return a pointer to the selected frame.
Otherwise, check that FRAME is a live frame, and return a pointer
to it. NPARAM is the parameter number of FRAME, for