~ubuntu-branches/ubuntu/quantal/freerdp/quantal

« back to all changes in this revision

Viewing changes to channels/common/chan_stream.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2010-06-23 21:39:09 UTC
  • Revision ID: james.westby@ubuntu.com-20100623213909-bb9pvvv03913tdv6
Tags: upstream-0.7.1
ImportĀ upstreamĀ versionĀ 0.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- c-basic-offset: 8 -*-
 
2
   FreeRDP: A Remote Desktop Protocol client.
 
3
 
 
4
   Copyright (C) Marc-Andre Moreau <marcandre.moreau@gmail.com> 2010
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 2 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
*/
 
20
 
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <string.h>
 
24
#include <iconv.h>
 
25
#include "chan_stream.h"
 
26
 
 
27
int
 
28
set_wstr(char* dst, int dstlen, char* src, int srclen)
 
29
{
 
30
        iconv_t cd;
 
31
        size_t avail;
 
32
        size_t in_size;
 
33
 
 
34
        cd = iconv_open("UTF-16LE", "UTF-8");
 
35
        if (cd == (iconv_t) - 1)
 
36
        {
 
37
                printf("set_wstr: iconv_open failed.\n");
 
38
                return 0;
 
39
        }
 
40
        in_size = (size_t)srclen;
 
41
        avail = (size_t)dstlen;
 
42
        iconv(cd, &src, &in_size, &dst, &avail);
 
43
        iconv_close(cd);
 
44
        return dstlen - (int)avail;
 
45
}
 
46
 
 
47
int
 
48
get_wstr(char* dst, int dstlen, char* src, int srclen)
 
49
{
 
50
        iconv_t cd;
 
51
        size_t avail;
 
52
        size_t in_size;
 
53
 
 
54
        cd = iconv_open("UTF-8", "UTF-16LE");
 
55
        if (cd == (iconv_t) - 1)
 
56
        {
 
57
                printf("set_wstr: iconv_open failed.\n");
 
58
                return 0;
 
59
        }
 
60
        in_size = (size_t)srclen;
 
61
        avail = (size_t)dstlen;
 
62
        iconv(cd, &src, &in_size, &dst, &avail);
 
63
        iconv_close(cd);
 
64
        return dstlen - (int)avail;
 
65
}
 
66