diff options
Diffstat (limited to 'gl')
-rw-r--r-- | gl/Makefile.am | 42 | ||||
-rw-r--r-- | gl/m4/gnulib-cache.m4 | 3 | ||||
-rw-r--r-- | gl/m4/gnulib-comp.m4 | 17 | ||||
-rw-r--r-- | gl/m4/strcase.m4 | 45 | ||||
-rw-r--r-- | gl/m4/strings_h.m4 | 52 | ||||
-rw-r--r-- | gl/strcasecmp.c | 62 | ||||
-rw-r--r-- | gl/strings.in.h | 122 | ||||
-rw-r--r-- | gl/strncasecmp.c | 62 |
8 files changed, 403 insertions, 2 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am index c2e8e5a..4339b2c 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am | |||
@@ -21,7 +21,7 @@ | |||
21 | # the same distribution terms as the rest of that program. | 21 | # the same distribution terms as the rest of that program. |
22 | # | 22 | # |
23 | # Generated by gnulib-tool. | 23 | # Generated by gnulib-tool. |
24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname environ floorf fsusage getaddrinfo gethostname getloadavg getopt-gnu gettext mountlist regex setenv strsep timegm unsetenv vasprintf vsnprintf | 24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname environ floorf fsusage getaddrinfo gethostname getloadavg getopt-gnu gettext mountlist regex setenv strcase strsep timegm unsetenv vasprintf vsnprintf |
25 | 25 | ||
26 | AUTOMAKE_OPTIONS = 1.9.6 gnits subdir-objects | 26 | AUTOMAKE_OPTIONS = 1.9.6 gnits subdir-objects |
27 | 27 | ||
@@ -1536,6 +1536,15 @@ EXTRA_DIST += stdlib.in.h | |||
1536 | 1536 | ||
1537 | ## end gnulib module stdlib | 1537 | ## end gnulib module stdlib |
1538 | 1538 | ||
1539 | ## begin gnulib module strcase | ||
1540 | |||
1541 | |||
1542 | EXTRA_DIST += strcasecmp.c strncasecmp.c | ||
1543 | |||
1544 | EXTRA_libgnu_a_SOURCES += strcasecmp.c strncasecmp.c | ||
1545 | |||
1546 | ## end gnulib module strcase | ||
1547 | |||
1539 | ## begin gnulib module streq | 1548 | ## begin gnulib module streq |
1540 | 1549 | ||
1541 | 1550 | ||
@@ -1661,6 +1670,37 @@ EXTRA_DIST += string.in.h | |||
1661 | 1670 | ||
1662 | ## end gnulib module string | 1671 | ## end gnulib module string |
1663 | 1672 | ||
1673 | ## begin gnulib module strings | ||
1674 | |||
1675 | BUILT_SOURCES += strings.h | ||
1676 | |||
1677 | # We need the following in order to create <strings.h> when the system | ||
1678 | # doesn't have one that works with the given compiler. | ||
1679 | strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) | ||
1680 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
1681 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
1682 | sed -e 's|@''GUARD_PREFIX''@|GL|g' \ | ||
1683 | -e 's|@''HAVE_STRINGS_H''@|$(HAVE_STRINGS_H)|g' \ | ||
1684 | -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
1685 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
1686 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
1687 | -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \ | ||
1688 | -e 's|@''GNULIB_FFS''@|$(GNULIB_FFS)|g' \ | ||
1689 | -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \ | ||
1690 | -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \ | ||
1691 | -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \ | ||
1692 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ | ||
1693 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ | ||
1694 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ | ||
1695 | < $(srcdir)/strings.in.h; \ | ||
1696 | } > $@-t && \ | ||
1697 | mv $@-t $@ | ||
1698 | MOSTLYCLEANFILES += strings.h strings.h-t | ||
1699 | |||
1700 | EXTRA_DIST += strings.in.h | ||
1701 | |||
1702 | ## end gnulib module strings | ||
1703 | |||
1664 | ## begin gnulib module strndup | 1704 | ## begin gnulib module strndup |
1665 | 1705 | ||
1666 | 1706 | ||
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4 index 2ed3509..e61a536 100644 --- a/gl/m4/gnulib-cache.m4 +++ b/gl/m4/gnulib-cache.m4 | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | # Specification in the form of a command-line invocation: | 29 | # Specification in the form of a command-line invocation: |
30 | # gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname environ floorf fsusage getaddrinfo gethostname getloadavg getopt-gnu gettext mountlist regex setenv strsep timegm unsetenv vasprintf vsnprintf | 30 | # gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname environ floorf fsusage getaddrinfo gethostname getloadavg getopt-gnu gettext mountlist regex setenv strcase strsep timegm unsetenv vasprintf vsnprintf |
31 | 31 | ||
32 | # Specification in the form of a few gnulib-tool.m4 macro invocations: | 32 | # Specification in the form of a few gnulib-tool.m4 macro invocations: |
33 | gl_LOCAL_DIR([]) | 33 | gl_LOCAL_DIR([]) |
@@ -46,6 +46,7 @@ gl_MODULES([ | |||
46 | mountlist | 46 | mountlist |
47 | regex | 47 | regex |
48 | setenv | 48 | setenv |
49 | strcase | ||
49 | strsep | 50 | strsep |
50 | timegm | 51 | timegm |
51 | unsetenv | 52 | unsetenv |
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index f23f769..b3cb4c1 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 | |||
@@ -119,10 +119,12 @@ AC_DEFUN([gl_EARLY], | |||
119 | # Code from module stdint: | 119 | # Code from module stdint: |
120 | # Code from module stdio: | 120 | # Code from module stdio: |
121 | # Code from module stdlib: | 121 | # Code from module stdlib: |
122 | # Code from module strcase: | ||
122 | # Code from module streq: | 123 | # Code from module streq: |
123 | # Code from module strerror: | 124 | # Code from module strerror: |
124 | # Code from module strerror-override: | 125 | # Code from module strerror-override: |
125 | # Code from module string: | 126 | # Code from module string: |
127 | # Code from module strings: | ||
126 | # Code from module strndup: | 128 | # Code from module strndup: |
127 | # Code from module strnlen: | 129 | # Code from module strnlen: |
128 | # Code from module strsep: | 130 | # Code from module strsep: |
@@ -377,6 +379,15 @@ AC_DEFUN([gl_INIT], | |||
377 | gl_STDINT_H | 379 | gl_STDINT_H |
378 | gl_STDIO_H | 380 | gl_STDIO_H |
379 | gl_STDLIB_H | 381 | gl_STDLIB_H |
382 | gl_STRCASE | ||
383 | if test $HAVE_STRCASECMP = 0; then | ||
384 | AC_LIBOBJ([strcasecmp]) | ||
385 | gl_PREREQ_STRCASECMP | ||
386 | fi | ||
387 | if test $HAVE_STRNCASECMP = 0; then | ||
388 | AC_LIBOBJ([strncasecmp]) | ||
389 | gl_PREREQ_STRNCASECMP | ||
390 | fi | ||
380 | gl_FUNC_STRERROR | 391 | gl_FUNC_STRERROR |
381 | if test $REPLACE_STRERROR = 1; then | 392 | if test $REPLACE_STRERROR = 1; then |
382 | AC_LIBOBJ([strerror]) | 393 | AC_LIBOBJ([strerror]) |
@@ -390,6 +401,7 @@ AC_DEFUN([gl_INIT], | |||
390 | gl_PREREQ_SYS_H_WINSOCK2 | 401 | gl_PREREQ_SYS_H_WINSOCK2 |
391 | fi | 402 | fi |
392 | gl_HEADER_STRING_H | 403 | gl_HEADER_STRING_H |
404 | gl_HEADER_STRINGS_H | ||
393 | gl_FUNC_STRNDUP | 405 | gl_FUNC_STRNDUP |
394 | if test $HAVE_STRNDUP = 0 || test $REPLACE_STRNDUP = 1; then | 406 | if test $HAVE_STRNDUP = 0 || test $REPLACE_STRNDUP = 1; then |
395 | AC_LIBOBJ([strndup]) | 407 | AC_LIBOBJ([strndup]) |
@@ -706,12 +718,15 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
706 | lib/stdio.in.h | 718 | lib/stdio.in.h |
707 | lib/stdlib.in.h | 719 | lib/stdlib.in.h |
708 | lib/str-two-way.h | 720 | lib/str-two-way.h |
721 | lib/strcasecmp.c | ||
709 | lib/streq.h | 722 | lib/streq.h |
710 | lib/strerror-override.c | 723 | lib/strerror-override.c |
711 | lib/strerror-override.h | 724 | lib/strerror-override.h |
712 | lib/strerror.c | 725 | lib/strerror.c |
713 | lib/string.in.h | 726 | lib/string.in.h |
727 | lib/strings.in.h | ||
714 | lib/stripslash.c | 728 | lib/stripslash.c |
729 | lib/strncasecmp.c | ||
715 | lib/strndup.c | 730 | lib/strndup.c |
716 | lib/strnlen.c | 731 | lib/strnlen.c |
717 | lib/strsep.c | 732 | lib/strsep.c |
@@ -845,8 +860,10 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
845 | m4/stdint_h.m4 | 860 | m4/stdint_h.m4 |
846 | m4/stdio_h.m4 | 861 | m4/stdio_h.m4 |
847 | m4/stdlib_h.m4 | 862 | m4/stdlib_h.m4 |
863 | m4/strcase.m4 | ||
848 | m4/strerror.m4 | 864 | m4/strerror.m4 |
849 | m4/string_h.m4 | 865 | m4/string_h.m4 |
866 | m4/strings_h.m4 | ||
850 | m4/strndup.m4 | 867 | m4/strndup.m4 |
851 | m4/strnlen.m4 | 868 | m4/strnlen.m4 |
852 | m4/strsep.m4 | 869 | m4/strsep.m4 |
diff --git a/gl/m4/strcase.m4 b/gl/m4/strcase.m4 new file mode 100644 index 0000000..22bf57c --- /dev/null +++ b/gl/m4/strcase.m4 | |||
@@ -0,0 +1,45 @@ | |||
1 | # strcase.m4 serial 11 | ||
2 | dnl Copyright (C) 2002, 2005-2013 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_STRCASE], | ||
8 | [ | ||
9 | gl_FUNC_STRCASECMP | ||
10 | gl_FUNC_STRNCASECMP | ||
11 | ]) | ||
12 | |||
13 | AC_DEFUN([gl_FUNC_STRCASECMP], | ||
14 | [ | ||
15 | AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) | ||
16 | AC_CHECK_FUNCS([strcasecmp]) | ||
17 | if test $ac_cv_func_strcasecmp = no; then | ||
18 | HAVE_STRCASECMP=0 | ||
19 | fi | ||
20 | ]) | ||
21 | |||
22 | AC_DEFUN([gl_FUNC_STRNCASECMP], | ||
23 | [ | ||
24 | AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) | ||
25 | AC_CHECK_FUNCS([strncasecmp]) | ||
26 | if test $ac_cv_func_strncasecmp = yes; then | ||
27 | HAVE_STRNCASECMP=1 | ||
28 | else | ||
29 | HAVE_STRNCASECMP=0 | ||
30 | fi | ||
31 | AC_CHECK_DECLS([strncasecmp]) | ||
32 | if test $ac_cv_have_decl_strncasecmp = no; then | ||
33 | HAVE_DECL_STRNCASECMP=0 | ||
34 | fi | ||
35 | ]) | ||
36 | |||
37 | # Prerequisites of lib/strcasecmp.c. | ||
38 | AC_DEFUN([gl_PREREQ_STRCASECMP], [ | ||
39 | : | ||
40 | ]) | ||
41 | |||
42 | # Prerequisites of lib/strncasecmp.c. | ||
43 | AC_DEFUN([gl_PREREQ_STRNCASECMP], [ | ||
44 | : | ||
45 | ]) | ||
diff --git a/gl/m4/strings_h.m4 b/gl/m4/strings_h.m4 new file mode 100644 index 0000000..76ef242 --- /dev/null +++ b/gl/m4/strings_h.m4 | |||
@@ -0,0 +1,52 @@ | |||
1 | # Configure a replacement for <strings.h>. | ||
2 | # serial 6 | ||
3 | |||
4 | # Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. | ||
5 | # This file is free software; the Free Software Foundation | ||
6 | # gives unlimited permission to copy and/or distribute it, | ||
7 | # with or without modifications, as long as this notice is preserved. | ||
8 | |||
9 | AC_DEFUN([gl_HEADER_STRINGS_H], | ||
10 | [ | ||
11 | dnl Use AC_REQUIRE here, so that the default behavior below is expanded | ||
12 | dnl once only, before all statements that occur in other macros. | ||
13 | AC_REQUIRE([gl_HEADER_STRINGS_H_BODY]) | ||
14 | ]) | ||
15 | |||
16 | AC_DEFUN([gl_HEADER_STRINGS_H_BODY], | ||
17 | [ | ||
18 | AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) | ||
19 | |||
20 | gl_CHECK_NEXT_HEADERS([strings.h]) | ||
21 | if test $ac_cv_header_strings_h = yes; then | ||
22 | HAVE_STRINGS_H=1 | ||
23 | else | ||
24 | HAVE_STRINGS_H=0 | ||
25 | fi | ||
26 | AC_SUBST([HAVE_STRINGS_H]) | ||
27 | |||
28 | dnl Check for declarations of anything we want to poison if the | ||
29 | dnl corresponding gnulib module is not in use. | ||
30 | gl_WARN_ON_USE_PREPARE([[ | ||
31 | /* Minix 3.1.8 has a bug: <sys/types.h> must be included before | ||
32 | <strings.h>. */ | ||
33 | #include <sys/types.h> | ||
34 | #include <strings.h> | ||
35 | ]], [ffs strcasecmp strncasecmp]) | ||
36 | ]) | ||
37 | |||
38 | AC_DEFUN([gl_STRINGS_MODULE_INDICATOR], | ||
39 | [ | ||
40 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | ||
41 | AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) | ||
42 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) | ||
43 | ]) | ||
44 | |||
45 | AC_DEFUN([gl_HEADER_STRINGS_H_DEFAULTS], | ||
46 | [ | ||
47 | GNULIB_FFS=0; AC_SUBST([GNULIB_FFS]) | ||
48 | dnl Assume proper GNU behavior unless another module says otherwise. | ||
49 | HAVE_FFS=1; AC_SUBST([HAVE_FFS]) | ||
50 | HAVE_STRCASECMP=1; AC_SUBST([HAVE_STRCASECMP]) | ||
51 | HAVE_DECL_STRNCASECMP=1; AC_SUBST([HAVE_DECL_STRNCASECMP]) | ||
52 | ]) | ||
diff --git a/gl/strcasecmp.c b/gl/strcasecmp.c new file mode 100644 index 0000000..0f0a742 --- /dev/null +++ b/gl/strcasecmp.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* Case-insensitive string comparison function. | ||
2 | Copyright (C) 1998-1999, 2005-2007, 2009-2013 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include <config.h> | ||
18 | |||
19 | /* Specification. */ | ||
20 | #include <string.h> | ||
21 | |||
22 | #include <ctype.h> | ||
23 | #include <limits.h> | ||
24 | |||
25 | #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) | ||
26 | |||
27 | /* Compare strings S1 and S2, ignoring case, returning less than, equal to or | ||
28 | greater than zero if S1 is lexicographically less than, equal to or greater | ||
29 | than S2. | ||
30 | Note: This function does not work with multibyte strings! */ | ||
31 | |||
32 | int | ||
33 | strcasecmp (const char *s1, const char *s2) | ||
34 | { | ||
35 | const unsigned char *p1 = (const unsigned char *) s1; | ||
36 | const unsigned char *p2 = (const unsigned char *) s2; | ||
37 | unsigned char c1, c2; | ||
38 | |||
39 | if (p1 == p2) | ||
40 | return 0; | ||
41 | |||
42 | do | ||
43 | { | ||
44 | c1 = TOLOWER (*p1); | ||
45 | c2 = TOLOWER (*p2); | ||
46 | |||
47 | if (c1 == '\0') | ||
48 | break; | ||
49 | |||
50 | ++p1; | ||
51 | ++p2; | ||
52 | } | ||
53 | while (c1 == c2); | ||
54 | |||
55 | if (UCHAR_MAX <= INT_MAX) | ||
56 | return c1 - c2; | ||
57 | else | ||
58 | /* On machines where 'char' and 'int' are types of the same size, the | ||
59 | difference of two 'unsigned char' values - including the sign bit - | ||
60 | doesn't fit in an 'int'. */ | ||
61 | return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); | ||
62 | } | ||
diff --git a/gl/strings.in.h b/gl/strings.in.h new file mode 100644 index 0000000..4469f86 --- /dev/null +++ b/gl/strings.in.h | |||
@@ -0,0 +1,122 @@ | |||
1 | /* A substitute <strings.h>. | ||
2 | |||
3 | Copyright (C) 2007-2013 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 3, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifndef _@GUARD_PREFIX@_STRINGS_H | ||
19 | |||
20 | #if __GNUC__ >= 3 | ||
21 | @PRAGMA_SYSTEM_HEADER@ | ||
22 | #endif | ||
23 | @PRAGMA_COLUMNS@ | ||
24 | |||
25 | /* Minix 3.1.8 has a bug: <sys/types.h> must be included before <strings.h>. | ||
26 | But avoid namespace pollution on glibc systems. */ | ||
27 | #if defined __minix && !defined __GLIBC__ | ||
28 | # include <sys/types.h> | ||
29 | #endif | ||
30 | |||
31 | /* The include_next requires a split double-inclusion guard. */ | ||
32 | #if @HAVE_STRINGS_H@ | ||
33 | # @INCLUDE_NEXT@ @NEXT_STRINGS_H@ | ||
34 | #endif | ||
35 | |||
36 | #ifndef _@GUARD_PREFIX@_STRINGS_H | ||
37 | #define _@GUARD_PREFIX@_STRINGS_H | ||
38 | |||
39 | #if ! @HAVE_DECL_STRNCASECMP@ | ||
40 | /* Get size_t. */ | ||
41 | # include <stddef.h> | ||
42 | #endif | ||
43 | |||
44 | |||
45 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | ||
46 | |||
47 | /* The definition of _GL_ARG_NONNULL is copied here. */ | ||
48 | |||
49 | /* The definition of _GL_WARN_ON_USE is copied here. */ | ||
50 | |||
51 | #ifdef __cplusplus | ||
52 | extern "C" { | ||
53 | #endif | ||
54 | |||
55 | |||
56 | /* Find the index of the least-significant set bit. */ | ||
57 | #if @GNULIB_FFS@ | ||
58 | # if !@HAVE_FFS@ | ||
59 | _GL_FUNCDECL_SYS (ffs, int, (int i)); | ||
60 | # endif | ||
61 | _GL_CXXALIAS_SYS (ffs, int, (int i)); | ||
62 | _GL_CXXALIASWARN (ffs); | ||
63 | #elif defined GNULIB_POSIXCHECK | ||
64 | # undef ffs | ||
65 | # if HAVE_RAW_DECL_FFS | ||
66 | _GL_WARN_ON_USE (ffs, "ffs is not portable - use the ffs module"); | ||
67 | # endif | ||
68 | #endif | ||
69 | |||
70 | /* Compare strings S1 and S2, ignoring case, returning less than, equal to or | ||
71 | greater than zero if S1 is lexicographically less than, equal to or greater | ||
72 | than S2. | ||
73 | Note: This function does not work in multibyte locales. */ | ||
74 | #if ! @HAVE_STRCASECMP@ | ||
75 | extern int strcasecmp (char const *s1, char const *s2) | ||
76 | _GL_ARG_NONNULL ((1, 2)); | ||
77 | #endif | ||
78 | #if defined GNULIB_POSIXCHECK | ||
79 | /* strcasecmp() does not work with multibyte strings: | ||
80 | POSIX says that it operates on "strings", and "string" in POSIX is defined | ||
81 | as a sequence of bytes, not of characters. */ | ||
82 | # undef strcasecmp | ||
83 | # if HAVE_RAW_DECL_STRCASECMP | ||
84 | _GL_WARN_ON_USE (strcasecmp, "strcasecmp cannot work correctly on character " | ||
85 | "strings in multibyte locales - " | ||
86 | "use mbscasecmp if you care about " | ||
87 | "internationalization, or use c_strcasecmp , " | ||
88 | "gnulib module c-strcase) if you want a locale " | ||
89 | "independent function"); | ||
90 | # endif | ||
91 | #endif | ||
92 | |||
93 | /* Compare no more than N bytes of strings S1 and S2, ignoring case, | ||
94 | returning less than, equal to or greater than zero if S1 is | ||
95 | lexicographically less than, equal to or greater than S2. | ||
96 | Note: This function cannot work correctly in multibyte locales. */ | ||
97 | #if ! @HAVE_DECL_STRNCASECMP@ | ||
98 | extern int strncasecmp (char const *s1, char const *s2, size_t n) | ||
99 | _GL_ARG_NONNULL ((1, 2)); | ||
100 | #endif | ||
101 | #if defined GNULIB_POSIXCHECK | ||
102 | /* strncasecmp() does not work with multibyte strings: | ||
103 | POSIX says that it operates on "strings", and "string" in POSIX is defined | ||
104 | as a sequence of bytes, not of characters. */ | ||
105 | # undef strncasecmp | ||
106 | # if HAVE_RAW_DECL_STRNCASECMP | ||
107 | _GL_WARN_ON_USE (strncasecmp, "strncasecmp cannot work correctly on character " | ||
108 | "strings in multibyte locales - " | ||
109 | "use mbsncasecmp or mbspcasecmp if you care about " | ||
110 | "internationalization, or use c_strncasecmp , " | ||
111 | "gnulib module c-strcase) if you want a locale " | ||
112 | "independent function"); | ||
113 | # endif | ||
114 | #endif | ||
115 | |||
116 | |||
117 | #ifdef __cplusplus | ||
118 | } | ||
119 | #endif | ||
120 | |||
121 | #endif /* _@GUARD_PREFIX@_STRING_H */ | ||
122 | #endif /* _@GUARD_PREFIX@_STRING_H */ | ||
diff --git a/gl/strncasecmp.c b/gl/strncasecmp.c new file mode 100644 index 0000000..35840bc --- /dev/null +++ b/gl/strncasecmp.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* strncasecmp.c -- case insensitive string comparator | ||
2 | Copyright (C) 1998-1999, 2005-2007, 2009-2013 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include <config.h> | ||
18 | |||
19 | /* Specification. */ | ||
20 | #include <string.h> | ||
21 | |||
22 | #include <ctype.h> | ||
23 | #include <limits.h> | ||
24 | |||
25 | #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) | ||
26 | |||
27 | /* Compare no more than N bytes of strings S1 and S2, ignoring case, | ||
28 | returning less than, equal to or greater than zero if S1 is | ||
29 | lexicographically less than, equal to or greater than S2. | ||
30 | Note: This function cannot work correctly in multibyte locales. */ | ||
31 | |||
32 | int | ||
33 | strncasecmp (const char *s1, const char *s2, size_t n) | ||
34 | { | ||
35 | register const unsigned char *p1 = (const unsigned char *) s1; | ||
36 | register const unsigned char *p2 = (const unsigned char *) s2; | ||
37 | unsigned char c1, c2; | ||
38 | |||
39 | if (p1 == p2 || n == 0) | ||
40 | return 0; | ||
41 | |||
42 | do | ||
43 | { | ||
44 | c1 = TOLOWER (*p1); | ||
45 | c2 = TOLOWER (*p2); | ||
46 | |||
47 | if (--n == 0 || c1 == '\0') | ||
48 | break; | ||
49 | |||
50 | ++p1; | ||
51 | ++p2; | ||
52 | } | ||
53 | while (c1 == c2); | ||
54 | |||
55 | if (UCHAR_MAX <= INT_MAX) | ||
56 | return c1 - c2; | ||
57 | else | ||
58 | /* On machines where 'char' and 'int' are types of the same size, the | ||
59 | difference of two 'unsigned char' values - including the sign bit - | ||
60 | doesn't fit in an 'int'. */ | ||
61 | return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); | ||
62 | } | ||