root/lib/libc/strcmp.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. strcmp

   1 /*
   2 FUNCTION
   3         <<strcmp>>---character string compare
   4         
   5 INDEX
   6         strcmp
   7 
   8 ANSI_SYNOPSIS
   9         #include <string.h>
  10         int strcmp(const char *<[a]>, const char *<[b]>);
  11 
  12 TRAD_SYNOPSIS
  13         #include <string.h>
  14         int strcmp(<[a]>, <[b]>)
  15         char *<[a]>;
  16         char *<[b]>;
  17 
  18 DESCRIPTION
  19         <<strcmp>> compares the string at <[a]> to
  20         the string at <[b]>.
  21 
  22 RETURNS
  23         If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,
  24         <<strcmp>> returns a number greater than zero.  If the two
  25         strings match, <<strcmp>> returns zero.  If <<*<[a]>>>
  26         sorts lexicographically before <<*<[b]>>>, <<strcmp>> returns a
  27         number less than zero.
  28 
  29 PORTABILITY
  30 <<strcmp>> is ANSI C.
  31 
  32 <<strcmp>> requires no supporting OS subroutines.
  33 
  34 QUICKREF
  35         strcmp ansi pure
  36 */
  37 
  38 int strcmp(const char *s1, const char *s2)
  39 { 
  40   while (*s1 != '\0' && *s1 == *s2)
  41     {
  42       s1++;
  43       s2++;
  44     }
  45 
  46   return (*(unsigned char *) s1) - (*(unsigned char *) s2);
  47 }

/* [<][>][^][v][top][bottom][index][help] */