Example #1
0
/*************************************
 * Function: pa_CloneMDLTag
 *
 * Description: This function allocates and fills in an entire
 * 		PA_Tag structure for any MDL tag element type.
 *
 * Params: The tag to clone
 *
 * Returns: A pointer to a completely filled in PA_Tag structure
 *      that is a clone of the tag passed in.  On failure it 
 *      returns NULL.
 *************************************/
PA_Tag *
PA_CloneMDLTag(PA_Tag * src)
{
	PA_Tag *tag;
	PA_Block buff;
	char *locked_buff, *src_buff;

	/*
	 * Allocate a new tag structure, return NULL
	 * if you can't.
	 */
	tag = XP_NEW(PA_Tag);
	if (tag == NULL)
	{
		return(NULL);
	}
	tag->type = src->type;
	tag->is_end = src->is_end;
	tag->newline_count = src->newline_count;
	tag->data_len = src->data_len;
	tag->true_len = src->true_len;
	tag->lo_data = NULL;
	tag->next = NULL;

	/* sure wish we could just do a strdup() here */
	buff = PA_ALLOC((tag->data_len + 1) * sizeof(char));
	if (buff != NULL)
	{
		PA_LOCK(locked_buff, char *, buff);
		PA_LOCK(src_buff, char *, src->data);
		XP_BCOPY(src_buff, locked_buff, tag->data_len);
		locked_buff[tag->data_len] = '\0';
		PA_UNLOCK(locked_buff);
		PA_UNLOCK(src_buff);
	}
Example #2
0
/*  Buffer write.  
**  ------------
*/
extern "C"  int 
memory_stream_write (NET_StreamClass *stream, const char* s, int32 l)
{
    DataObject * data = (DataObject *)stream->data_object;	

    ASSERT(data);
    ASSERT(s);

    if(!data || !data->start || !data->loc)
        return(MK_OUT_OF_MEMORY);

    /* check the sizes - make bigger and recopy if needed */
    if(((unsigned long)(data->loc - data->start))  + l > (unsigned long)data->sz) {
    char * buffer;
        int oldcontents = data->loc - data->start;

        data->sz += DEFAULT_BUFFER_SZ;
        buffer = (char *) XP_REALLOC(data->start, data->sz);
        if(!buffer) {
          XP_FREE(data->start);
          data->start = NULL;
          data->loc = NULL;
          return(MK_OUT_OF_MEMORY);
        }
          
        data->start = buffer;
        data->loc = data->start + oldcontents;     
    }
    
    /* copy the stuff over and update the pointer */
    XP_BCOPY(s, data->loc, l);
    data->loc += l;

    data->cur_loc += l;

    float fPercent = 0.0f;

    if (data->content_length) 
        fPercent = (float)data->cur_loc / (float)data->content_length;
    if (data->cur_loc) 
        FE_SetProgressBarPercent(data->context, (int)(fPercent * 100));

    return((int) l);
}