OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [string/] [strncasecmp.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/*
2
FUNCTION
3
        <<strncasecmp>>---case insensitive character string compare
4
 
5
INDEX
6
        strncasecmp
7
 
8
ANSI_SYNOPSIS
9
        #include <string.h>
10
        int strncasecmp(const char *<[a]>, const char * <[b]>, size_t <[length]>);
11
 
12
TRAD_SYNOPSIS
13
        #include <string.h>
14
        int strncasecmp(<[a]>, <[b]>, <[length]>)
15
        char *<[a]>;
16
        char *<[b]>;
17
        size_t <[length]>
18
 
19
DESCRIPTION
20
        <<strncasecmp>> compares up to <[length]> characters
21
        from the string at <[a]> to the string at <[b]> in a
22
        case-insensitive manner.
23
 
24
RETURNS
25
 
26
        If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
27
        both are converted to upper case), <<strncasecmp>> returns a
28
        number greater than zero.  If the two strings are equivalent,
29
        <<strncasecmp>> returns zero.  If <<*<[a]>>> sorts
30
        lexicographically before <<*<[b]>>>, <<strncasecmp>> returns a
31
        number less than zero.
32
 
33
PORTABILITY
34
<<strncasecmp>> is in the Berkeley Software Distribution.
35
 
36
<<strncasecmp>> requires no supporting OS subroutines. It uses
37 56 joel
tolower() from elsewhere in this library.
38 39 lampret
 
39
QUICKREF
40
        strncasecmp
41
*/
42
 
43
#include <string.h>
44
#include <ctype.h>
45
 
46
int
47
_DEFUN (strncasecmp, (s1, s2, n),
48
        _CONST char *s1 _AND
49
        _CONST char *s2 _AND
50
        size_t n)
51
{
52
  if (n == 0)
53
    return 0;
54
 
55 56 joel
  while (n-- != 0 && tolower(*s1) == tolower(*s2))
56 39 lampret
    {
57
      if (n == 0 || *s1 == '\0' || *s2 == '\0')
58
        break;
59
      s1++;
60
      s2++;
61
    }
62
 
63 56 joel
  return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
64 39 lampret
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.