~itmages/itmages/itmages-windows-extension

« back to all changes in this revision

Viewing changes to enconv.c

  • Committer: Dmitry
  • Date: 2012-03-11 07:56:24 UTC
  • Revision ID: git-v1:d5a30bf1fe74b46641b08d0151d39dba15b67f0e
Migrate from launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    ITmages  upload client for Windows
 
3
    Copyright (C) 2011 Dmitriy Simbiriatin <slpiv@itmages.ru>
 
4
 
 
5
    This program is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU General Public License
 
7
    as published by the Free Software Foundation; either version 2
 
8
    of the License, or (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include <windows.h>
 
21
#include "errorshandler.h"
 
22
 
 
23
wchar_t *AcpToWide(char *string)
 
24
{
 
25
    int len = MultiByteToWideChar(CP_ACP, 0, string, -1, NULL, 0);
 
26
    wchar_t *buffer = (wchar_t*) malloc(len * sizeof(wchar_t));
 
27
    if (buffer == NULL) {
 
28
        ErrorsHandler(ERROR_MEMALLOC);
 
29
        exit(EXIT_FAILURE);
 
30
    }
 
31
    MultiByteToWideChar(CP_ACP, 0, string, -1, buffer, len);
 
32
    return buffer;
 
33
}
 
34
 
 
35
char *WideToAcp(wchar_t *string)
 
36
{
 
37
    int len = WideCharToMultiByte(CP_ACP, 0, string, -1, NULL, 0, 0, 0);
 
38
    char *buffer = (char*) malloc(len * sizeof(char));
 
39
    if (buffer == NULL) {
 
40
        ErrorsHandler(ERROR_MEMALLOC);
 
41
        exit(EXIT_FAILURE);
 
42
    }
 
43
    WideCharToMultiByte(CP_ACP, 0, string, -1, buffer, len, 0, 0);
 
44
    return buffer;
 
45
}
 
46
 
 
47
wchar_t *Utf8ToWide(char *string)
 
48
{
 
49
    int len = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0);
 
50
    wchar_t *buffer = (wchar_t*) malloc(len * sizeof(wchar_t));
 
51
    if (buffer == NULL) {
 
52
        ErrorsHandler(ERROR_MEMALLOC);
 
53
        exit(EXIT_FAILURE);
 
54
    }
 
55
    MultiByteToWideChar(CP_UTF8, 0, string, -1, buffer, len);
 
56
    return buffer;
 
57
}
 
58
 
 
59
char *WideToUtf8(wchar_t *string)
 
60
{
 
61
    int len = WideCharToMultiByte(CP_UTF8, 0, string, -1, NULL, 0, 0, 0);
 
62
    char *buffer = (char*) malloc(len * sizeof(char));
 
63
    if (buffer == NULL) {
 
64
        ErrorsHandler(ERROR_MEMALLOC);
 
65
        exit(EXIT_FAILURE);
 
66
    }
 
67
    WideCharToMultiByte(CP_UTF8, 0, string, -1, buffer, len, 0, 0);
 
68
    return buffer;
 
69
}