2 Unix SMB/CIFS implementation.
3 Character set conversion Extensions
4 Copyright (C) Igor Vergeichik <iverg@mail.ru> 2001
5 Copyright (C) Andrew Tridgell 2001
6 Copyright (C) Simo Sorce 2001
7 Copyright (C) Martin Pool 2003
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "system/locale.h"
29 * Copy a string from a unix char* src to a UCS2 destination,
30 * allocating a buffer using talloc().
32 * @param dest always set at least to NULL
33 * @param converted_size set to the number of bytes occupied by the string in
34 * the destination on success.
36 * @return true if new buffer was correctly allocated, and string was
39 bool push_ucs2_talloc(TALLOC_CTX
*ctx
, smb_ucs2_t
**dest
, const char *src
,
40 size_t *converted_size
)
42 size_t src_len
= strlen(src
)+1;
45 return convert_string_talloc(ctx
, CH_UNIX
, CH_UTF16LE
, src
, src_len
,
46 (void **)dest
, converted_size
);
50 * @brief Create a UTF-8 string from a unix charset string.
52 * The resulting UTF-8 string is talloc'ed.
54 * @param[in] ctx The talloc memory context.
56 * @param[in] dest A pointer to store the pointer to the talloc'ed UTF-8
59 * @param[in] src The unix charset string to convert.
61 * @param[in] converted_size A pointer to store the length of the talloc'ed
62 * UTF-8 string including the nul-termination bytes.
64 * The destination string should be free'd using talloc_free() if no longer
67 * @return True on success, false otherwise.
69 bool push_utf8_talloc(TALLOC_CTX
*ctx
, char **dest
, const char *src
,
70 size_t *converted_size
)
72 size_t src_len
= strlen(src
)+1;
75 return convert_string_talloc(ctx
, CH_UNIX
, CH_UTF8
, src
, src_len
,
76 (void**)dest
, converted_size
);
80 * Copy a string from a unix char* src to an ASCII destination,
81 * allocating a buffer using talloc().
83 * @param dest always set at least to NULL
85 * @param converted_size The number of bytes occupied by the string in the destination
86 * @returns boolean indicating if the conversion was successful
88 bool push_ascii_talloc(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
, size_t *converted_size
)
90 size_t src_len
= strlen(src
)+1;
93 return convert_string_talloc(mem_ctx
, CH_UNIX
, CH_DOS
, src
, src_len
,
94 (void **)dest
, converted_size
);
98 * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc
100 * @param dest always set at least to NULL
101 * @param converted_size set to the number of bytes occupied by the string in
102 * the destination on success.
104 * @return true if new buffer was correctly allocated, and string was
108 bool pull_ucs2_talloc(TALLOC_CTX
*ctx
, char **dest
, const smb_ucs2_t
*src
,
109 size_t *converted_size
)
111 size_t src_len
= (strlen_w(src
)+1) * sizeof(smb_ucs2_t
);
114 return convert_string_talloc(ctx
, CH_UTF16LE
, CH_UNIX
, src
, src_len
,
115 (void **)dest
, converted_size
);
120 * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc
122 * @param dest always set at least to NULL
123 * @param converted_size set to the number of bytes occupied by the string in
124 * the destination on success.
126 * @return true if new buffer was correctly allocated, and string was
130 bool pull_utf8_talloc(TALLOC_CTX
*ctx
, char **dest
, const char *src
,
131 size_t *converted_size
)
133 size_t src_len
= strlen(src
)+1;
136 return convert_string_talloc(ctx
, CH_UTF8
, CH_UNIX
, src
, src_len
,
137 (void **)dest
, converted_size
);
142 * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc
144 * @param dest always set at least to NULL
145 * @param converted_size set to the number of bytes occupied by the string in
146 * the destination on success.
148 * @return true if new buffer was correctly allocated, and string was
152 bool pull_ascii_talloc(TALLOC_CTX
*ctx
, char **dest
, const char *src
,
153 size_t *converted_size
)
155 size_t src_len
= strlen(src
)+1;
158 return convert_string_talloc(ctx
, CH_DOS
, CH_UNIX
, src
, src_len
,
159 (void **)dest
, converted_size
);