Exemplo n.º 1
0
int epr_delete_selector(epr_t *epr, const char *name)
{
	int i,k;
	int count;
	Selector *selectors;
	if(epr == NULL || name == NULL) return 0;
	count = epr->refparams.selectorset.count;
	selectors = epr->refparams.selectorset.selectors;
	for(i =0; i < count; i++) {
		if(strcmp(name, selectors[i].name) == 0)
			break;
	}
	if(i == count) return -1;

	u_free(selectors[i].name);
	if(selectors[i].type == 0) {
		u_free(selectors[i].value);
	}
	else {
		epr_destroy((epr_t *)selectors[i].value);
	}

	for(k = i; k < count-1; k++) {
		memcpy(&selectors[k], &selectors[k+1], sizeof(Selector));
	}

	epr->refparams.selectorset.selectors = u_realloc(selectors, (count-1)*sizeof(Selector));
	epr->refparams.selectorset.count--;

	return 0;
}
Exemplo n.º 2
0
static int epr_add_selector(epr_t *epr, const char *name, selector_entry *selector)
 {
 	int i;
 	Selector *p;
	if(epr == NULL) return 0;
 	p = epr->refparams.selectorset.selectors;
	for(i = 0; i< epr->refparams.selectorset.count; i++) {
		if(p->name && ( strcmp(name, p->name) == 0 ) ) {
			return -1;
		}
		p++;
	}
	p = epr->refparams.selectorset.selectors;
	p = u_realloc(p, (epr->refparams.selectorset.count+1) * sizeof(Selector));
	if(p == NULL) return -1;
	p[epr->refparams.selectorset.count].name = u_strdup(name);
	p[epr->refparams.selectorset.count].type = selector->type;
	if(selector->type == 0) {
		if (selector->entry.text) {
			p[epr->refparams.selectorset.count].value = u_strdup(selector->entry.text);
		}
	} else {
		p[epr->refparams.selectorset.count].value = (char *)epr_copy(selector->entry.eprp);
	}

	epr->refparams.selectorset.selectors = p;
	epr->refparams.selectorset.count++;
	return 0;
 }
Exemplo n.º 3
0
/**
 *  \brief  Enlarge the underlying memory block of the given buffer
 *
 *  Enlarge the buffer data block of the supplied ::u_string_t object \p s 
 *  to (at least) \p size bytes.
 *
 *  \param  s       an ::u_string_t object
 *  \param  size    the requested new size
 *
 *  \retval  0  on success
 *  \retval ~0  on failure
 */
int u_string_reserve (u_string_t *s, size_t size)
{
    char *nbuf = NULL;

    dbg_return_if (s == NULL, ~0);
    nop_return_if (size <= s->data_sz, 0);
   
    /* realloc requested size plus 1 char to store the terminating '\0' */
    nbuf = u_realloc(((s->data == null) ? NULL : s->data), size + 1);
    dbg_err_sif (nbuf == NULL);

    /* zero terminate it */
    nbuf[size] = '\0';

    s->data = (void *) nbuf;
    s->data_sz = size;

    return 0;
err:
    return ~0;
}
Exemplo n.º 4
0
Arquivo: buf.c Projeto: fdotli/libu
/**
 *  \brief  Enlarge the memory allocated to a given buffer
 *
 *  Enlarge the buffer data block to (at least) \p size bytes.
 *
 *  \param  ubuf    an already allocated ::u_buf_t object
 *  \param  size    the requested size in bytes
 *
 *  \retval  0  on success
 *  \retval ~0  on failure
 */
int u_buf_reserve (u_buf_t *ubuf, size_t size)
{
    char *nbuf;

    dbg_err_if (ubuf == NULL);

    nop_return_if (size <= ubuf->size, 0);  /* nothing to do */
   
    /* size plus 1 char to store a '\0' */
    dbg_err_sif ((nbuf = u_realloc(ubuf->data, size + 1)) == NULL);

    /* buffer data will always be zero-terminated (but the len field will not
     * count the last '\0') */
    nbuf[size] = '\0';

    ubuf->data = nbuf;
    ubuf->size = size;

    return 0;
err:
    return ~0;
}