home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / MULTBYTE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.6 KB  |  80 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - multbyte.c
  3.  *
  4.  * function(s)
  5.  *        mblen    - determines number of bytes in multibyte character
  6.  *        mbtowc   - converts multibyte character to wide character
  7.  *        wctomb   - converts wide character to multibyte character
  8.  *        mbstowcs - converts a multibyte string to a wide character string
  9.  *        wcstombs - converts a wide character string to a multibyte string
  10.  *-----------------------------------------------------------------------*/
  11.  
  12. /*
  13.  *      C/C++ Run Time Library - Version 5.0
  14.  *
  15.  *      Copyright (c) 1987, 1992 by Borland International
  16.  *      All Rights Reserved.
  17.  *
  18.  */
  19.  
  20.  
  21. #include <stdlib.h>
  22.  
  23. #pragma argsused
  24. int _FARFUNC mblen(const char *s, size_t n)
  25. {
  26.     if (s == NULL)
  27.         return 0;
  28.     if (*s == 0)
  29.         return 0;
  30.     else
  31.         return 1;
  32. }
  33.  
  34.  
  35. #pragma argsused
  36. int _FARFUNC mbtowc(wchar_t *pwc, const char *s, size_t n)
  37. {
  38.     if (s == NULL)
  39.         return 0;
  40.     if (pwc != NULL)
  41.         *pwc = *s;
  42.     if (*s == 0)
  43.         return 0;
  44.     else
  45.         return 1;
  46. }
  47.  
  48.  
  49. int _FARFUNC wctomb(char *s, wchar_t wc)
  50. {
  51.     if (s == NULL)
  52.         return 0;
  53.     *s = wc;
  54.     return 1; /* zero if wc == 0 ? */
  55. }
  56.  
  57.  
  58. size_t _FARFUNC mbstowcs(wchar_t *pwcs, const char *s, size_t n)
  59. {
  60.     int i;
  61.  
  62.     for (i=0; i<n && *s; i++)
  63.         *pwcs++ = *s++;
  64.     if (i<n)
  65.         *pwcs = 0;
  66.     return i;
  67. }
  68.  
  69.  
  70. size_t _FARFUNC wcstombs(char *s, const wchar_t *pwcs, size_t n)
  71. {
  72.     int i;
  73.  
  74.     for (i=0; i<n && *pwcs; i++)
  75.         *s++ = *pwcs++;
  76.     if (i<n)
  77.         *s = 0;
  78.     return i;
  79. }
  80.