2 Unix SMB/Netbios implementation.
4 Samba utility functions
5 Copyright (C) Andrew Tridgell 1992-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 /*******************************************************************
25 Put an ASCII string into a UNICODE buffer (little endian).
26 ********************************************************************/
28 char *ascii_to_unibuf(char *dest, const char *src, int maxlen)
30 char *destend = dest + maxlen;
33 while (dest < destend)
51 /*******************************************************************
52 Pull an ASCII string out of a UNICODE buffer (little endian).
53 ********************************************************************/
55 void unibuf_to_ascii(char *dest, const char *src, int maxlen)
57 char *destend = dest + maxlen;
60 while (dest < destend)
63 if ((c == 0) && (*src == 0))
76 /*******************************************************************
77 Put an ASCII string into a UNICODE array (uint16's).
78 ********************************************************************/
80 void ascii_to_unistr(uint16 *dest, const char *src, int maxlen)
82 uint16 *destend = dest + maxlen;
85 while (dest < destend)
93 *(dest++) = (uint16)c;
100 /*******************************************************************
101 Pull an ASCII string out of a UNICODE array (uint16's).
102 ********************************************************************/
104 void unistr_to_ascii(char *dest, const uint16 *src, int len)
106 char *destend = dest + len;
109 while (dest < destend)
124 /*******************************************************************
125 Convert a UNISTR2 structure to an ASCII string
126 ********************************************************************/
128 void unistr2_to_ascii(char *dest, const UNISTR2 *str, int maxlen)
136 len = MIN(str->uni_str_len, maxlen);
137 destend = dest + len;
139 while (dest < destend)
154 /*******************************************************************
155 Skip a UNICODE string in a little endian buffer.
156 ********************************************************************/
158 char *skip_unibuf(char *srcbuf, int len)
160 uint16 *src = (uint16 *)srcbuf;
161 uint16 *srcend = src + len/2;
163 while ((src < srcend) && (*(src++) != 0))
171 /*******************************************************************
172 UNICODE strcpy between buffers.
173 ********************************************************************/
175 char *uni_strncpy(char *destbuf, const char *srcbuf, int len)
177 const uint16 *src = (const uint16 *)srcbuf;
178 uint16 *dest = (uint16 *)destbuf;
179 uint16 *destend = dest + len/2;
182 while (dest < destend)
198 /*******************************************************************
199 Return a number stored in a buffer
200 ********************************************************************/
202 uint32 buffer2_to_uint32(const BUFFER2 *str)
204 if (str->buf_len == 4)
206 const char *src = str->buffer;
216 /*******************************************************************
217 Convert a 'multi-string' buffer to space-separated ASCII.
218 ********************************************************************/
220 void buffer2_to_multistr(char *dest, const BUFFER2 *str, int maxlen)
228 len = MIN(str->buf_len/2, maxlen);
229 destend = dest + len;
231 while (dest < destend)
234 *(dest++) = (c == 0) ? ' ' : (char)c;