comparison libpurple/protocols/oscar/bstream.c @ 27590:a08e84032814

merge of '2348ff22f0ff3453774b8b25b36238465580c609' and 'e76f11543c2a4aa05bdf584f087cbe3439029661'
author Paul Aurich <paul@darkrain42.org>
date Sun, 12 Jul 2009 05:43:38 +0000
parents 7f43d6779764
children bbb27d65681f
comparison
equal deleted inserted replaced
27104:048bcf41deef 27590:a08e84032814
159 bs->offset += 4; 159 bs->offset += 4;
160 160
161 return aimutil_getle32(bs->data + bs->offset - 4); 161 return aimutil_getle32(bs->data + bs->offset - 4);
162 } 162 }
163 163
164 int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, int len) 164 static void byte_stream_getrawbuf_nocheck(ByteStream *bs, guint8 *buf, int len)
165 { 165 {
166
167 if (byte_stream_empty(bs) < len)
168 return 0;
169
170 memcpy(buf, bs->data + bs->offset, len); 166 memcpy(buf, bs->data + bs->offset, len);
171 bs->offset += len; 167 bs->offset += len;
172 168 }
169
170 int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, int len)
171 {
172
173 if (byte_stream_empty(bs) < len)
174 return 0;
175
176 byte_stream_getrawbuf_nocheck(bs, buf, len);
173 return len; 177 return len;
174 } 178 }
175 179
176 guint8 *byte_stream_getraw(ByteStream *bs, int len) 180 guint8 *byte_stream_getraw(ByteStream *bs, int len)
177 { 181 {
178 guint8 *ob; 182 guint8 *ob;
179 183
184 if (byte_stream_empty(bs) < len)
185 return NULL;
186
180 ob = g_malloc(len); 187 ob = g_malloc(len);
181 188
182 if (byte_stream_getrawbuf(bs, ob, len) < len) { 189 byte_stream_getrawbuf_nocheck(bs, ob, len);
183 g_free(ob); 190
191 return ob;
192 }
193
194 char *byte_stream_getstr(ByteStream *bs, int len)
195 {
196 char *ob;
197
198 if (byte_stream_empty(bs) < len)
184 return NULL; 199 return NULL;
185 }
186
187 return ob;
188 }
189
190 char *byte_stream_getstr(ByteStream *bs, int len)
191 {
192 char *ob;
193 200
194 ob = g_malloc(len + 1); 201 ob = g_malloc(len + 1);
195 202
196 if (byte_stream_getrawbuf(bs, (guint8 *)ob, len) < len) { 203 byte_stream_getrawbuf_nocheck(bs, (guint8 *)ob, len);
197 g_free(ob);
198 return NULL;
199 }
200 204
201 ob[len] = '\0'; 205 ob[len] = '\0';
202 206
203 return ob; 207 return ob;
204 } 208 }