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 write a string in unicoode format
26 ********************************************************************/
27 int PutUniCode(char *dst,char *src)
40 /*******************************************************************
41 skip past some unicode strings in a buffer
42 ********************************************************************/
43 char *skip_unicode_string(char *buf,int n)
54 /*******************************************************************
55 Return a ascii version of a unicode string
56 Hack alert: uses fixed buffer(s) and only handles ascii strings
57 ********************************************************************/
59 char *unistrn2(uint16 *buf, int len)
61 static char lbufs[8][MAXUNI];
63 char *lbuf = lbufs[nexti];
68 for (p = lbuf; *buf && p-lbuf < MAXUNI-2 && len > 0; len--, p++, buf++)
77 static char lbufs[8][MAXUNI];
79 /*******************************************************************
80 Return a ascii version of a unicode string
81 Hack alert: uses fixed buffer(s) and only handles ascii strings
82 ********************************************************************/
84 char *unistr2(uint16 *buf)
86 char *lbuf = lbufs[nexti];
91 for (p = lbuf; *buf && p-lbuf < MAXUNI-2; p++, buf++)
100 /*******************************************************************
101 Return a ascii version of a unicode string
102 ********************************************************************/
103 char *unistr2_to_str(UNISTR2 *str)
105 char *lbuf = lbufs[nexti];
107 uint16 *buf = str->buffer;
108 int max_size = MIN(sizeof(str->buffer)-2, str->uni_str_len);
112 for (p = lbuf; *buf && p-lbuf < max_size; p++, buf++)
121 /*******************************************************************
122 Return a number stored in a buffer
123 ********************************************************************/
124 uint32 buffer2_to_uint32(BUFFER2 *str)
126 if (str->buf_len == 4)
128 return IVAL(str->buffer, 0);
136 /*******************************************************************
137 Return a ascii version of a NOTunicode string
138 ********************************************************************/
139 char *buffer2_to_str(BUFFER2 *str)
141 char *lbuf = lbufs[nexti];
143 uint16 *buf = str->buffer;
144 int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2);
148 for (p = lbuf; *buf && p-lbuf < max_size; p++, buf++)
157 /*******************************************************************
158 Return a ascii version of a NOTunicode string
159 ********************************************************************/
160 char *buffer2_to_multistr(BUFFER2 *str)
162 char *lbuf = lbufs[nexti];
164 uint16 *buf = str->buffer;
165 int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2);
169 for (p = lbuf; p-lbuf < max_size; p++, buf++)
185 /*******************************************************************
186 create a null-terminated unicode string from a null-terminated ascii string.
187 return number of unicode chars copied, excluding the null character.
189 only handles ascii strings
190 ********************************************************************/
192 int struni2(uint16 *p, const char *buf)
196 if (p == NULL) return 0;
200 for (; *buf && len < MAXUNI-2; len++, p++, buf++)
211 /*******************************************************************
212 Return a ascii version of a unicode string
213 Hack alert: uses fixed buffer(s) and only handles ascii strings
214 ********************************************************************/
216 char *unistr(char *buf)
218 char *lbuf = lbufs[nexti];
223 for (p = lbuf; *buf && p-lbuf < MAXUNI-2; p++, buf += 2)
232 /*******************************************************************
233 strcpy for unicode strings. returns length (in num of wide chars)
234 ********************************************************************/
235 int unistrcpy(char *dst, char *src)