1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * $Id: strequal.c,v 1.25 2004/01/29 13:56:45 bagder Exp $
22 ***************************************************************************/
31 #ifdef HAVE_STRCASECMP
32 /* this is for "-ansi -Wall -pedantic" to stop complaining! */
33 extern int (strcasecmp)(const char *s1, const char *s2);
34 extern int (strncasecmp)(const char *s1, const char *s2, size_t n);
37 int curl_strequal(const char *first, const char *second)
39 #if defined(HAVE_STRCASECMP)
40 return !(strcasecmp)(first, second);
41 #elif defined(HAVE_STRCMPI)
42 return !(strcmpi)(first, second);
43 #elif defined(HAVE_STRICMP)
44 return !(stricmp)(first, second);
46 while (*first && *second) {
47 if (toupper(*first) != toupper(*second)) {
53 return toupper(*first) == toupper(*second);
57 int curl_strnequal(const char *first, const char *second, size_t max)
59 #if defined(HAVE_STRCASECMP)
60 return !strncasecmp(first, second, max);
61 #elif defined(HAVE_STRCMPI)
62 return !strncmpi(first, second, max);
63 #elif defined(HAVE_STRICMP)
64 return !strnicmp(first, second, max);
66 while (*first && *second && max) {
67 if (toupper(*first) != toupper(*second)) {
75 return 1; /* they are equal this far */
77 return toupper(*first) == toupper(*second);
83 * The strlcat() function appends the NUL-terminated string src to the end
84 * of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-termi-
87 * The strlcpy() and strlcat() functions return the total length of the
88 * string they tried to create. For strlcpy() that means the length of src.
89 * For strlcat() that means the initial length of dst plus the length of
90 * src. While this may seem somewhat confusing it was done to make trunca-
91 * tion detection simple.
95 size_t Curl_strlcat(char *dst, const char *src, size_t siz)
102 /* Find the end of dst and adjust bytes left but don't go past end */
103 while (n-- != 0 && *d != '\0')
109 return(dlen + strlen(s));
119 return(dlen + (s - src)); /* count does not include NUL */