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.3 KiB

  1. /***
  2. *wcsrev.c - reverse a wide-character string in place
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _wcsrev() - reverse a wchar_t string in place (not including
  8. * L'\0' character)
  9. *
  10. *Revision History:
  11. * 09-09-91 ETC Created from strrev.c.
  12. * 04-07-92 KRS Updated and ripped out _INTL switches.
  13. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  14. * 02-07-94 CFW POSIXify.
  15. *
  16. *******************************************************************************/
  17. #ifndef _POSIX_
  18. #include <cruntime.h>
  19. #include <string.h>
  20. /***
  21. *wchar_t *_wcsrev(string) - reverse a wide-character string in place
  22. *
  23. *Purpose:
  24. * Reverses the order of characters in the string. The terminating
  25. * null character remains in place (wide-characters).
  26. *
  27. *Entry:
  28. * wchar_t *string - string to reverse
  29. *
  30. *Exit:
  31. * returns string - now with reversed characters
  32. *
  33. *Exceptions:
  34. *
  35. *******************************************************************************/
  36. wchar_t * __cdecl _wcsrev (
  37. wchar_t * string
  38. )
  39. {
  40. wchar_t *start = string;
  41. wchar_t *left = string;
  42. wchar_t ch;
  43. while (*string++) /* find end of string */
  44. ;
  45. string -= 2;
  46. while (left < string)
  47. {
  48. ch = *left;
  49. *left++ = *string;
  50. *string-- = ch;
  51. }
  52. return(start);
  53. }
  54. #endif /* _POSIX_ */