~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to lib/strequal.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: strequal.c,v 1.33 2007-11-07 09:21:36 bagder Exp $
 
21
 * $Id: strequal.c,v 1.40 2008-10-23 11:49:19 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
 
#ifndef _GNU_SOURCE
25
 
/* glibc needs this to define the prototype for strcasestr */
26
 
#define _GNU_SOURCE 1
27
 
#endif
28
 
 
29
24
#include "setup.h"
30
25
 
31
26
#include <string.h>
37
32
 
38
33
#include "strequal.h"
39
34
 
40
 
#if defined(HAVE_STRCASECMP) && defined(__STRICT_ANSI__)
41
 
/* this is for "-ansi -Wall -pedantic" to stop complaining! */
42
 
extern int (strcasecmp)(const char *s1, const char *s2);
43
 
extern int (strncasecmp)(const char *s1, const char *s2, size_t n);
44
 
#endif
45
 
 
46
35
int curl_strequal(const char *first, const char *second)
47
36
{
48
37
#if defined(HAVE_STRCASECMP)
65
54
 
66
55
int curl_strnequal(const char *first, const char *second, size_t max)
67
56
{
68
 
#if defined(HAVE_STRCASECMP)
 
57
#if defined(HAVE_STRNCASECMP)
69
58
  return !strncasecmp(first, second, max);
70
 
#elif defined(HAVE_STRCMPI)
 
59
#elif defined(HAVE_STRNCMPI)
71
60
  return !strncmpi(first, second, max);
72
 
#elif defined(HAVE_STRICMP)
 
61
#elif defined(HAVE_STRNICMP)
73
62
  return !strnicmp(first, second, max);
74
63
#else
75
64
  while(*first && *second && max) {
87
76
#endif
88
77
}
89
78
 
90
 
/*
91
 
 * Curl_strcasestr() finds the first occurrence of the substring needle in the
92
 
 * string haystack.  The terminating `\0' characters are not compared. The
93
 
 * matching is done CASE INSENSITIVE, which thus is the difference between
94
 
 * this and strstr().
95
 
 */
96
 
char *Curl_strcasestr(const char *haystack, const char *needle)
97
 
{
98
 
#if defined(HAVE_STRCASESTR)
99
 
  return strcasestr(haystack, needle);
100
 
#else
101
 
  size_t nlen = strlen(needle);
102
 
  size_t hlen = strlen(haystack);
103
 
 
104
 
  while(hlen-- >= nlen) {
105
 
    if(curl_strnequal(haystack, needle, nlen))
106
 
      return (char *)haystack;
107
 
    haystack++;
108
 
  }
109
 
  return NULL;
110
 
#endif
111
 
}
112
 
 
113
79
#ifndef HAVE_STRLCAT
114
80
/*
115
81
 * The strlcat() function appends the NUL-terminated string src to the end