Source code of Windows XP (NT5)
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.

71 lines
1.8 KiB

  1. /***
  2. *strcmp.c - routine to compare two strings (for equal, less, or greater)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Compares two string, determining their lexical order.
  8. *
  9. *Revision History:
  10. * 05-31-89 JCR C version created.
  11. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  12. * copyright.
  13. * 10-01-90 GJF New-style function declarator.
  14. * 04-01-91 SRW Add #pragma function for i386 _WIN32_ and _CRUISER_
  15. * builds
  16. * 10-11-91 GJF Bug fix! Comparison of final bytes must use unsigned
  17. * chars.
  18. * 09-01-93 GJF Replaced _CALLTYPE1 with __cdecl.
  19. * 12-03-93 GJF Turn on #pragma function for all MS front-ends (esp.,
  20. * Alpha compiler).
  21. *
  22. *******************************************************************************/
  23. #include <cruntime.h>
  24. #include <string.h>
  25. #ifdef _MSC_VER
  26. #pragma function(strcmp)
  27. #endif
  28. /***
  29. *strcmp - compare two strings, returning less than, equal to, or greater than
  30. *
  31. *Purpose:
  32. * STRCMP compares two strings and returns an integer
  33. * to indicate whether the first is less than the second, the two are
  34. * equal, or whether the first is greater than the second.
  35. *
  36. * Comparison is done byte by byte on an UNSIGNED basis, which is to
  37. * say that Null (0) is less than any other character (1-255).
  38. *
  39. *Entry:
  40. * const char * src - string for left-hand side of comparison
  41. * const char * dst - string for right-hand side of comparison
  42. *
  43. *Exit:
  44. * returns -1 if src < dst
  45. * returns 0 if src == dst
  46. * returns +1 if src > dst
  47. *
  48. *Exceptions:
  49. *
  50. *******************************************************************************/
  51. int __cdecl strcmp (
  52. const char * src,
  53. const char * dst
  54. )
  55. {
  56. int ret = 0 ;
  57. while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
  58. ++src, ++dst;
  59. if ( ret < 0 )
  60. ret = -1 ;
  61. else if ( ret > 0 )
  62. ret = 1 ;
  63. return( ret );
  64. }