home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / strncasecmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  1.6 KB  |  71 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: strncasecmp.c,v 1.1 1996/12/11 11:18:28 aros Exp $
  4.  
  5.     Desc: ANSI C function strncasecmp()
  6.     Lang: english
  7. */
  8. #include <ctype.h>
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <string.h>
  14.  
  15.     int strncasecmp (
  16.  
  17. /*  SYNOPSIS */
  18.     const char * str1,
  19.     const char * str2,
  20.     size_t         n)
  21.  
  22. /*  FUNCTION
  23.     Calculate str1 - str2 ignoring case. Upto n characters are taken
  24.     into account.
  25.  
  26.     INPUTS
  27.     str1, str2 - Strings to compare
  28.  
  29.     RESULT
  30.     The difference of the strings. The difference is 0, if both are
  31.     equal, < 0 if str1 < str2 and > 0 if str1 > str2. Note that
  32.     it may be greater then 1 or less than -1.
  33.  
  34.     NOTES
  35.     This function is not part of a library and may thus be called
  36.     any time.
  37.  
  38.     EXAMPLE
  39.  
  40.     BUGS
  41.  
  42.     SEE ALSO
  43.  
  44.     INTERNALS
  45.  
  46.     HISTORY
  47.     24-12-95    digulla created
  48.  
  49. ******************************************************************************/
  50. {
  51.     int diff;
  52.  
  53.     /* No need to check *str2 since: a) str1 is equal str2 (both are 0),
  54.     then *str1 will terminate the loop b) str1 and str2 are not equal
  55.     (eg. *str2 is 0), then the diff part will be FALSE. I calculate
  56.     the diff first since a) it's more probable that the first chars
  57.     will be different and b) I don't need to initialize diff then. */
  58.     while (n && !(diff = tolower (*str1) - tolower (*str2)) && *str1)
  59.     {
  60.     /* advance both strings. I do that here, since doing it in the
  61.         check above would mean to advance the strings once too often */
  62.     str1 ++;
  63.     str2 ++;
  64.  
  65.     n--;
  66.     }
  67.  
  68.     /* Now return the difference. */
  69.     return diff;
  70. } /* strncasecmp */
  71.