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 ********************************************************************/
54 const char *unibuf_to_ascii(char *dest, const char *src, int maxlen)
56 char *destend = dest + maxlen;
59 while (dest < destend)
62 if ((c == 0) && (*src == 0))
77 /*******************************************************************
78 Put an ASCII string into a UNICODE array (uint16's).
79 ********************************************************************/
81 void ascii_to_unistr(uint16 *dest, const char *src, int maxlen)
83 uint16 *destend = dest + maxlen;
86 while (dest < destend)
94 *(dest++) = (uint16)c;
101 /*******************************************************************
102 Pull an ASCII string out of a UNICODE array (uint16's).
103 ********************************************************************/
105 void unistr_to_ascii(char *dest, const uint16 *src, int len)
107 char *destend = dest + len;
110 while (dest < destend)
125 /*******************************************************************
126 Convert a UNISTR2 structure to an ASCII string
127 ********************************************************************/
129 void unistr2_to_ascii(char *dest, const UNISTR2 *str, int maxlen)
137 len = MIN(str->uni_str_len, maxlen);
138 destend = dest + len;
140 while (dest < destend)
155 /*******************************************************************
156 Skip a UNICODE string in a little endian buffer.
157 ********************************************************************/
159 char *skip_unibuf(char *srcbuf, int len)
161 uint16 *src = (uint16 *)srcbuf;
162 uint16 *srcend = src + len/2;
164 while ((src < srcend) && (*(src++) != 0))
172 /*******************************************************************
173 UNICODE strcpy between buffers.
174 ********************************************************************/
176 char *uni_strncpy(char *destbuf, const char *srcbuf, int len)
178 const uint16 *src = (const uint16 *)srcbuf;
179 uint16 *dest = (uint16 *)destbuf;
180 uint16 *destend = dest + len/2;
183 while (dest < destend)
199 /*******************************************************************
200 Return a number stored in a buffer
201 ********************************************************************/
203 uint32 buffer2_to_uint32(const BUFFER2 *str)
205 if (str->buf_len == 4)
207 const char *src = str->buffer;
217 /*******************************************************************
218 Convert a 'multi-string' buffer to space-separated ASCII.
219 ********************************************************************/
221 void buffer2_to_multistr(char *dest, const BUFFER2 *str, int maxlen)
229 len = MIN(str->buf_len/2, maxlen);
230 destend = dest + len;
232 while (dest < destend)
235 *(dest++) = (c == 0) ? ' ' : (char)c;