home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / strcoll.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  98 lines

  1. /***
  2. *strcoll.c - Collate locale strings
  3. *
  4. *       Copyright (c) 1988-1998, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Compare two strings using the locale LC_COLLATE information.
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <string.h>
  13.  
  14. #ifdef _WIN32
  15. #include <windows.h>
  16. #include <stdlib.h>
  17. #include <malloc.h>
  18. #include <locale.h>
  19. #include <setlocal.h>
  20. #include <mtdll.h>
  21. #include <errno.h>
  22. #include <awint.h>
  23. #endif  /* _WIN32 */
  24.  
  25. /***
  26. *int strcoll() - Collate locale strings
  27. *
  28. *Purpose:
  29. *       Compare two strings using the locale LC_COLLATE information.
  30. *       [ANSI].
  31. *
  32. *       Non-C locale support available under _INTL switch.
  33. *       In the C locale, strcoll() simply resolves to strcmp().
  34. *Entry:
  35. *       const char *s1 = pointer to the first string
  36. *       const char *s2 = pointer to the second string
  37. *
  38. *Exit:
  39. *       Less than 0    = first string less than second string
  40. *       0              = strings are equal
  41. *       Greater than 0 = first string greater than second string
  42. *
  43. *Exceptions:
  44. *       _NLSCMPERROR    = error
  45. *       errno = EINVAL
  46. *
  47. *******************************************************************************/
  48.  
  49. int __cdecl strcoll (
  50.         const char *_string1,
  51.         const char *_string2
  52.         )
  53. {
  54. #if defined (_WIN32)
  55.  
  56.         int ret;
  57. #if defined (_MT)
  58.         int local_lock_flag;
  59. #endif  /* defined (_MT) */
  60.  
  61.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  62.                 return strcmp(_string1, _string2);
  63.         }
  64.  
  65.         _lock_locale( local_lock_flag )
  66.  
  67. #if defined (_MT)
  68.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  69.                 _unlock_locale( local_lock_flag )
  70.                 return strcmp(_string1, _string2);
  71.         }
  72. #endif  /* defined (_MT) */
  73.  
  74.         if ( 0 == (ret = __crtCompareStringA( __lc_handle[LC_COLLATE],
  75.                                               SORT_STRINGSORT,
  76.                                               _string1,
  77.                                               -1,
  78.                                               _string2,
  79.                                               -1,
  80.                                               __lc_collate_cp )) )
  81.             goto error_cleanup;
  82.  
  83.         _unlock_locale( local_lock_flag )
  84.         return (ret - 2);
  85.  
  86. error_cleanup:
  87.  
  88.         _unlock_locale( local_lock_flag )
  89.         errno = EINVAL;
  90.         return _NLSCMPERROR;
  91.  
  92. #else  /* defined (_WIN32) */
  93.  
  94.         return strcmp(_string1,_string2);
  95.  
  96. #endif  /* defined (_WIN32) */
  97. }
  98.