This source file includes following definitions.
- u8_strconv_to_encoding
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 #include <config.h>
28
29
30 #include "uniconv.h"
31
32 #include <errno.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "c-strcaseeq.h"
37 #include "striconveha.h"
38 #include "unistr.h"
39
40 char *
41 u8_strconv_to_encoding (const uint8_t *string,
42 const char *tocode,
43 enum iconv_ilseq_handler handler)
44 {
45 char *result;
46 size_t length;
47
48 if (STRCASEEQ (tocode, "UTF-8", 'U','T','F','-','8',0,0,0,0))
49 {
50
51 length = u8_strlen (string) + 1;
52 if (u8_check (string, length))
53 {
54 errno = EILSEQ;
55 return NULL;
56 }
57 result = (char *) malloc (length);
58 if (result == NULL)
59 {
60 errno = ENOMEM;
61 return NULL;
62 }
63 memcpy (result, (const char *) string, length);
64 return result;
65 }
66 else
67 {
68 result = NULL;
69 length = 0;
70 if (mem_iconveha ((const char *) string, u8_strlen (string) + 1,
71 "UTF-8", tocode,
72 handler == iconveh_question_mark, handler,
73 NULL, &result, &length) < 0)
74 return NULL;
75
76 if (!(length > 0 && result[length-1] == '\0'
77 && strlen (result) == length-1))
78 {
79 free (result);
80 errno = EILSEQ;
81 return NULL;
82 }
83 return result;
84 }
85 }