comparison th_datastruct.c @ 464:761724e01c02

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 10 May 2018 17:15:36 +0300
parents 85fa3d333556
children e4ce60239d16
comparison
equal deleted inserted replaced
463:b5cd85983039 464:761724e01c02
413 if (buf->allocated) 413 if (buf->allocated)
414 th_free(buf); 414 th_free(buf);
415 } 415 }
416 416
417 417
418 BOOL th_growbuf_grow(th_growbuf_t *buf, const size_t grow) 418 BOOL th_growbuf_grow(th_growbuf_t *buf, const size_t amount)
419 { 419 {
420 if (buf == NULL) 420 if (buf == NULL)
421 return FALSE; 421 return FALSE;
422 422
423 if (buf->data == NULL || buf->len + grow >= buf->size) 423 if (buf->data == NULL || buf->len + amount >= buf->size)
424 { 424 {
425 buf->size += grow + (buf->mingrow > 0 ? buf->mingrow : TH_BUFGROW); 425 buf->size += amount + (buf->mingrow > 0 ? buf->mingrow : TH_BUFGROW);
426 buf->data = (uint8_t *) th_realloc(buf->data, buf->size); 426 if ((buf->data = th_realloc(buf->data, buf->size)) == NULL)
427 if (buf->data == NULL)
428 return FALSE; 427 return FALSE;
429 } 428 }
430 return TRUE; 429 return TRUE;
431 } 430 }
432 431
457 456
458 return TRUE; 457 return TRUE;
459 } 458 }
460 459
461 460
462 BOOL th_growbuf_put_str(th_growbuf_t *buf, const void *s, const size_t len) 461 BOOL th_growbuf_put_str(th_growbuf_t *buf, const void *str, const size_t len)
463 { 462 {
464 if (s == NULL) 463 if (str == NULL)
465 return FALSE; 464 return FALSE;
466 465
467 if (!th_growbuf_grow(buf, len + 1)) 466 if (!th_growbuf_grow(buf, len + 1))
468 return FALSE; 467 return FALSE;
469 468
470 memcpy(buf->data + buf->len, s, len + 1); 469 memcpy(buf->data + buf->len, str, len + 1);
471 buf->len += len; 470 buf->len += len;
472 471
473 return TRUE; 472 return TRUE;
474 } 473 }
475 474