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

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