ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

mbstowcs_nt.c
Go to the documentation of this file.
00001 #define WIN32_NO_STATUS
00002 #include <windows.h>
00003 #include <ndk/umtypes.h>
00004 #include <ndk/rtlfuncs.h>
00005 #include <string.h>
00006 
00007 WCHAR NTAPI RtlAnsiCharToUnicodeChar(IN OUT PUCHAR *AnsiChar);
00008 #undef MB_CUR_MAX
00009 #define MB_CUR_MAX 2
00010 
00011 /*
00012  * @implemented
00013  */
00014 int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
00015 {
00016     UCHAR mbarr[MB_CUR_MAX] = { 0 };
00017     PUCHAR mbs = mbarr;
00018     WCHAR wc;
00019 
00020     if (mbchar == NULL)
00021         return 0;
00022 
00023     if (wchar == NULL)
00024         return 0;
00025 
00026     memcpy(mbarr, mbchar, min(count, sizeof mbarr));
00027 
00028     wc = RtlAnsiCharToUnicodeChar(&mbs);
00029 
00030     if (wc == L' ' && mbarr[0] != ' ')
00031         return -1;
00032 
00033     *wchar = wc;
00034 
00035     return (int)(mbs - mbarr);
00036 }
00037 
00038 /*
00039  * @implemented
00040  */
00041 size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
00042 {
00043     NTSTATUS Status;
00044     ULONG Size;
00045     ULONG Length;
00046 
00047     Length = (ULONG)strlen (mbstr);
00048 
00049     if (wcstr == NULL)
00050     {
00051         RtlMultiByteToUnicodeSize (&Size,
00052                                    mbstr,
00053                                    Length);
00054 
00055         return (size_t)Size;
00056     }
00057 
00058     Status = RtlMultiByteToUnicodeN (wcstr,
00059                                      (ULONG)count * sizeof(WCHAR),
00060                                      &Size,
00061                                      mbstr,
00062                                      Length);
00063     if (!NT_SUCCESS(Status))
00064         return -1;
00065 
00066     return (size_t)Size;
00067 }
00068 
00069 /* EOF */

Generated on Sat May 26 2012 04:35:35 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.