BOOTSTRAP (kutils) functions


LIBRARY ROUTINE

kstrncmp - compare the first n characters of two strings

LIBRARY CALL

int kstrncmp(
   const char *istr1,
   const char *istr2,
   size_t      num)

INPUT

OUTPUT

none

RETURN VALUE

If the two strings are identical or 'num' is less than or equal to zero, the value of 0 is returned. If the two strings differ, the ASCII value difference of the first character that differs in the two strings will be returned. If the ASCII value of the differing character in 'istr1' is greater than the one in 'istr2', then the return value is positive, and implies that 'istr1' is greater than 'istr2'. If the difference between the two ASCII values is negative, the return value implies that 'istr2' is greater than 'istr1'.

DESCRIPTION

This routine is a replacement for the system strcasecmp. It does a character by character case sensitive comparison of both input strings until the current character for one string does not equal the current character of the other string, until the end of the input strings are reached, or until num characters have been compared. It protects against NULL on the input strings by replacing NULL pointers with a reference to an empty string.

ADDITIONAL INFORMATION

none

EXAMPLES

This example is similar to the kstrncasecmp() example. It calls kstrncmp twice on the same two strings with different values of 'num'.
char *s1 = "Same-DIFFERENT";
char *s2 = "Same-different";

kprintf("Same is %d\n", kstrncmp(s1, s2, 5)); kprintf("Different is %d\n", kstrncmp(s1, s2, 10));

The output will be:

Same is 0 Different is -32

SIDE EFFECTS

none

RESTRICTIONS

none

MODIFICATION

none

FILES

$BOOTSTRAP/objects/library/kutils/src/strings.c

SEE ALSO

kutils(3)

COPYRIGHT

Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.