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

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