1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| /*TestConvertStr.c*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <stdio.h>
#include "TestConvertStr.h"
wchar_t * AllocA2W(char const *sczA)
{
size_t const cchLenA = strlen(sczA);
size_t const cchLenW = mbstowcs(NULL, sczA, cchLenA+1);
wchar_t * szW = calloc(cchLenW+1, sizeof *szW);
if(szW!=NULL)
mbstowcs(szW, sczA, cchLenA+1);
return szW;
}
char * AllocW2A(wchar_t const *sczW)
{
size_t const cchLenW = wcslen(sczW);
size_t const cchLenA = wcstombs(NULL, sczW, cchLenW+1);
char * szA = calloc(cchLenA+1, sizeof *szA);
if(szA!=NULL)
wcstombs(szA, sczW, cchLenW+1);
return szA;
}
char * AllocA2A(char const *sczA)
{
size_t const cchLenA = strlen(sczA);
char * szA = calloc(cchLenA+1, sizeof *szA);
if(szA!=NULL)
strcpy(szA, sczA);
return szA;
}
wchar_t * AllocW2W(wchar_t const *sczW)
{
size_t const cchLenW = wcslen(sczW);
wchar_t * szW = calloc(cchLenW+1, sizeof *szW);
if(szW!=NULL)
wcscpy(szW, sczW);
return szW;
}
void FreeA(char *szA)
{
free(szA);
}
void FreeW(wchar_t *szW)
{
free(szW);
}
char * AbortIfNullA(char *szA)
{
if(szA==NULL)
{
fputs("Echec d'allocation en conversion de chaine!\n", stderr);
abort();
}
return szA;
}
wchar_t * AbortIfNullW(wchar_t *szW)
{
if(szW==NULL)
{
fputs("Echec d'allocation en conversion de chaine!\n", stderr);
abort();
}
return szW;
} |
Partager