pike.git / src / dynamic_buffer.c

version» Context lines:

pike.git/src/dynamic_buffer.c:1:   /*\ - ||| This file a part of uLPC, and is copyright by Fredrik Hubinette - ||| uLPC is distributed as GPL (General Public License) + ||| This file a part of Pike, and is copyright by Fredrik Hubinette + ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h"   #include "dynamic_buffer.h"   #include "stralloc.h"   #include "error.h"   #include "memory.h"      static dynamic_buffer buff;      char *low_make_buf_space(INT32 space,dynamic_buffer *buf)   {    char *ret; -  + #ifdef DEBUG +  if(!buf->s.str) fatal("ARRRRGH! Deadly Trap!\n"); + #endif +     if(buf->s.len+space>=buf->bufsize)    { -  +  if(!buf->bufsize) buf->bufsize=1; +     do{    buf->bufsize*=2;    }while(buf->s.len+space>=buf->bufsize);       buf->s.str=(char *)realloc(buf->s.str,buf->bufsize);    if(!buf->s.str)    error("Out of memory.\n");    }    ret=buf->s.str + buf->s.len;    buf->s.len+=space;
pike.git/src/dynamic_buffer.c:85:    if(buf->s.str) free(buf->s.str);    buf->s.str=0;   }      char *simple_free_buf(void)   {    if(!buff.s.str) return 0;    return complex_free_buf().str;   }    - struct lpc_string *low_free_buf(dynamic_buffer *buf) + struct pike_string *low_free_buf(dynamic_buffer *buf)   { -  struct lpc_string *q; +  struct pike_string *q;    if(!buf->s.str) return 0;    q=make_shared_binary_string(buf->s.str,buf->s.len);    free(buf->s.str);    buf->s.str=0;    buf->s.len=0;    return q;   }    - struct lpc_string *free_buf(void) { return low_free_buf(&buff); } + struct pike_string *free_buf(void) { return low_free_buf(&buff); }   char *make_buf_space(INT32 space) { return low_make_buf_space(space,&buff); }   void my_putchar(char b) { low_my_putchar(b,&buff); }   void my_binary_strcat(const char *b,INT32 l) { low_my_binary_strcat(b,l,&buff); }   void my_strcat(const char *b) { my_binary_strcat(b,strlen(b)); }   void init_buf(void) { low_init_buf(&buff); }   void init_buf_with_string(string s) { low_init_buf_with_string(s,&buff); }   char *return_buf(void)   {    my_putchar(0);    return buff.s.str;   }   /* int my_get_buf_size() { return buff->s.len; } */