blob: de856d8fdd3f916e01d9813347c9c3c860e2f232 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
vlm80a48592005-02-25 12:10:27 +00002 * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
vlmfa67ddc2004-06-03 03:38:44 +00004 * Redistribution and modifications are permitted subject to BSD license.
5 */
vlm39ba4c42004-09-22 16:06:28 +00006#include <asn_internal.h>
vlmfa67ddc2004-06-03 03:38:44 +00007#include <INTEGER.h>
vlma4799a62004-10-21 11:21:25 +00008#include <asn_codecs_prim.h> /* Encoder and decoder of a primitive type */
vlmfa67ddc2004-06-03 03:38:44 +00009#include <assert.h>
10#include <errno.h>
11
12/*
13 * INTEGER basic type description.
14 */
vlmef6355b2004-09-29 13:26:15 +000015static ber_tlv_tag_t asn_DEF_INTEGER_tags[] = {
vlmfa67ddc2004-06-03 03:38:44 +000016 (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
17};
vlmef6355b2004-09-29 13:26:15 +000018asn_TYPE_descriptor_t asn_DEF_INTEGER = {
vlmfa67ddc2004-06-03 03:38:44 +000019 "INTEGER",
vlm9de248e2004-10-20 15:50:55 +000020 "INTEGER",
vlm6678cb12004-09-26 13:10:40 +000021 ASN__PRIMITIVE_TYPE_free,
vlm39ba4c42004-09-22 16:06:28 +000022 INTEGER_print,
vlmfa67ddc2004-06-03 03:38:44 +000023 asn_generic_no_constraint,
vlm6678cb12004-09-26 13:10:40 +000024 ber_decode_primitive,
vlmfa67ddc2004-06-03 03:38:44 +000025 INTEGER_encode_der,
vlma4799a62004-10-21 11:21:25 +000026 INTEGER_decode_xer,
vlm39ba4c42004-09-22 16:06:28 +000027 INTEGER_encode_xer,
vlmfa67ddc2004-06-03 03:38:44 +000028 0, /* Use generic outmost tag fetcher */
vlmef6355b2004-09-29 13:26:15 +000029 asn_DEF_INTEGER_tags,
30 sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]),
31 asn_DEF_INTEGER_tags, /* Same as above */
32 sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]),
vlme413c122004-08-20 13:23:42 +000033 0, 0, /* No members */
vlmb42843a2004-06-05 08:17:50 +000034 0 /* No specifics */
vlmfa67ddc2004-06-03 03:38:44 +000035};
36
37/*
vlmfa67ddc2004-06-03 03:38:44 +000038 * Encode INTEGER type using DER.
39 */
vlm39ba4c42004-09-22 16:06:28 +000040asn_enc_rval_t
vlmef6355b2004-09-29 13:26:15 +000041INTEGER_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
vlmfa67ddc2004-06-03 03:38:44 +000042 int tag_mode, ber_tlv_tag_t tag,
43 asn_app_consume_bytes_f *cb, void *app_key) {
vlm6678cb12004-09-26 13:10:40 +000044 INTEGER_t *st = (INTEGER_t *)sptr;
vlmfa67ddc2004-06-03 03:38:44 +000045
46 ASN_DEBUG("%s %s as INTEGER (tm=%d)",
vlm6678cb12004-09-26 13:10:40 +000047 cb?"Encoding":"Estimating", td->name, tag_mode);
vlmfa67ddc2004-06-03 03:38:44 +000048
49 /*
50 * Canonicalize integer in the buffer.
51 * (Remove too long sign extension, remove some first 0x00 bytes)
52 */
53 if(st->buf) {
54 uint8_t *buf = st->buf;
55 uint8_t *end1 = buf + st->size - 1;
56 int shift;
57
58 /* Compute the number of superfluous leading bytes */
59 for(; buf < end1; buf++) {
60 /*
61 * If the contents octets of an integer value encoding
62 * consist of more than one octet, then the bits of the
63 * first octet and bit 8 of the second octet:
64 * a) shall not all be ones; and
65 * b) shall not all be zero.
66 */
67 switch(*buf) {
68 case 0x00: if((buf[1] & 0x80) == 0)
69 continue;
70 break;
71 case 0xff: if((buf[1] & 0x80))
72 continue;
73 break;
74 }
75 break;
76 }
77
78 /* Remove leading superfluous bytes from the integer */
79 shift = buf - st->buf;
80 if(shift) {
81 uint8_t *nb = st->buf;
82 uint8_t *end;
83
84 st->size -= shift; /* New size, minus bad bytes */
85 end = nb + st->size;
86
87 for(; nb < end; nb++, buf++)
88 *nb = *buf;
89 }
90
91 } /* if(1) */
92
vlm6678cb12004-09-26 13:10:40 +000093 return der_encode_primitive(td, sptr, tag_mode, tag, cb, app_key);
vlmfa67ddc2004-06-03 03:38:44 +000094}
95
vlm80a48592005-02-25 12:10:27 +000096static const asn_INTEGER_enum_map_t *INTEGER__map_value2enum(asn_INTEGER_specifics_t *specs, long value);
97static const asn_INTEGER_enum_map_t *INTEGER__map_enum2value(asn_INTEGER_specifics_t *specs, const char *lstart, const char *lstop);
98
vlmfa67ddc2004-06-03 03:38:44 +000099/*
100 * INTEGER specific human-readable output.
101 */
vlm39ba4c42004-09-22 16:06:28 +0000102static ssize_t
vlm80a48592005-02-25 12:10:27 +0000103INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_bytes_f *cb, void *app_key, int plainOrXER) {
104 asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
vlm7d278c42004-07-19 17:30:25 +0000105 char scratch[32]; /* Enough for 64-bit integer */
vlmfa67ddc2004-06-03 03:38:44 +0000106 uint8_t *buf = st->buf;
107 uint8_t *buf_end = st->buf + st->size;
108 signed long accum;
vlm39ba4c42004-09-22 16:06:28 +0000109 ssize_t wrote = 0;
vlmfa67ddc2004-06-03 03:38:44 +0000110 char *p;
111 int ret;
112
vlm7d278c42004-07-19 17:30:25 +0000113 /*
114 * Advance buf pointer until the start of the value's body.
115 * This will make us able to process large integers using simple case,
116 * when the actual value is small
117 * (0x0000000000abcdef would yield a fine 0x00abcdef)
118 */
119 /* Skip the insignificant leading bytes */
120 for(; buf < buf_end-1; buf++) {
121 switch(*buf) {
122 case 0x00: if((buf[1] & 0x80) == 0) continue; break;
123 case 0xff: if((buf[1] & 0x80) != 0) continue; break;
124 }
125 break;
126 }
127
vlmfa67ddc2004-06-03 03:38:44 +0000128 /* Simple case: the integer size is small */
vlm7d278c42004-07-19 17:30:25 +0000129 if((size_t)(buf_end - buf) <= sizeof(accum)) {
vlm80a48592005-02-25 12:10:27 +0000130 const asn_INTEGER_enum_map_t *el;
131 size_t scrsize;
132 char *scr;
133
134 if(buf == buf_end) {
135 accum = 0;
136 } else {
137 accum = (*buf & 0x80) ? -1 : 0;
138 for(; buf < buf_end; buf++)
139 accum = (accum << 8) | *buf;
140 }
141
142 el = INTEGER__map_value2enum(specs, accum);
143 if(el) {
144 scrsize = el->enum_len + 32;
145 scr = (char *)alloca(scrsize);
146 if(plainOrXER == 0)
147 ret = snprintf(scr, scrsize,
148 "%ld (%s)", accum, el->enum_name);
149 else
150 ret = snprintf(scr, scrsize,
151 "<%s/>", el->enum_name);
152 } else if(plainOrXER && specs && specs->strict_enumeration) {
153 ASN_DEBUG("ASN.1 forbids dealing with "
154 "unknown value of ENUMERATED type");
155 errno = EPERM;
156 return -1;
157 } else {
158 scrsize = sizeof(scratch);
159 scr = scratch;
160 ret = snprintf(scr, scrsize, "%ld", accum);
161 }
162 assert(ret > 0 && (size_t)ret < scrsize);
163 return (cb(scr, ret, app_key) < 0) ? -1 : ret;
164 } else if(plainOrXER && specs && specs->strict_enumeration) {
165 /*
166 * Here and earlier, we cannot encode the ENUMERATED values
167 * if there is no corresponding identifier.
168 */
169 ASN_DEBUG("ASN.1 forbids dealing with "
170 "unknown value of ENUMERATED type");
171 errno = EPERM;
172 return -1;
vlmfa67ddc2004-06-03 03:38:44 +0000173 }
174
175 /* Output in the long xx:yy:zz... format */
vlm7d278c42004-07-19 17:30:25 +0000176 /* TODO: replace with generic algorithm (Knuth TAOCP Vol 2, 4.3.1) */
vlmfa67ddc2004-06-03 03:38:44 +0000177 for(p = scratch; buf < buf_end; buf++) {
vlm1ff928d2004-08-11 08:10:13 +0000178 static const char *h2c = "0123456789ABCDEF";
vlm7d278c42004-07-19 17:30:25 +0000179 if((p - scratch) >= (ssize_t)(sizeof(scratch) - 4)) {
vlmfa67ddc2004-06-03 03:38:44 +0000180 /* Flush buffer */
vlm39ba4c42004-09-22 16:06:28 +0000181 if(cb(scratch, p - scratch, app_key) < 0)
vlmfa67ddc2004-06-03 03:38:44 +0000182 return -1;
vlm39ba4c42004-09-22 16:06:28 +0000183 wrote += p - scratch;
vlmfa67ddc2004-06-03 03:38:44 +0000184 p = scratch;
185 }
186 *p++ = h2c[*buf >> 4];
187 *p++ = h2c[*buf & 0x0F];
vlmef6355b2004-09-29 13:26:15 +0000188 *p++ = 0x3a; /* ":" */
vlmfa67ddc2004-06-03 03:38:44 +0000189 }
vlm7d278c42004-07-19 17:30:25 +0000190 if(p != scratch)
vlmef6355b2004-09-29 13:26:15 +0000191 p--; /* Remove the last ":" */
vlmfa67ddc2004-06-03 03:38:44 +0000192
vlm39ba4c42004-09-22 16:06:28 +0000193 wrote += p - scratch;
194 return (cb(scratch, p - scratch, app_key) < 0) ? -1 : wrote;
195}
196
197/*
198 * INTEGER specific human-readable output.
199 */
200int
vlmef6355b2004-09-29 13:26:15 +0000201INTEGER_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
vlm39ba4c42004-09-22 16:06:28 +0000202 asn_app_consume_bytes_f *cb, void *app_key) {
203 const INTEGER_t *st = (const INTEGER_t *)sptr;
vlm6678cb12004-09-26 13:10:40 +0000204 ssize_t ret;
vlm39ba4c42004-09-22 16:06:28 +0000205
206 (void)td;
207 (void)ilevel;
208
vlm6678cb12004-09-26 13:10:40 +0000209 if(!st && !st->buf)
210 ret = cb("<absent>", 8, app_key);
211 else
vlm80a48592005-02-25 12:10:27 +0000212 ret = INTEGER__dump(td, st, cb, app_key, 0);
vlm39ba4c42004-09-22 16:06:28 +0000213
vlm6678cb12004-09-26 13:10:40 +0000214 return (ret < 0) ? -1 : 0;
vlm39ba4c42004-09-22 16:06:28 +0000215}
216
vlm80a48592005-02-25 12:10:27 +0000217struct e2v_key {
218 const char *start;
219 const char *stop;
220 asn_INTEGER_enum_map_t *vemap;
221 unsigned int *evmap;
222};
223static int
224INTEGER__compar_enum2value(const void *kp, const void *am) {
225 const struct e2v_key *key = (const struct e2v_key *)kp;
226 const asn_INTEGER_enum_map_t *el = (const asn_INTEGER_enum_map_t *)am;
227 const char *ptr, *end, *name;
228
229 /* Remap the element (sort by different criterion) */
230 el = key->vemap + key->evmap[el - key->vemap];
231
232 /* Compare strings */
233 for(ptr = key->start, end = key->stop, name = el->enum_name;
234 ptr < end; ptr++, name++) {
235 if(*ptr != *name)
236 return *(const unsigned char *)ptr
237 - *(const unsigned char *)name;
238 }
239 return name[0] ? -1 : 0;
240}
241
242static const asn_INTEGER_enum_map_t *
243INTEGER__map_enum2value(asn_INTEGER_specifics_t *specs, const char *lstart, const char *lstop) {
244 int count = specs ? specs->map_count : 0;
245 struct e2v_key key;
246 const char *lp;
247
248 if(!count) return NULL;
249
250 /* Guaranteed: assert(lstart < lstop); */
251 /* Figure out the tag name */
252 for(lstart++, lp = lstart; lp < lstop; lp++) {
253 switch(*lp) {
254 case 9: case 10: case 11: case 12: case 13: case 32: /* WSP */
255 case 0x2f: /* '/' */ case 0x3e: /* '>' */
256 break;
257 default:
258 continue;
259 }
260 break;
261 }
262 if(lp == lstop) return NULL; /* No tag found */
263 lstop = lp;
264
265 key.start = lstart;
266 key.stop = lstop;
267 key.vemap = specs->value2enum;
268 key.evmap = specs->enum2value;
269 return (asn_INTEGER_enum_map_t *)bsearch(&key, specs->value2enum, count,
270 sizeof(specs->value2enum[0]), INTEGER__compar_enum2value);
271}
272
273static int
274INTEGER__compar_value2enum(const void *kp, const void *am) {
275 long a = *(const long *)kp;
276 const asn_INTEGER_enum_map_t *el = (const asn_INTEGER_enum_map_t *)am;
277 long b = el->nat_value;
278 if(a < b) return -1;
279 else if(a == b) return 0;
280 else return 1;
281}
282
283static const asn_INTEGER_enum_map_t *
284INTEGER__map_value2enum(asn_INTEGER_specifics_t *specs, long value) {
285 int count = specs ? specs->map_count : 0;
286 if(!count) return 0;
287 return (asn_INTEGER_enum_map_t *)bsearch(&value, specs->value2enum,
288 count, sizeof(specs->value2enum[0]),
289 INTEGER__compar_value2enum);
290}
291
vlma4799a62004-10-21 11:21:25 +0000292/*
293 * Decode the chunk of XML text encoding INTEGER.
294 */
295static ssize_t
vlm80a48592005-02-25 12:10:27 +0000296INTEGER__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, void *chunk_buf, size_t chunk_size) {
vlmb848b2a2004-10-21 14:02:19 +0000297 INTEGER_t *st = (INTEGER_t *)sptr;
vlma4799a62004-10-21 11:21:25 +0000298 long sign = 1;
299 long value;
vlm80a48592005-02-25 12:10:27 +0000300 const char *lp;
301 const char *lstart = (const char *)chunk_buf;
302 const char *lstop = lstart + chunk_size;
vlma4799a62004-10-21 11:21:25 +0000303 enum {
304 ST_SKIPSPACE,
305 ST_WAITDIGITS,
306 ST_DIGITS,
307 } state = ST_SKIPSPACE;
vlme4f9cac2004-10-21 12:11:57 +0000308
vlma4799a62004-10-21 11:21:25 +0000309 /*
vlm80a48592005-02-25 12:10:27 +0000310 * We may have received a tag here. It will be processed inline.
311 * Use strtoul()-like code and serialize the result.
vlma4799a62004-10-21 11:21:25 +0000312 */
vlme4f9cac2004-10-21 12:11:57 +0000313 for(value = 0, lp = lstart; lp < lstop; lp++) {
314 int lv = *lp;
vlma4799a62004-10-21 11:21:25 +0000315 switch(lv) {
316 case 0x09: case 0x0a: case 0x0d: case 0x20:
317 if(state == ST_SKIPSPACE) continue;
318 break;
319 case 0x2d: /* '-' */
320 if(state == ST_SKIPSPACE) {
321 sign = -1;
322 state = ST_WAITDIGITS;
323 continue;
324 }
325 break;
326 case 0x2b: /* '+' */
327 if(state == ST_SKIPSPACE) {
328 state = ST_WAITDIGITS;
329 continue;
330 }
331 break;
332 case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
333 case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
334 if(state != ST_DIGITS) state = ST_DIGITS;
335
vlme4f9cac2004-10-21 12:11:57 +0000336 {
337 long new_value = value * 10;
338
339 if(new_value / 10 != value)
340 /* Overflow */
341 return -1;
342
343 value = new_value + (lv - 0x30);
vlma4799a62004-10-21 11:21:25 +0000344 /* Check for two's complement overflow */
345 if(value < 0) {
346 /* Check whether it is a LONG_MIN */
347 if(sign == -1
vlmb848b2a2004-10-21 14:02:19 +0000348 && (unsigned long)value
349 == ~((unsigned long)-1 >> 1)) {
vlme4f9cac2004-10-21 12:11:57 +0000350 sign = 1;
vlma4799a62004-10-21 11:21:25 +0000351 } else {
352 /* Overflow */
353 return -1;
354 }
355 }
vlme4f9cac2004-10-21 12:11:57 +0000356 }
vlma4799a62004-10-21 11:21:25 +0000357 continue;
vlm80a48592005-02-25 12:10:27 +0000358 case 0x3c: /* '<' */
359 if(state == ST_SKIPSPACE) {
360 const asn_INTEGER_enum_map_t *el;
361 el = INTEGER__map_enum2value(
362 (asn_INTEGER_specifics_t *)
363 td->specifics, lstart, lstop);
364 if(el) {
365 ASN_DEBUG("Found \"%s\" => %ld",
366 el->enum_name, el->nat_value);
367 state = ST_DIGITS;
368 value = el->nat_value;
369 break;
370 }
371 ASN_DEBUG("Unknown identifier for INTEGER");
372 }
373 return -1;
vlma4799a62004-10-21 11:21:25 +0000374 }
vlme4f9cac2004-10-21 12:11:57 +0000375 break;
vlma4799a62004-10-21 11:21:25 +0000376 }
377
378 if(state != ST_DIGITS)
379 return -1; /* No digits */
380
381 value *= sign; /* Change sign, if needed */
382
383 if(asn_long2INTEGER(st, value))
384 return -1;
385
vlme4f9cac2004-10-21 12:11:57 +0000386 return lp - lstart;
vlma4799a62004-10-21 11:21:25 +0000387}
388
389asn_dec_rval_t
390INTEGER_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
391 asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
392 void *buf_ptr, size_t size) {
393
394 return xer_decode_primitive(opt_codec_ctx, td,
vlmb848b2a2004-10-21 14:02:19 +0000395 sptr, sizeof(INTEGER_t), opt_mname,
vlma4799a62004-10-21 11:21:25 +0000396 buf_ptr, size, INTEGER__xer_body_decode);
397}
398
vlm39ba4c42004-09-22 16:06:28 +0000399asn_enc_rval_t
vlmef6355b2004-09-29 13:26:15 +0000400INTEGER_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
vlm39ba4c42004-09-22 16:06:28 +0000401 int ilevel, enum xer_encoder_flags_e flags,
402 asn_app_consume_bytes_f *cb, void *app_key) {
403 const INTEGER_t *st = (const INTEGER_t *)sptr;
404 asn_enc_rval_t er;
405
406 (void)ilevel;
407 (void)flags;
408
409 if(!st && !st->buf)
410 _ASN_ENCODE_FAILED;
411
vlm80a48592005-02-25 12:10:27 +0000412 er.encoded = INTEGER__dump(td, st, cb, app_key, 1);
vlm39ba4c42004-09-22 16:06:28 +0000413 if(er.encoded < 0) _ASN_ENCODE_FAILED;
414
415 return er;
vlmfa67ddc2004-06-03 03:38:44 +0000416}
417
vlmfa67ddc2004-06-03 03:38:44 +0000418int
vlmef6355b2004-09-29 13:26:15 +0000419asn_INTEGER2long(const INTEGER_t *iptr, long *lptr) {
vlmfa67ddc2004-06-03 03:38:44 +0000420 uint8_t *b, *end;
421 size_t size;
422 long l;
423
424 /* Sanity checking */
425 if(!iptr || !iptr->buf || !lptr) {
426 errno = EINVAL;
427 return -1;
428 }
429
430 /* Cache the begin/end of the buffer */
431 b = iptr->buf; /* Start of the INTEGER buffer */
432 size = iptr->size;
433 end = b + size; /* Where to stop */
434
435 if(size > sizeof(long)) {
436 uint8_t *end1 = end - 1;
437 /*
438 * Slightly more advanced processing,
439 * able to >sizeof(long) bytes,
440 * when the actual value is small
441 * (0x0000000000abcdef would yield a fine 0x00abcdef)
442 */
443 /* Skip out the insignificant leading bytes */
444 for(; b < end1; b++) {
445 switch(*b) {
446 case 0x00: if((b[1] & 0x80) == 0) continue; break;
447 case 0xff: if((b[1] & 0x80) != 0) continue; break;
448 }
449 break;
450 }
451
452 size = end - b;
453 if(size > sizeof(long)) {
454 /* Still cannot fit the long */
455 errno = ERANGE;
456 return -1;
457 }
458 }
459
460 /* Shortcut processing of a corner case */
461 if(end == b) {
462 *lptr = 0;
463 return 0;
464 }
465
466 /* Perform the sign initialization */
467 /* Actually l = -(*b >> 7); gains nothing, yet unreadable! */
468 if((*b >> 7)) l = -1; else l = 0;
469
470 /* Conversion engine */
471 for(; b < end; b++)
472 l = (l << 8) | *b;
473
474 *lptr = l;
475 return 0;
476}
vlma4799a62004-10-21 11:21:25 +0000477
478int
479asn_long2INTEGER(INTEGER_t *st, long value) {
480 uint8_t *buf, *bp;
481 uint8_t *p;
482 uint8_t *pstart;
483 uint8_t *pend1;
vlm96a4e462004-10-26 08:20:46 +0000484 int littleEndian = 1; /* Run-time detection */
485 int add;
vlma4799a62004-10-21 11:21:25 +0000486
487 if(!st) {
488 errno = EINVAL;
489 return -1;
490 }
491
vlmb848b2a2004-10-21 14:02:19 +0000492 buf = (uint8_t *)MALLOC(sizeof(value));
vlma4799a62004-10-21 11:21:25 +0000493 if(!buf) return -1;
494
vlm96a4e462004-10-26 08:20:46 +0000495 if(*(char *)&littleEndian) {
496 pstart = (uint8_t *)&value + sizeof(value) - 1;
497 pend1 = (uint8_t *)&value;
498 add = -1;
499 } else {
500 pstart = (uint8_t *)&value;
501 pend1 = pstart + sizeof(value) - 1;
502 add = 1;
503 }
504
vlma4799a62004-10-21 11:21:25 +0000505 /*
506 * If the contents octet consists of more than one octet,
507 * then bits of the first octet and bit 8 of the second octet:
508 * a) shall not all be ones; and
509 * b) shall not all be zero.
510 */
vlm6c593842004-10-26 09:03:31 +0000511 for(p = pstart; p != pend1; p += add) {
vlma4799a62004-10-21 11:21:25 +0000512 switch(*p) {
vlm6c593842004-10-26 09:03:31 +0000513 case 0x00: if((*(p+add) & 0x80) == 0)
vlma4799a62004-10-21 11:21:25 +0000514 continue;
515 break;
vlm6c593842004-10-26 09:03:31 +0000516 case 0xff: if((*(p+add) & 0x80))
vlma4799a62004-10-21 11:21:25 +0000517 continue;
518 break;
519 }
520 break;
521 }
522 /* Copy the integer body */
vlm6c593842004-10-26 09:03:31 +0000523 for(pstart = p, bp = buf, pend1 += add; p != pend1; p += add)
524 *bp++ = *p;
vlma4799a62004-10-21 11:21:25 +0000525
526 if(st->buf) FREEMEM(st->buf);
527 st->buf = buf;
vlm6c593842004-10-26 09:03:31 +0000528 st->size = bp - buf;
vlma4799a62004-10-21 11:21:25 +0000529
530 return 0;
531}