Skip to content
Snippets Groups Projects
Select Git revision
  • aa12d997b136ae0347c5a613ca486865fc7f70db
  • master default protected
  • 9.0
  • 8.0
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • nt-tools
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
  • v8.0.1982
  • v8.0.1980
  • v8.0.1978
  • v8.0.1976
  • v8.0.1974
  • v8.0.1972
  • v8.0.1970
  • v8.0.1968
  • v8.0.1966
41 results

dynamic_buffer.c

Blame
  • dynamic_buffer.c 4.34 KiB
    /*
    || This file is part of Pike. For copyright information see COPYRIGHT.
    || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
    || for more information.
    */
    
    #include "global.h"
    #include "dynamic_buffer.h"
    #include "stralloc.h"
    #include "pike_error.h"
    #include "pike_memory.h"
    
    PMOD_EXPORT dynamic_buffer pike_global_buffer;
    
    PMOD_EXPORT char *low_make_buf_space(ptrdiff_t space, dynamic_buffer *buf)
    {
      char *ret;
    #ifdef PIKE_DEBUG
      if(!buf->s.str) Pike_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=realloc(buf->s.str, buf->bufsize);
        if(!buf->s.str)
          Pike_fatal("Out of memory.\n");
      }
      ret = buf->s.str + buf->s.len;
      buf->s.len += space;
      return ret;
    }
    
    PMOD_EXPORT void low_my_putchar(int b,dynamic_buffer *buf)
    {
    #ifdef PIKE_DEBUG
      if(!buf->s.str)
        Pike_fatal("Error in internal buffering.\n");
    #endif
      low_make_buf_space(1,buf)[0]=b;
    }
    
    PMOD_EXPORT void low_my_binary_strcat(const char *b, size_t l,
    				      dynamic_buffer *buf)
    {
    #ifdef PIKE_DEBUG
      if(!buf->s.str)
        Pike_fatal("Error in internal buffering.\n");
    #endif
    
      MEMCPY(low_make_buf_space(l, buf),b, l);
    }
    
    PMOD_EXPORT void debug_initialize_buf(dynamic_buffer *buf)
    {
      buf->s.str=xalloc((buf->bufsize=BUFFER_BEGIN_SIZE));
      *(buf->s.str)=0;
      buf->s.len=0;
    }
    
    PMOD_EXPORT void low_reinit_buf(dynamic_buffer *buf)
    {
      if(!buf->s.str)
      {
        initialize_buf(buf);