OSDN Git Service

I was library can be compiled 20140223
[zither/ds-zither.git] / libms / safe_convert_data.c
1 /// selef_convert_data() 
2 //  masashi shimakura 20140223
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <iconv.h>
8 #include <errno.h>
9
10 #include "libms.h"
11
12
13 char * safe_convert_data(const char * input_code, const char * output_code, char * data, int * ret)
14 {
15 char * inbuf;
16 char * outbuf;
17 int max;
18 // int count;
19
20 max = (int)strlen(data);
21
22 if(max > 0){
23    inbuf = (char *)calloc(max * 2, sizeof(char));
24    outbuf = (char *)calloc(max * 2, sizeof(char));
25    inbuf = safe_memcpy(inbuf, data, max);
26
27    ret = convert(input_code, output_code, inbuf, outbuf, (max * 2));
28
29    data = safe_memcpy(data, outbuf, (max * 2));
30
31    free(inbuf);
32    free(outbuf);
33    }
34 else{
35    fprintf(stderr,"safe_convert_data(): data size err.\n");
36    }
37
38 return data;
39 }
40
41
42
43
44
45
46