Beispiel #1
0
/*******************************************************************************
 * Move 'len' bytes from 'src' buffer to 'dest' buffer.  There must be at
 * least 'len' bytes available in the source buffer and space for 'len'
 * bytes in the destination buffer.
 */
void fcgi_buf_get_to_buf(Buffer *dest, Buffer *src, int len)
{
    char *dest_end, *src_begin;
    int dest_len, src_len, move_len;

    ASSERT(len > 0);
    ASSERT(BufferLength(src) >= len);
    ASSERT(BufferFree(dest) >= len);

    fcgi_buf_check(src);
    fcgi_buf_check(dest);

    for (;;) {
        if (len == 0)
            return;

        fcgi_buf_get_free_block_info(dest, &dest_end, &dest_len);
        fcgi_buf_get_block_info(src, &src_begin, &src_len);

        move_len = min(dest_len, src_len);
        move_len = min(move_len, len);

        if (move_len == 0)
            return;

        memcpy(dest_end, src_begin, move_len);
        fcgi_buf_toss(src, move_len);
        fcgi_buf_add_update(dest, move_len);
        len -= move_len;
    }
}
void PICAPI ps_image_unref(ps_image* img)
{
    if (!picasso::is_valid_system_device()) {
        global_status = STATUS_DEVICE_ERROR;
        return;
    }

    if (!img) {
        global_status = STATUS_INVALID_ARGUMENT;
        return;
    }

    img->refcount--;
    if (img->refcount <= 0) {
        if (img->flage == buffer_alloc_surface)
            BufferFree(img->buffer.buffer());
        else if (img->flage == buffer_alloc_malloc)
            mem_free(img->buffer.buffer());
        else if (img->flage == buffer_alloc_image)
            ps_image_unref(static_cast<ps_image*>(img->host));
        else if (img->flage == buffer_alloc_canvas)
            ps_canvas_unref(static_cast<ps_canvas*>(img->host));

        (&img->buffer)->picasso::rendering_buffer::~rendering_buffer();
        mem_free(img);
    }
    global_status = STATUS_SUCCEED;
}
Beispiel #3
0
void PICAPI ps_canvas_unref(ps_canvas* canvas)
{
    if (!picasso::is_valid_system_device()) {
        global_status = STATUS_DEVICE_ERROR;
        return;
    }

    if (!canvas) {
        global_status = STATUS_INVALID_ARGUMENT;
        return;
    }

    canvas->refcount--;
    if (canvas->refcount <= 0) {
        delete canvas->p; //mem_free painter
        if (canvas->flage == buffer_alloc_surface) {
            BufferFree(canvas->buffer.buffer());
        } else if (canvas->flage == buffer_alloc_malloc) {
            mem_free(canvas->buffer.buffer());
        } else if (canvas->flage == buffer_alloc_image) {
            ps_image_unref(static_cast<ps_image*>(canvas->host));
        } else if (canvas->flage == buffer_alloc_canvas) {
            ps_canvas_unref(static_cast<ps_canvas*>(canvas->host));
        }

        if (canvas->mask) {
            ps_mask_unref(canvas->mask);
        }

        (&canvas->buffer)->picasso::rendering_buffer::~rendering_buffer();
        mem_free(canvas);
    }
    global_status = STATUS_SUCCEED;
}
Beispiel #4
0
bool
BufferRealloc(TBuffer *       const buf,
              xmlrpc_uint32_t const memsize) {

    if (buf->staticid)
    {
        TBuffer b;

        if (memsize<=buf->size)
            return TRUE;

        if (BufferAlloc(&b,memsize))
        {
            memcpy(b.data,buf->data,buf->size);
            BufferFree(buf);
            *buf=b;
            return TRUE;
        }
    }
    else
    {
        void *d;
        
        d=realloc(buf->data,memsize);
        if (d)
        {
            buf->data=d;
            buf->size=memsize;
            return TRUE;
        }
    }

    return FALSE;
}
Beispiel #5
0
/*----------------------------------------------------------------------*/
static void
BufferUpdate(Widget w)
{
    assert( _XfeBufferType(w) != XmBUFFER_NONE );

    BufferFree(w);
    BufferAllocate(w);
}
Beispiel #6
0
void StringFree(TString *s)
{
	/* sanity */
	if (!s) {
		return;
	}

	s->size=0;
	BufferFree(&(s->buffer));
}
Beispiel #7
0
/*******************************************************************************
 * Updates the buf to reflect recently added data.
 */
void fcgi_buf_add_update(Buffer *buf, int count)
{
    fcgi_buf_check(buf);
    ASSERT(count >= 0);
    ASSERT(count <= BufferFree(buf));

    buf->length += count;
    buf->end += count;
    if(buf->end >= buf->data + buf->size) {
        buf->end -= buf->size;
    }

    fcgi_buf_check(buf);
}
Beispiel #8
0
/*******************************************************************************
 * Adds a block of data to a buffer, returning the number of bytes added.
 */
int fcgi_buf_add_block(Buffer *buf, char *data, int datalen)
{
    char *end;
    int copied = 0;     /* Number of bytes actually copied. */
    int canCopy;        /* Number of bytes to copy in a given op. */

    ASSERT(data != NULL);
    ASSERT(datalen >= 0);

    if(datalen == 0) {
        return 0;
    }

    ASSERT(datalen > 0);
    fcgi_buf_check(buf);
    end = buf->data + buf->size;

    /*
     * Copy the first part of the data:  from here to the end of the
     * buffer, or the end of the data, whichever comes first.
     */
    datalen = min(BufferFree(buf), datalen);
    canCopy = min(datalen, end - buf->end);
    memcpy(buf->end, data, canCopy);
    buf->length += canCopy;
    buf->end += canCopy;
    copied += canCopy;
    if (buf->end >= end) {
        buf->end = buf->data;
    }
    datalen -= canCopy;

    /*
     * If there's more to go, copy the second part starting from the
     * beginning of the buffer.
     */
    if (datalen > 0) {
        data += canCopy;
        memcpy(buf->end, data, datalen);
        buf->length += datalen;
        buf->end += datalen;
        copied += datalen;
    }
    return(copied);
}
Beispiel #9
0
static int __gz_lines_iterator (lua_State *L)
{
  gzFile zf = (gzFile) lua_topointer (L, lua_upvalueindex(1));
  int ch = '\0';
  char* ret;

  if (content_buffer_length == 0)
    ExtendBuffer ();
  else
    ResetBuffer ();

  #ifdef READ_LINE_ONE_BY_ONE

  while ( (ch = gzgetc(zf)) != -1 && ch != '\n') {
    AddToBuffer ((char) ch);
  }

  #else

  do {
    ret = gzgets (zf, content_buffer + BufferFill (), BufferFree ());
    if (ret == Z_NULL)
      break;
    int l = strlen (content_buffer);
    content_length = l;
    if (l > 0) {
      ch = content_buffer[l - 1];
      if (ch != '\n')
	ExtendBuffer ();
      else
	content_buffer[l-1] = '\0';
    }
  } while (ret && ch != '\n');

  #endif

  if (ch == '\n' || BufferFill () > 0) {
    if (ch == '\n')
      
    lua_pushstring (L, FinishBuffer ());
    return 1;
  } else {
    return pushresult(L, &zf, NULL);
  }
}
Beispiel #10
0
/*----------------------------------------------------------------------*/
static void
Destroy(Widget w)
{
    /* Remove all CallBacks */
    /* XtRemoveAllCallbacks(w,XmNenterCallback); */
    /* XtRemoveAllCallbacks(w,XmNfocusCallback); */
    /* XtRemoveAllCallbacks(w,XmNleaveCallback); */
    /* XtRemoveAllCallbacks(w,XmNresizeCallback); */
	
    /* Free or release a possible buffer */
    BufferFree(w);

    /* Free background gc if needed */
    if (_XfeBackgroundGC(w))
    {
		_XfePrimitiveReleaseBackgroundGC(w);
    }
}
Beispiel #11
0
 /*******************************************************************************
 * Build and queue a FastCGI message header.  It is the caller's
 * responsibility to make sure that there's enough space in the buffer, and
 * that the data bytes (specified by 'len') are queued immediately following
 * this header.
 */
static void queue_header(fcgi_request *fr, unsigned char type, unsigned int len)
{
    FCGI_Header header;

    ASSERT(type > 0);
    ASSERT(type <= FCGI_MAXTYPE);
    ASSERT(len <= 0xffff);
    ASSERT(BufferFree(fr->serverOutputBuffer) >= sizeof(FCGI_Header));

    /* Assemble and queue the packet header. */
    header.version = FCGI_VERSION;
    header.type = type;
    header.requestIdB1 = (unsigned char) (fr->requestId >> 8);
    header.requestIdB0 = (unsigned char) fr->requestId;
    header.contentLengthB1 = (unsigned char) (len / 256);  /* MSB */
    header.contentLengthB0 = (unsigned char) (len % 256);  /* LSB */
    header.paddingLength = 0;
    header.reserved = 0;
    fcgi_buf_add_block(fr->serverOutputBuffer, (char *) &header, sizeof(FCGI_Header));
}
Beispiel #12
0
bool EdiComposer::Compose(const Document& doc, const wxString& outFilename) {

    m_outputFile = new wxFile(outFilename, wxFile::write);
    if ( !m_outputFile ) {
        LOG_ERROR(wxGetApp().GetLogger(), 0, ADVPCS_COMPOSE_ERROR_OPEN_EDI_FILE + outFilename + "]");
        return false;
    }

    BufferAlloc();
    GetTrailer().Reset();

    LOG_INFO(wxGetApp().GetLogger(), 0, ADVPCS_COMPOSE_BUILD_HEADER);
    bool hr = ComposeHeader(doc);

    LOG_INFO(wxGetApp().GetLogger(), 0, ADVPCS_COMPOSE_BUILD_DETAIL);
    bool dr = ComposeDetail(doc);

    LOG_INFO(wxGetApp().GetLogger(), 0, ADVPCS_COMPOSE_ADDING_TRAILER);
    ComposeTrailer(doc);

    BufferFree();
    LOG_INFO(wxGetApp().GetLogger(), 0, wxString::Format(ADVPCS_COMPOSE_OK, outFilename) );
    return hr & dr;
};
Beispiel #13
0
int BufferRealloc(TBuffer *buf,uint32 memsize)
{
	/* sanity */
	if (!buf) {
		return FALSE;
	}

	if (buf->staticid)
	{
		TBuffer b;

		if (memsize<=buf->size)
			return TRUE;

		if (BufferAlloc(&b,memsize))
		{
			memcpy(b.data,buf->data,buf->size);
			BufferFree(buf);
			*buf=b;
			return TRUE;
		}
	}
	else
	{
		void *d;
		
		if( (d = (void*)realloc(buf->data,memsize)) )
		{
			buf->data=d;
			buf->size=memsize;
			return TRUE;
		}
	}

	return FALSE;
}
Beispiel #14
0
CCBaseBuffer::~CCBaseBuffer ( )
{	BufferFree ( );
}
Beispiel #15
0
void
StringFree(TString * const stringP) {
    stringP->size = 0;
    BufferFree(&stringP->buffer);
}