Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

  1. /***
  2. *strncmp.c - compare first n characters of two strings
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines strncmp() - compare first n characters of two strings
  8. * for lexical order.
  9. *
  10. *Revision History:
  11. * 05-31-89 JCR C version created.
  12. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  13. * copyright.
  14. * 10-02-90 GJF New-style function declarator.
  15. * 10-11-91 GJF Bug fix! Comparison of final bytes must use unsigned
  16. * chars.
  17. * 09-02-93 GJF Replaced _CALLTYPE1 with __cdecl.
  18. *
  19. *******************************************************************************/
  20. #include <cruntime.h>
  21. #include <string.h>
  22. /***
  23. *int strncmp(first, last, count) - compare first count chars of strings
  24. *
  25. *Purpose:
  26. * Compares two strings for lexical order. The comparison stops
  27. * after: (1) a difference between the strings is found, (2) the end
  28. * of the strings is reached, or (3) count characters have been
  29. * compared.
  30. *
  31. *Entry:
  32. * char *first, *last - strings to compare
  33. * unsigned count - maximum number of characters to compare
  34. *
  35. *Exit:
  36. * returns <0 if first < last
  37. * returns 0 if first == last
  38. * returns >0 if first > last
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43. int __cdecl strncmp (
  44. const char * first,
  45. const char * last,
  46. size_t count
  47. )
  48. {
  49. if (!count)
  50. return(0);
  51. while (--count && *first && *first == *last)
  52. {
  53. first++;
  54. last++;
  55. }
  56. return( *(unsigned char *)first - *(unsigned char *)last );
  57. }