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.

87 lines
2.2 KiB

  1. /***
  2. *mbsset.c - Sets all charcaters of string to given character (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Sets all charcaters of string to given character (MBCS)
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 08-20-93 CFW Change short params to int for 32-bit tree.
  12. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  13. * 05-09-94 CFW Optimize for SBCS.
  14. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  15. *
  16. *******************************************************************************/
  17. #ifdef _MBCS
  18. #include <cruntime.h>
  19. #include <string.h>
  20. #include <mbdata.h>
  21. #include <mbctype.h>
  22. #include <mbstring.h>
  23. /***
  24. * mbsset - Sets all charcaters of string to given character (MBCS)
  25. *
  26. *Purpose:
  27. * Sets all of characters in string (except the terminating '/0'
  28. * character) equal to the supplied character. Handles MBCS
  29. * chars correctly.
  30. *
  31. *Entry:
  32. * unsigned char *string = string to modify
  33. * unsigned int val = value to fill string with
  34. *
  35. *Exit:
  36. * returns string = now filled with the specified char
  37. *
  38. *Uses:
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43. unsigned char * __cdecl _mbsset(
  44. unsigned char *string,
  45. unsigned int val
  46. )
  47. {
  48. unsigned char *start = string;
  49. unsigned char highval, lowval;
  50. if ( _ISNOTMBCP )
  51. return _strset(string, val);
  52. if (highval = (unsigned char) (val>>8)) {
  53. /* 2-byte value */
  54. lowval = (unsigned char)(val & 0x00ff);
  55. while (*string) {
  56. *string++ = highval;
  57. if (*string)
  58. *string++ = lowval;
  59. else
  60. /* don't orphan lead byte */
  61. string[-1] = ' ';
  62. }
  63. }
  64. else {
  65. /* single byte value */
  66. while (*string)
  67. *string++ = (unsigned char)val;
  68. }
  69. return(start);
  70. }
  71. #endif /* _MBCS */