s3: Fix some nonempty line endings
[Samba/gebeck_regimport.git] / lib / util / charset / pull_push.c
blobb7a5bcdc65b83d50d007b533bfa86330fd2ad8ca
1 /*
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/>.
24 #include "includes.h"
25 #include "system/locale.h"
27 /**
28 * Copy a string from a unix char* src to a UCS2 destination,
29 * allocating a buffer using talloc().
31 * @param dest always set at least to NULL
32 * @parm converted_size set to the number of bytes occupied by the string in
33 * the destination on success.
35 * @return true if new buffer was correctly allocated, and string was
36 * converted.
37 **/
38 bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src,
39 size_t *converted_size)
41 size_t src_len = strlen(src)+1;
43 *dest = NULL;
44 return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len,
45 (void **)dest, converted_size);
48 /**
49 * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc
51 * @param dest always set at least to NULL
52 * @parm converted_size set to the number of bytes occupied by the string in
53 * the destination on success.
55 * @return true if new buffer was correctly allocated, and string was
56 * converted.
57 **/
59 bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
60 size_t *converted_size)
62 size_t src_len = strlen(src)+1;
64 *dest = NULL;
65 return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len,
66 (void**)dest, converted_size);
69 /**
70 * Copy a string from a unix char* src to an ASCII destination,
71 * allocating a buffer using talloc().
73 * @param dest always set at least to NULL
75 * @param converted_size The number of bytes occupied by the string in the destination
76 * @returns boolean indicating if the conversion was successful
77 **/
78 bool push_ascii_talloc(TALLOC_CTX *mem_ctx, char **dest, const char *src, size_t *converted_size)
80 size_t src_len = strlen(src)+1;
82 *dest = NULL;
83 return convert_string_talloc(mem_ctx, CH_UNIX, CH_DOS, src, src_len,
84 (void **)dest, converted_size);
87 /**
88 * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc
90 * @param dest always set at least to NULL
91 * @parm converted_size set to the number of bytes occupied by the string in
92 * the destination on success.
94 * @return true if new buffer was correctly allocated, and string was
95 * converted.
96 **/
98 bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src,
99 size_t *converted_size)
101 size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
103 *dest = NULL;
104 return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len,
105 (void **)dest, converted_size);
110 * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc
112 * @param dest always set at least to NULL
113 * @parm converted_size set to the number of bytes occupied by the string in
114 * the destination on success.
116 * @return true if new buffer was correctly allocated, and string was
117 * converted.
120 bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
121 size_t *converted_size)
123 size_t src_len = strlen(src)+1;
125 *dest = NULL;
126 return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len,
127 (void **)dest, converted_size);
132 * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc
134 * @param dest always set at least to NULL
135 * @parm converted_size set to the number of bytes occupied by the string in
136 * the destination on success.
138 * @return true if new buffer was correctly allocated, and string was
139 * converted.
142 bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
143 size_t *converted_size)
145 size_t src_len = strlen(src)+1;
147 *dest = NULL;
148 return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len,
149 (void **)dest, converted_size);