Logo Search packages:      
Sourcecode: bglibs version File versions

int str_alloc ( str s,
unsigned  size,
int  copy 

Allocate storage for a string.

s String to modify.
size Minimum number of bytes for which to allocate.
copy If set, the existing string will be copied into the new string.
The size given is incremented to account for adding a trailing NUL byte (to ensure compatibility with C string functions) and is then rounded up to the nearest STR_BLOCKSIZE interval.

Definition at line 32 of file alloc.c.

References len, s, size, and STR_BLOCKSIZE.

  char* news;
  unsigned newsize;
  if ((newsize = size + 1) < size) return 0;
  if (newsize >= s->size) {
    newsize += newsize/8 + STR_BLOCKSIZE-1;
    newsize -= newsize % STR_BLOCKSIZE;
    if (newsize <= size) return 0;
    if ((news = malloc(newsize)) == 0) return 0;
    if (s->s) {
      if (copy) memcpy(news, s->s, s->len+1);
    s->size = newsize;
    s->s = news;
  return 1;

Generated by  Doxygen 1.6.0   Back to index