forked from jcline/fuse-google-drive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencoding_functions.c
41 lines (36 loc) · 893 Bytes
/
encoding_functions.c
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
#include <iconv.h>
#include <unistd.h>
#include <string.h>
#define GOOGLE_CODE_PAGE "UTF-8"
int
encode(char *input, char *buffer, size_t buffsize, const char *codeto)
{
size_t insize;
const char* in = input;
const char* out = buffer;
int iconverr;
iconv_t d = iconv_open(codeto, GOOGLE_CODE_PAGE);
if (d == (iconv_t)(-1))
return -1;
insize = strlen(input);
bzero(buffer, buffsize);
if((iconverr = iconv(d, &in, &insize, &out, &buffsize))==-1)
return -1;
iconv_close(d);
}
int
decode(char *input, char *buffer, size_t buffsize, const char *codefrom)
{
size_t insize;
const char* in = input;
const char* out = buffer;
int iconverr;
iconv_t d = iconv_open(GOOGLE_CODE_PAGE, codefrom);
if (d == (iconv_t)(-1))
return -1;
insize = strlen(input);
bzero(buffer, buffsize);
if((iconverr = iconv(d, &in, &insize, &out, &buffsize))==-1)
return -1;
iconv_close(d);
}