summaryrefslogtreecommitdiff
path: root/src/libstddjb/case_diffb.c
blob: 47e10bbb475a0887cf47c365e97f547f80f3893d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* ISC license. */

#include <skalibs/config.h>
#include <skalibs/bytestr.h>

#ifdef SKALIBS_FLAG_REPLACE_LIBC

int case_diffb (char const *s, unsigned int len, char const *t)
{
  register unsigned char x = 0, y = 0 ;
  unsigned char const d = 'a' - 'A' ;

  while (len-- && (x == y))
  {
    x = *s++ ;
    if (('a' <= x) && (x <= 'z')) x -= d ;
    y = *t++ ;
    if (('a' <= y) && (y <= 'z')) y -= d ;
  }
  return (int)(x - y) ;
}

#else

#include <strings.h>

int case_diffb (char const *s, unsigned int len, char const *t)
{
  return strncasecmp(s, t, len) ;
}

#endif