Sha256: 6d4a8c5eb2e3109cf3a52c4def22c7c0ce49a86f10976abbde239f02dc8db46f
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
#include "pbuffer.h" /* reentrant pbuffer functions */ TMPLPRO_LOCAL size_t pbuffer_size(pbuffer* pBuffer) { return pBuffer->bufsize; } TMPLPRO_LOCAL void pbuffer_preinit(pbuffer* pBuffer) { pBuffer->bufsize=0; pBuffer->buffer=NULL; } TMPLPRO_LOCAL char* pbuffer_init(pbuffer* pBuffer) { pBuffer->bufsize=256; pBuffer->buffer=(char*) malloc (pBuffer->bufsize * sizeof(char)); return pBuffer->buffer; } TMPLPRO_LOCAL char* pbuffer_init_as(pbuffer* pBuffer,size_t size) { pBuffer->bufsize=PBUFFER_MULTIPLICATOR*size; pBuffer->buffer=(char*) malloc (pBuffer->bufsize * sizeof(char)); return pBuffer->buffer; } TMPLPRO_LOCAL char* pbuffer_string(pbuffer* pBuffer) { return pBuffer->buffer; } TMPLPRO_LOCAL char* pbuffer_resize(pbuffer* pBuffer, size_t size) { if (pBuffer->bufsize==0) { pbuffer_init_as(pBuffer, size); } else if (pBuffer->bufsize< size) { pBuffer->bufsize=PBUFFER_MULTIPLICATOR*size; /* aggresive memory allocation to prevent frequent requests*/ pBuffer->buffer=(char*) realloc (pBuffer->buffer,pBuffer->bufsize * sizeof(char)); } return pBuffer->buffer; } TMPLPRO_LOCAL void pbuffer_free(pbuffer* pBuffer) { if (pBuffer->bufsize!=0) { pBuffer->bufsize=0; free(pBuffer->buffer); pBuffer->buffer=NULL; } } TMPLPRO_LOCAL void pbuffer_fill_from_pstring(pbuffer* pBuffer, PSTRING pstr) { size_t size = pstr.endnext - pstr.begin; const char* from = pstr.begin; char* dest; if (pBuffer->bufsize==0) { pbuffer_init_as(pBuffer, size+1); } else if (pBuffer->bufsize<size) { pbuffer_resize(pBuffer, size+1); } dest = pBuffer->buffer; while (from<pstr.endnext) { *(dest++)=*(from++); } *dest='\0'; } TMPLPRO_LOCAL void pbuffer_swap(pbuffer* buf1, pbuffer* buf2) { pbuffer tmpbuf = *buf1; *buf1 = *buf2; *buf2 = tmpbuf; } /* * Local Variables: * mode: c * End: */
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
html-template-pro-0.0.3 | ext/html/template/pbuffer.c |
html-template-pro-0.0.2 | ext/html/template/internal/pbuffer.c |
html-template-pro-0.0.1 | ext/html/template/internal/pbuffer.c |