From fb9d1ff00f76836dd66725de869656c5fa53b071 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 May 2000 14:09:31 +0000 Subject: files moved to main branch from the newlib branch --- lib/strequal.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lib/strequal.c (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c new file mode 100644 index 000000000..e40e06e97 --- /dev/null +++ b/lib/strequal.c @@ -0,0 +1,83 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Curl. + * + * The Initial Developer of the Original Code is Daniel Stenberg. + * + * Portions created by the Initial Developer are Copyright (C) 2000. + * All Rights Reserved. + * + * ------------------------------------------------------------ + * Main author: + * - Daniel Stenberg + * + * http://curl.haxx.nu + * + * $Source$ + * $Revision$ + * $Date$ + * $Author$ + * $State$ + * $Locker$ + * + * ------------------------------------------------------------ + ****************************************************************************/ + +#include "setup.h" + +int strequal(const char *first, const char *second) +{ +#if defined(HAVE_STRCASECMP) + return !strcasecmp(first, second); +#elif defined(HAVE_STRCMPI) + return !strcmpi(first, second); +#elif defined(HAVE_STRICMP) + return !strcmpi(first, second); +#else + while (*first && *second) { + if (toupper(*first) != toupper(*second)) { + break; + } + first++; + second++; + } + return toupper(*first) == toupper(*second); +#endif +} + +int strnequal(const char *first, const char *second, size_t max) +{ +#if defined(HAVE_STRCASECMP) + return !strncasecmp(first, second, max); +#elif defined(HAVE_STRCMPI) + return !strncmpi(first, second, max); +#elif defined(HAVE_STRICMP) + return !strnicmp(first, second, max); +#else + while (*first && *second && max) { + if (toupper(*first) != toupper(*second)) { + break; + } + max--; + first++; + second++; + } + return toupper(*first) == toupper(*second); +#endif +} + -- cgit v1.2.1 From ec520ceefd73391926dac1661c440c9a3138adc1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 14 Jun 2000 14:26:20 +0000 Subject: =?UTF-8?q?bad=20HAVE=5FSTRICMP=20usage=20found=20by=20Bj=F6rn=20S?= =?UTF-8?q?tenberg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index e40e06e97..87dbc5d86 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -47,7 +47,7 @@ int strequal(const char *first, const char *second) #elif defined(HAVE_STRCMPI) return !strcmpi(first, second); #elif defined(HAVE_STRICMP) - return !strcmpi(first, second); + return !stricmp(first, second); #else while (*first && *second) { if (toupper(*first) != toupper(*second)) { -- cgit v1.2.1 From ce7e3586da4f1cb8c3771754737d4db8d047a736 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 14 Jun 2000 17:23:51 +0000 Subject: Added #include --- lib/strequal.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 87dbc5d86..cf3db959e 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -38,6 +38,8 @@ * ------------------------------------------------------------ ****************************************************************************/ +#include + #include "setup.h" int strequal(const char *first, const char *second) -- cgit v1.2.1 From 1ef3600a0731fef8f59563a1e49981f1b64b9746 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Jun 2000 15:31:26 +0000 Subject: haxx.nu => haxx.se --- lib/strequal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index cf3db959e..d69e536bd 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -24,9 +24,9 @@ * * ------------------------------------------------------------ * Main author: - * - Daniel Stenberg + * - Daniel Stenberg * - * http://curl.haxx.nu + * http://curl.haxx.se * * $Source$ * $Revision$ -- cgit v1.2.1 From b6e18f2f665f16910c04cb52bdc7b90270ab7c9b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Aug 2000 14:26:33 +0000 Subject: #include "setup.h" moved first of all includes --- lib/strequal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index d69e536bd..4aec362b3 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -38,10 +38,10 @@ * ------------------------------------------------------------ ****************************************************************************/ -#include - #include "setup.h" +#include + int strequal(const char *first, const char *second) { #if defined(HAVE_STRCASECMP) -- cgit v1.2.1 From 24dee483e9e925c2ab79dd582f70c9a55ab9ba4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 3 Jan 2001 09:29:33 +0000 Subject: dual-license fix --- lib/strequal.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 4aec362b3..0bb893894 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,38 +5,21 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ + * Copyright (C) 2000, Daniel Stenberg, , et al. * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. + * In order to be useful for every potential user, curl and libcurl are + * dual-licensed under the MPL and the MIT/X-derivate licenses. * - * The Original Code is Curl. + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the MPL or the MIT/X-derivate + * licenses. You may pick one of these licenses. * - * The Initial Developer of the Original Code is Daniel Stenberg. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. * - * Portions created by the Initial Developer are Copyright (C) 2000. - * All Rights Reserved. - * - * ------------------------------------------------------------ - * Main author: - * - Daniel Stenberg - * - * http://curl.haxx.se - * - * $Source$ - * $Revision$ - * $Date$ - * $Author$ - * $State$ - * $Locker$ - * - * ------------------------------------------------------------ - ****************************************************************************/ + * $Id$ + *****************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 4031104404c6ceed5e57134125dcdb6cac51c564 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Jan 2001 10:11:41 +0000 Subject: Internal symbols that aren't static are now prefixed with 'Curl_' --- lib/strequal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 0bb893894..82e991cda 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -25,7 +25,7 @@ #include -int strequal(const char *first, const char *second) +int Curl_strequal(const char *first, const char *second) { #if defined(HAVE_STRCASECMP) return !strcasecmp(first, second); @@ -45,7 +45,7 @@ int strequal(const char *first, const char *second) #endif } -int strnequal(const char *first, const char *second, size_t max) +int Curl_strnequal(const char *first, const char *second, size_t max) { #if defined(HAVE_STRCASECMP) return !strncasecmp(first, second, max); -- cgit v1.2.1 From db70cd28b34e73fc38617176cd8b1306a129abe5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 5 Feb 2001 23:35:44 +0000 Subject: adjusted the IPv6 stuff to compile and build on Linux as well --- lib/strequal.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 82e991cda..97d1f9199 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -66,3 +66,29 @@ int Curl_strnequal(const char *first, const char *second, size_t max) #endif } +#ifndef HAVE_STRLCAT +/* + * The strlcat() function appends the NUL-terminated string src to the end + * of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-termi- + * nating the result. + * + * The strlcpy() and strlcat() functions return the total length of the + * string they tried to create. For strlcpy() that means the length of src. + * For strlcat() that means the initial length of dst plus the length of + * src. While this may seem somewhat confusing it was done to make trunca- + * tion detection simple. + */ +size_t strlcat(char *dst, const char *src, size_t size) +{ + size_t len = strlen(dst); + size_t orglen = len; + int index=0; + + while(src[index] && (len < (size-1)) ) { + dst[len++] = src[index++]; + } + dst[len]=0; + + return orglen + strlen(src); +} +#endif -- cgit v1.2.1 From 833ce37cb95646bfc02dbf1a87ac3fd5d3937de5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 6 Feb 2001 09:08:24 +0000 Subject: new openbsd inspired implementation of strlcat() --- lib/strequal.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 97d1f9199..42aea7cd0 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -77,18 +77,33 @@ int Curl_strnequal(const char *first, const char *second, size_t max) * For strlcat() that means the initial length of dst plus the length of * src. While this may seem somewhat confusing it was done to make trunca- * tion detection simple. + * + * */ size_t strlcat(char *dst, const char *src, size_t size) { - size_t len = strlen(dst); - size_t orglen = len; - int index=0; - - while(src[index] && (len < (size-1)) ) { - dst[len++] = src[index++]; + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; } - dst[len]=0; + *d = '\0'; - return orglen + strlen(src); + return(dlen + (s - src)); /* count does not include NUL */ } #endif -- cgit v1.2.1 From 09f6fc22eda36fa0d6ec9205cfa27ba7b204996b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 6 Feb 2001 09:12:39 +0000 Subject: silly me, corrected the strlcat() to compile --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 42aea7cd0..6e198f1b5 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -80,7 +80,7 @@ int Curl_strnequal(const char *first, const char *second, size_t max) * * */ -size_t strlcat(char *dst, const char *src, size_t size) +size_t strlcat(char *dst, const char *src, size_t siz) { char *d = dst; const char *s = src; -- cgit v1.2.1 From 3738e4bdc0fa250e47a92f4d0bf611177104cc78 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 14 Mar 2001 08:47:56 +0000 Subject: The Curl_* prefixes are now changed for curl_* ones, as these two functions are used externally and thus are public symbols. --- lib/strequal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 6e198f1b5..38ba23986 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -25,7 +25,7 @@ #include -int Curl_strequal(const char *first, const char *second) +int curl_strequal(const char *first, const char *second) { #if defined(HAVE_STRCASECMP) return !strcasecmp(first, second); @@ -45,7 +45,7 @@ int Curl_strequal(const char *first, const char *second) #endif } -int Curl_strnequal(const char *first, const char *second, size_t max) +int curl_strnequal(const char *first, const char *second, size_t max) { #if defined(HAVE_STRCASECMP) return !strncasecmp(first, second, max); -- cgit v1.2.1 From 6c50d2ee7d7e4c87a04422613a76de39702a0e89 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 18 May 2001 10:02:44 +0000 Subject: strlcat() is now Curl_strlcat() instead to prevent collisions when used with other libs --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 38ba23986..e14bc245d 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -80,7 +80,7 @@ int curl_strnequal(const char *first, const char *second, size_t max) * * */ -size_t strlcat(char *dst, const char *src, size_t siz) +size_t Curl_strlcat(char *dst, const char *src, size_t siz) { char *d = dst; const char *s = src; -- cgit v1.2.1 From 4034f31823ddac3f839f54921c9898c36858c76f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 24 Aug 2001 07:24:34 +0000 Subject: cleanups --- lib/strequal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index e14bc245d..e05832efd 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -28,11 +28,11 @@ int curl_strequal(const char *first, const char *second) { #if defined(HAVE_STRCASECMP) - return !strcasecmp(first, second); + return !(strcasecmp)(first, second); #elif defined(HAVE_STRCMPI) - return !strcmpi(first, second); + return !(strcmpi)(first, second); #elif defined(HAVE_STRICMP) - return !stricmp(first, second); + return !(stricmp)(first, second); #else while (*first && *second) { if (toupper(*first) != toupper(*second)) { -- cgit v1.2.1 From 6147879837a53d22c9be04e7a4fc315a297ba2b3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Fri, 7 Sep 2001 04:01:32 +0000 Subject: Added formatting sections for emacs and vim --- lib/strequal.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index e05832efd..54ecb74bb 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -107,3 +107,11 @@ size_t Curl_strlcat(char *dst, const char *src, size_t siz) return(dlen + (s - src)); /* count does not include NUL */ } #endif + +/* + * local variables: + * eval: (load-file "../curl-mode.el") + * end: + * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker + * vim<600: et sw=2 ts=2 sts=2 tw=78 + */ -- cgit v1.2.1 From 8e91d5de8e4e17ce3d4936cc91171d09726e7bb3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Thu, 11 Oct 2001 09:32:19 +0000 Subject: looks nicer and is better compatible with older vim versions --- lib/strequal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 54ecb74bb..988f774bd 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -112,6 +112,6 @@ size_t Curl_strlcat(char *dst, const char *src, size_t siz) * local variables: * eval: (load-file "../curl-mode.el") * end: - * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker - * vim<600: et sw=2 ts=2 sts=2 tw=78 + * vim600: fdm=marker + * vim: et sw=2 ts=2 sts=2 tw=78 */ -- cgit v1.2.1 From dccc77a32595f39c01198ccdd9e2c7794588c556 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 27 Nov 2001 07:27:32 +0000 Subject: Eric Lavigne updates --- lib/strequal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 988f774bd..6859e26bd 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -24,6 +24,7 @@ #include "setup.h" #include +#include int curl_strequal(const char *first, const char *second) { -- cgit v1.2.1 From 7493db2338a669261ed82cce834446b4c3b08bd5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 3 Dec 2001 12:57:45 +0000 Subject: Eric nailed a but in strnequal() for macintosh --- lib/strequal.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 6859e26bd..df5d4f14b 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -63,6 +63,9 @@ int curl_strnequal(const char *first, const char *second, size_t max) first++; second++; } + if(0 == max) + return 1; /* they are equal this far */ + return toupper(*first) == toupper(*second); #endif } -- cgit v1.2.1 From 974f314f5785156af6983675aeb28313cc8ba2ea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 07:54:55 +0000 Subject: copyright string (year) update --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index df5d4f14b..f645e0a83 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2000, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. -- cgit v1.2.1 From ba4e69bebc8f7f32f3bc7faa1e13e7580754075b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2002 11:52:59 +0000 Subject: updated source code boilerplate/header --- lib/strequal.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index f645e0a83..a2cc65c97 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -7,19 +7,19 @@ * * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * - * In order to be useful for every potential user, curl and libcurl are - * dual-licensed under the MPL and the MIT/X-derivate licenses. - * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the MPL or the MIT/X-derivate - * licenses. You may pick one of these licenses. + * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * $Id$ - *****************************************************************************/ + ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From f26a338a54e04d0a6907f5d2479d8b0fa9daf297 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 21:08:12 +0000 Subject: copyright year update in the source header --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index a2cc65c97..382feedae 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From a7c72b7abf1213c471f3fd11e6b8e3a37d526f60 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Jan 2003 10:14:20 +0000 Subject: removed the local variables for emacs and vim, use the new sample.emacs way for emacs, and vim users should provide a similar non-polluting style --- lib/strequal.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 382feedae..04e0c9788 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -111,11 +111,3 @@ size_t Curl_strlcat(char *dst, const char *src, size_t siz) return(dlen + (s - src)); /* count does not include NUL */ } #endif - -/* - * local variables: - * eval: (load-file "../curl-mode.el") - * end: - * vim600: fdm=marker - * vim: et sw=2 ts=2 sts=2 tw=78 - */ -- cgit v1.2.1 From 32899f8309211e2141937d24b754480a9df10951 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 24 Aug 2003 14:29:06 +0000 Subject: added the strcasecmp() proto here (moved from setup.h), as this is the only file within libcurl to use that function --- lib/strequal.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 04e0c9788..780a99801 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -26,6 +26,12 @@ #include #include +#ifdef HAVE_STRCASECMP +/* this is for "-ansi -Wall -pedantic" to stop complaining! */ +extern int (strcasecmp)(const char *s1, const char *s2); +extern int (strncasecmp)(const char *s1, const char *s2, size_t n); +#endif + int curl_strequal(const char *first, const char *second) { #if defined(HAVE_STRCASECMP) -- cgit v1.2.1 From 053f6c85efd0bf698f73343989474d672d0563a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Jan 2004 09:19:33 +0000 Subject: updated year in the copyright string --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 780a99801..4349b500a 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 4d17d6876e4b2f08380812c4ec113073b0a14639 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 29 Jan 2004 13:56:45 +0000 Subject: Dan Fandrich's cleanup patch to make pedantic compiler options cause less warnings. Minor edits by me. --- lib/strequal.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 4349b500a..37a68876e 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -26,6 +26,8 @@ #include #include +#include "strequal.h" + #ifdef HAVE_STRCASECMP /* this is for "-ansi -Wall -pedantic" to stop complaining! */ extern int (strcasecmp)(const char *s1, const char *s2); -- cgit v1.2.1 From 61bded1d8265211f434143aa7984783f2ab2a045 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 13 Jun 2004 08:32:57 +0000 Subject: added Curl_strcasestr() for case insensitive strstr() searching --- lib/strequal.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 37a68876e..ec4910281 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -1,8 +1,8 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -10,7 +10,7 @@ * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. - * + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. @@ -78,6 +78,25 @@ int curl_strnequal(const char *first, const char *second, size_t max) #endif } +/* + * Curl_strcasestr() finds the first occurrence of the substring needle in the + * string haystack. The terminating `\0' characters are not compared. The + * matching is done CASE INSENSITIVE, which thus is the difference between + * this and strstr(). + */ +char *Curl_strcasestr(const char *haystack, const char *needle) +{ + size_t nlen = strlen(needle); + size_t hlen = strlen(haystack); + + while(hlen-- >= nlen) { + if(curl_strnequal(haystack, needle, nlen)) + return (char *)haystack; + haystack++; + } + return NULL; +} + #ifndef HAVE_STRLCAT /* * The strlcat() function appends the NUL-terminated string src to the end @@ -90,7 +109,7 @@ int curl_strnequal(const char *first, const char *second, size_t max) * src. While this may seem somewhat confusing it was done to make trunca- * tion detection simple. * - * + * */ size_t Curl_strlcat(char *dst, const char *src, size_t siz) { -- cgit v1.2.1 From 39af394a1c3ae1d8ac71ad263a7c524988702c2e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 6 Oct 2004 07:50:18 +0000 Subject: removed tabs and trailing whitespace from source --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index ec4910281..f993e382a 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -135,6 +135,6 @@ size_t Curl_strlcat(char *dst, const char *src, size_t siz) } *d = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + return(dlen + (s - src)); /* count does not include NUL */ } #endif -- cgit v1.2.1 From 4272af801fab5f58abcaaa61ae7ce75a90929fb5 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 9 Aug 2006 16:36:17 +0000 Subject: Only define the string prototypes in ANSI mode to reduce interference on systems that prototype them slightly differently. --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index f993e382a..34f95fd90 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -28,7 +28,7 @@ #include "strequal.h" -#ifdef HAVE_STRCASECMP +#if defined(HAVE_STRCASECMP) && defined(__STRICT_ANSI__) /* this is for "-ansi -Wall -pedantic" to stop complaining! */ extern int (strcasecmp)(const char *s1, const char *s2); extern int (strncasecmp)(const char *s1, const char *s2, size_t n); -- cgit v1.2.1 From 772a985dc3318214443ddd2ad6541d520f089368 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 27 Oct 2006 03:47:57 +0000 Subject: Update copyright year, since the file has been modified --- lib/strequal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 34f95fd90..1bff429a7 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 5e7164f87a7b65a4790b3b3e080664dabc8d50a4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 1 Apr 2007 07:51:30 +0000 Subject: Matt Kraai provided a patch that makes curl build on QNX 6 fine again. Mostly by letting configure check for setmode and ifdef on HAVE_SETMODE. NOTE: non- configure platforms that havve setmode() needs their hard-coded config.h files fixed. I fixed the src/config-win32.h. --- lib/strequal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 1bff429a7..cb8767002 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -26,6 +26,10 @@ #include #include +#ifdef HAVE_STRINGS_H +#include +#endif + #include "strequal.h" #if defined(HAVE_STRCASECMP) && defined(__STRICT_ANSI__) -- cgit v1.2.1 From c4782007667a29b1a02f13108f9ec0017aa3cbc7 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 25 Sep 2007 06:43:58 +0000 Subject: Use a native strcasestr() if found. --- lib/strequal.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index cb8767002..adf84403d 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -90,6 +90,9 @@ int curl_strnequal(const char *first, const char *second, size_t max) */ char *Curl_strcasestr(const char *haystack, const char *needle) { +#if defined(HAVE_STRCASESTR) + return strcasestr(haystack, needle); +#else size_t nlen = strlen(needle); size_t hlen = strlen(haystack); @@ -99,6 +102,7 @@ char *Curl_strcasestr(const char *haystack, const char *needle) haystack++; } return NULL; +#endif } #ifndef HAVE_STRLCAT -- cgit v1.2.1 From 966130132f75e0c30b176281081721bcb19e234d Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 25 Sep 2007 17:33:56 +0000 Subject: Make glibc define the prototype for strcasestr --- lib/strequal.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index adf84403d..49dc4880b 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -21,6 +21,11 @@ * $Id$ ***************************************************************************/ +#ifndef _GNU_SOURCE +/* glibc needs this to define the prototype for strcasestr */ +#define _GNU_SOURCE 1 +#endif + #include "setup.h" #include -- cgit v1.2.1 From cbd1a77ec24e397d05f20c6de106625676343c9d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2007 09:21:35 +0000 Subject: if () => if() while () => while() and some other minor re-indentings --- lib/strequal.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 49dc4880b..639a7ffc2 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -52,8 +52,8 @@ int curl_strequal(const char *first, const char *second) #elif defined(HAVE_STRICMP) return !(stricmp)(first, second); #else - while (*first && *second) { - if (toupper(*first) != toupper(*second)) { + while(*first && *second) { + if(toupper(*first) != toupper(*second)) { break; } first++; @@ -72,8 +72,8 @@ int curl_strnequal(const char *first, const char *second, size_t max) #elif defined(HAVE_STRICMP) return !strnicmp(first, second, max); #else - while (*first && *second && max) { - if (toupper(*first) != toupper(*second)) { + while(*first && *second && max) { + if(toupper(*first) != toupper(*second)) { break; } max--; @@ -132,15 +132,15 @@ size_t Curl_strlcat(char *dst, const char *src, size_t siz) size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') + while(n-- != 0 && *d != '\0') d++; dlen = d - dst; n = siz - dlen; - if (n == 0) + if(n == 0) return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { + while(*s != '\0') { + if(n != 1) { *d++ = *s; n--; } -- cgit v1.2.1 From 4c621bc697b13472eeb90202f42b2a183b629e42 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 15 Sep 2008 00:32:08 +0000 Subject: improve detection of: strcasecmp() strcasestr() strcmpi() stricmp() strlcat() strncasecmp() strncmpi() strnicmp() --- lib/strequal.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 639a7ffc2..ac9075d58 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -21,11 +21,6 @@ * $Id$ ***************************************************************************/ -#ifndef _GNU_SOURCE -/* glibc needs this to define the prototype for strcasestr */ -#define _GNU_SOURCE 1 -#endif - #include "setup.h" #include @@ -37,12 +32,6 @@ #include "strequal.h" -#if defined(HAVE_STRCASECMP) && defined(__STRICT_ANSI__) -/* this is for "-ansi -Wall -pedantic" to stop complaining! */ -extern int (strcasecmp)(const char *s1, const char *s2); -extern int (strncasecmp)(const char *s1, const char *s2, size_t n); -#endif - int curl_strequal(const char *first, const char *second) { #if defined(HAVE_STRCASECMP) @@ -65,11 +54,11 @@ int curl_strequal(const char *first, const char *second) int curl_strnequal(const char *first, const char *second, size_t max) { -#if defined(HAVE_STRCASECMP) +#if defined(HAVE_STRNCASECMP) return !strncasecmp(first, second, max); -#elif defined(HAVE_STRCMPI) +#elif defined(HAVE_STRNCMPI) return !strncmpi(first, second, max); -#elif defined(HAVE_STRICMP) +#elif defined(HAVE_STRNICMP) return !strnicmp(first, second, max); #else while(*first && *second && max) { -- cgit v1.2.1 From 36e56f36ada9499698db01ca509b7fe5d8d33811 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 15 Oct 2008 09:56:34 +0000 Subject: remove Curl_strcasestr() since there is no code at all using this function! --- lib/strequal.c | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index ac9075d58..e8c667497 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -76,29 +76,6 @@ int curl_strnequal(const char *first, const char *second, size_t max) #endif } -/* - * Curl_strcasestr() finds the first occurrence of the substring needle in the - * string haystack. The terminating `\0' characters are not compared. The - * matching is done CASE INSENSITIVE, which thus is the difference between - * this and strstr(). - */ -char *Curl_strcasestr(const char *haystack, const char *needle) -{ -#if defined(HAVE_STRCASESTR) - return strcasestr(haystack, needle); -#else - size_t nlen = strlen(needle); - size_t hlen = strlen(haystack); - - while(hlen-- >= nlen) { - if(curl_strnequal(haystack, needle, nlen)) - return (char *)haystack; - haystack++; - } - return NULL; -#endif -} - #ifndef HAVE_STRLCAT /* * The strlcat() function appends the NUL-terminated string src to the end -- cgit v1.2.1 From a579d6706436615845f57692921e0891fb6e3719 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 15 Oct 2008 21:43:48 +0000 Subject: - Pascal Terjan filed bug #2154627 (http://curl.haxx.se/bug/view.cgi?id=2154627) which pointed out that libcurl uses strcasecmp() in multiple places where it causes failures when the Turkish locale is used. This is because 'i' and 'I' isn't the same letter so strcasecmp() on those letters are different in Turkish than in English (or just about all other languages). I thus introduced a totally new internal function in libcurl (called Curl_ascii_equal) for doing case insentive comparisons for english-(ascii?) style strings that thus will make "file" and "FILE" match even if the Turkish locale is selected. --- lib/strequal.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index e8c667497..c1a82f789 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -76,6 +76,30 @@ int curl_strnequal(const char *first, const char *second, size_t max) #endif } +/* + * Curl_ascii_equal() is for doing "ascii" case insensitive strings. This is + * meant to be locale independent and only compare strings we know are safe + * for this. + * See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for some + * further explanation to why this function is necessary. + */ +#define TOASCIIUPPER(x) ((((x) >= 'a') && ((x) <= 'z'))?((x) - 0x20):(x)) + +int Curl_ascii_equal(const char *first, const char *second) +{ + while(*first && *second) { + if(! (TOASCIIUPPER(*first) == TOASCIIUPPER(*second))) + /* get out of the loop as soon as they don't match */ + break; + first++; + second++; + } + /* we do the comparison here (possibly again), just to make sure that if the + loop above is skipped because one of the strings reached zero, we must not + return this as a successful match */ + return (TOASCIIUPPER(*first) == TOASCIIUPPER(*second)); +} + #ifndef HAVE_STRLCAT /* * The strlcat() function appends the NUL-terminated string src to the end -- cgit v1.2.1 From 545cafce9b81f4bda89072a5ebb2d1632f10dc44 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Oct 2008 07:59:00 +0000 Subject: Curl_ascii_equal() must not assume that the string is actually ASCII (so that a-z are consecutive and with a 0x20 "distance" to the uppercase letter), since we do support EBCDIC as well. Thus I replaced the macro with a (larger) switch case. I better change the function name... --- lib/strequal.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index c1a82f789..53654c68a 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -76,6 +76,67 @@ int curl_strnequal(const char *first, const char *second, size_t max) #endif } +/* Portable toupper (remember EBCDIC). Do not use tupper() because + its behavior is altered by the current locale. */ +static bool my_toupper(unsigned char in) +{ + switch (in) { + case 'a': + return 'A'; + case 'b': + return 'B'; + case 'c': + return 'C'; + case 'd': + return 'D'; + case 'e': + return 'E'; + case 'f': + return 'F'; + case 'g': + return 'G'; + case 'h': + return 'H'; + case 'i': + return 'I'; + case 'j': + return 'J'; + case 'k': + return 'K'; + case 'l': + return 'L'; + case 'm': + return 'M'; + case 'n': + return 'N'; + case 'o': + return 'O'; + case 'p': + return 'P'; + case 'q': + return 'Q'; + case 'r': + return 'R'; + case 's': + return 'S'; + case 't': + return 'T'; + case 'u': + return 'U'; + case 'v': + return 'V'; + case 'w': + return 'W'; + case 'x': + return 'X'; + case 'y': + return 'Y'; + case 'z': + return 'Z'; + } + return in; +} + /* * Curl_ascii_equal() is for doing "ascii" case insensitive strings. This is * meant to be locale independent and only compare strings we know are safe @@ -83,12 +144,11 @@ int curl_strnequal(const char *first, const char *second, size_t max) * See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for some * further explanation to why this function is necessary. */ -#define TOASCIIUPPER(x) ((((x) >= 'a') && ((x) <= 'z'))?((x) - 0x20):(x)) int Curl_ascii_equal(const char *first, const char *second) { while(*first && *second) { - if(! (TOASCIIUPPER(*first) == TOASCIIUPPER(*second))) + if(! (my_toupper(*first) == my_toupper(*second))) /* get out of the loop as soon as they don't match */ break; first++; @@ -97,7 +157,7 @@ int Curl_ascii_equal(const char *first, const char *second) /* we do the comparison here (possibly again), just to make sure that if the loop above is skipped because one of the strings reached zero, we must not return this as a successful match */ - return (TOASCIIUPPER(*first) == TOASCIIUPPER(*second)); + return (my_toupper(*first) == my_toupper(*second)); } #ifndef HAVE_STRLCAT -- cgit v1.2.1 From 9d16b4081ed011c11f9876ae2685076e92113593 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Oct 2008 08:23:48 +0000 Subject: Renamed Curl_ascii_equal to Curl_raw_equal and bugfixed the my_toupper function used in strequal.c so now all test cases run fine for me again. --- lib/strequal.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 53654c68a..5065b3871 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -78,7 +78,7 @@ int curl_strnequal(const char *first, const char *second, size_t max) /* Portable toupper (remember EBCDIC). Do not use tupper() because its behavior is altered by the current locale. */ -static bool my_toupper(unsigned char in) +static unsigned char my_toupper(unsigned char in) { switch (in) { case 'a': @@ -138,17 +138,18 @@ static bool my_toupper(unsigned char in) } /* - * Curl_ascii_equal() is for doing "ascii" case insensitive strings. This is - * meant to be locale independent and only compare strings we know are safe - * for this. - * See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for some - * further explanation to why this function is necessary. + * Curl_raw_equal() is for doing "raw" case insensitive strings. This is meant + * to be locale independent and only compare strings we know are safe for + * this. See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for + * some further explanation to why this function is necessary. + * + * The function is capable of comparing a-z case insensitively even for non-ascii. */ -int Curl_ascii_equal(const char *first, const char *second) +int Curl_raw_equal(const char *first, const char *second) { while(*first && *second) { - if(! (my_toupper(*first) == my_toupper(*second))) + if(my_toupper(*first) != my_toupper(*second)) /* get out of the loop as soon as they don't match */ break; first++; -- cgit v1.2.1 From bab5183820dbd2e0ea9ee4f0442844291d05c90e Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 23 Oct 2008 01:20:57 +0000 Subject: Created Curl_raw_nequal() which does a C-locale string case comparison. Changed checkprefix() to use it and those instances of strnequal() that compare host names or other protocol strings that are defined to be independent of case in the C locale. This should fix a few more Turkish locale problems. --- lib/strequal.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 5065b3871..3d00aa213 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -161,6 +161,22 @@ int Curl_raw_equal(const char *first, const char *second) return (my_toupper(*first) == my_toupper(*second)); } +int Curl_raw_nequal(const char *first, const char *second, size_t max) +{ + while(*first && *second && max) { + if(my_toupper(*first) != my_toupper(*second)) { + break; + } + max--; + first++; + second++; + } + if(0 == max) + return 1; /* they are equal this far */ + + return my_toupper(*first) == my_toupper(*second); +} + #ifndef HAVE_STRLCAT /* * The strlcat() function appends the NUL-terminated string src to the end -- cgit v1.2.1 From b701ea36a723b2d7700e23ae53e2c3145dfe7bda Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 23 Oct 2008 11:49:19 +0000 Subject: moved the Curl_raw_ functions into the new lib/rawstr.c file for easier curlx_ inclusion by the curl tool without colliding with the curl_strequal functions. --- lib/strequal.c | 101 --------------------------------------------------------- 1 file changed, 101 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 3d00aa213..e8c667497 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -76,107 +76,6 @@ int curl_strnequal(const char *first, const char *second, size_t max) #endif } -/* Portable toupper (remember EBCDIC). Do not use tupper() because - its behavior is altered by the current locale. */ -static unsigned char my_toupper(unsigned char in) -{ - switch (in) { - case 'a': - return 'A'; - case 'b': - return 'B'; - case 'c': - return 'C'; - case 'd': - return 'D'; - case 'e': - return 'E'; - case 'f': - return 'F'; - case 'g': - return 'G'; - case 'h': - return 'H'; - case 'i': - return 'I'; - case 'j': - return 'J'; - case 'k': - return 'K'; - case 'l': - return 'L'; - case 'm': - return 'M'; - case 'n': - return 'N'; - case 'o': - return 'O'; - case 'p': - return 'P'; - case 'q': - return 'Q'; - case 'r': - return 'R'; - case 's': - return 'S'; - case 't': - return 'T'; - case 'u': - return 'U'; - case 'v': - return 'V'; - case 'w': - return 'W'; - case 'x': - return 'X'; - case 'y': - return 'Y'; - case 'z': - return 'Z'; - } - return in; -} - -/* - * Curl_raw_equal() is for doing "raw" case insensitive strings. This is meant - * to be locale independent and only compare strings we know are safe for - * this. See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for - * some further explanation to why this function is necessary. - * - * The function is capable of comparing a-z case insensitively even for non-ascii. - */ - -int Curl_raw_equal(const char *first, const char *second) -{ - while(*first && *second) { - if(my_toupper(*first) != my_toupper(*second)) - /* get out of the loop as soon as they don't match */ - break; - first++; - second++; - } - /* we do the comparison here (possibly again), just to make sure that if the - loop above is skipped because one of the strings reached zero, we must not - return this as a successful match */ - return (my_toupper(*first) == my_toupper(*second)); -} - -int Curl_raw_nequal(const char *first, const char *second, size_t max) -{ - while(*first && *second && max) { - if(my_toupper(*first) != my_toupper(*second)) { - break; - } - max--; - first++; - second++; - } - if(0 == max) - return 1; /* they are equal this far */ - - return my_toupper(*first) == my_toupper(*second); -} - #ifndef HAVE_STRLCAT /* * The strlcat() function appends the NUL-terminated string src to the end -- cgit v1.2.1 From 4b43d18c4a733b1c47ccab481502a7d84fd07691 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 15 Feb 2010 16:18:52 +0000 Subject: fix compiler warning: conversion from "long" to "size_t" may lose sign --- lib/strequal.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index e8c667497..803064887 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -95,16 +95,19 @@ size_t Curl_strlcat(char *dst, const char *src, size_t siz) char *d = dst; const char *s = src; size_t n = siz; - size_t dlen; + union { + ssize_t sig; + size_t uns; + } dlen; /* Find the end of dst and adjust bytes left but don't go past end */ while(n-- != 0 && *d != '\0') d++; - dlen = d - dst; - n = siz - dlen; + dlen.sig = d - dst; + n = siz - dlen.uns; if(n == 0) - return(dlen + strlen(s)); + return(dlen.uns + strlen(s)); while(*s != '\0') { if(n != 1) { *d++ = *s; @@ -114,6 +117,6 @@ size_t Curl_strlcat(char *dst, const char *src, size_t siz) } *d = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + return(dlen.uns + (s - src)); /* count does not include NUL */ } #endif -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/strequal.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 803064887..f6bf5f3b9 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 0f7bea7c3a6ddb0bf43f890c764322faaa3ba561 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 10 Jun 2011 14:40:46 +0200 Subject: unittest: mark all unit tested functions With "@unittest: [num]" in the header comment for each tested function. Shows we have a log way to go still... --- lib/strequal.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index f6bf5f3b9..15896b9fd 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -31,6 +31,9 @@ #include "strequal.h" +/* + * @unittest: 1301 + */ int curl_strequal(const char *first, const char *second) { #if defined(HAVE_STRCASECMP) @@ -51,6 +54,9 @@ int curl_strequal(const char *first, const char *second) #endif } +/* + * @unittest: 1301 + */ int curl_strnequal(const char *first, const char *second, size_t max) { #if defined(HAVE_STRNCASECMP) -- cgit v1.2.1 From f1586cb4775681810afd8e6626e7842d459f3b85 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Jul 2011 17:23:27 +0200 Subject: stdio.h, stdlib.h, string.h, stdarg.h and ctype.h inclusion done in setup_once.h --- lib/strequal.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/strequal.c') diff --git a/lib/strequal.c b/lib/strequal.c index 15896b9fd..89ad8a6e8 100644 --- a/lib/strequal.c +++ b/lib/strequal.c @@ -22,9 +22,6 @@ #include "setup.h" -#include -#include - #ifdef HAVE_STRINGS_H #include #endif -- cgit v1.2.1