Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1998 - 2005 Pekka Riikonen
+ Copyright (C) 1998 - 2006 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
if (!sb)
return NULL;
- /* Allocate the actual data area */
- sb->head = (unsigned char *)silc_calloc(len, sizeof(*sb->head));
- if (!sb->head)
- return NULL;
+ if (len) {
+ /* Allocate the actual data area */
+ sb->head = (unsigned char *)silc_calloc(len, sizeof(*sb->head));
+ if (!sb->head)
+ return NULL;
- /* Set pointers to the new buffer */
- sb->data = sb->head;
- sb->tail = sb->head;
- sb->end = sb->head + len;
+ /* Set pointers to the new buffer */
+ sb->data = sb->head;
+ sb->tail = sb->head;
+ sb->end = sb->head + len;
+ }
return sb;
}
*
* Allocates new SilcBuffer and returns it.
*
- * This routine use SilcStack are memory source.
+ * This routine use SilcStack are memory source. If `stack' is NULL
+ * reverts back to normal allocating routine.
*
***/
{
SilcBuffer sb;
+ if (!stack)
+ return silc_buffer_alloc(len);
+
/* Allocate new SilcBuffer */
sb = (SilcBuffer)silc_scalloc(stack, 1, sizeof(*sb));
if (!sb)
* `len' bytes so that the buffer is ready to use without calling the
* silc_buffer_pull_tail.
*
- * This routine use SilcStack are memory source.
+ * This routine use SilcStack are memory source. If `stack' is NULL
+ * reverts back to normal allocating routine.
*
***/
* is exact clone of the old one except that there is now more space
* at the end of buffer.
*
- * This routine use SilcStack are memory source.
+ * This routine use SilcStack are memory source. If `stack' is NULL
+ * reverts back to normal allocating routine.
*
***/
SilcUInt32 hlen, dlen;
unsigned char *h;
+ if (!stack)
+ return silc_buffer_realloc(sb, newsize);
+
if (!sb)
return silc_buffer_salloc(stack, newsize);
* automatically so that the buffer is ready to use without calling the
* silc_buffer_pull_tail.
*
- * This routine use SilcStack are memory source.
+ * This routine use SilcStack are memory source. If `stack' is NULL
+ * reverts back to normal allocating routine.
*
***/
* currently valid data area, nothing more. Use silc_buffer_clone to
* copy entire buffer.
*
- * This routine use SilcStack are memory source.
+ * This routine use SilcStack are memory source. If `stack' is NULL
+ * reverts back to normal allocating routine.
*
***/
* everything from the source buffer. The result is exact clone of
* the original buffer.
*
- * This routine use SilcStack are memory source.
+ * This routine use SilcStack are memory source. If `stack' is NULL
+ * reverts back to normal allocating routine.
*
***/