Ejemplo n.º 1
0
extern sd_hash_t* sd_hash_new(size_t a_size, const sd_hash_ops_t* a_ops)
{
    const static sd_hash_ops_t default_ops = {
        (void*) &sd_hash_hash_string,
        (void*) &strcmp,
        0, 0, 0, 0
    };

    sd_hash_t*		hash;
    sd_hash_iter_t**	tab;

    if (a_size == 0) a_size = SD_HASH_DEFAULT_SIZE;

    hash	= sd_calloc(1, sizeof(*hash));
    tab		= sd_calloc(a_size, sizeof(*tab));

    if (hash == 0 || tab == 0) {
        free(hash);
        free(tab);
        return 0;
    }

    hash->nelem	= 0;
    hash->size	= a_size;
    hash->tab	= tab;
    hash->ops	= a_ops != 0 ? a_ops : &default_ops;

    return hash;
}
Ejemplo n.º 2
0
sd_stack_t* sd_stack_new(size_t max)
{
    sd_stack_t* this;

    this        = sd_calloc(1, sizeof(sd_stack_t));
    this->max   = max == 0 ? INT_MAX : max;
    this->size  = SD_STACK_INIT_SIZE;
    this->sp    = 0;
    this->array = sd_calloc(this->size, sizeof(*this->array));

    return this;
}
Ejemplo n.º 3
0
static void rehash(sd_hash_t* a_this)
{
    size_t			i;
    int h, size;
    sd_hash_iter_t**	tab;
    sd_hash_iter_t*	p;
    sd_hash_iter_t*	q;

    size	= SD_HASH_GROWTAB * a_this->size;
    tab		= sd_calloc(size, sizeof(*tab));

    if (tab == 0) return;

    for (i = 0; i < a_this->size; i++) {
        for (p = a_this->tab[i]; p; p = q) {
            q						= p->__next;
            h						= hindex(p->__hkey,
                                             size);
            p->__next					= tab[h];
            tab[h]					= p;
            if (p->__next != 0) p->__next->__prev	= p;
            p->__prev					= 0;
        }
    }
    free(a_this->tab);

    a_this->tab		= tab;
    a_this->size	= size;
}
Ejemplo n.º 4
0
static struct mmap_info* mmap_info_new(const char* a_name)
{
    struct mmap_info* minfo = NULL;

    minfo = sd_calloc(1, sizeof(*minfo));
    minfo->name = a_name;

    if ( (minfo->fd = open(minfo->name, O_RDWR, 0644)) == -1) {
	perror("open");
	mmap_info_delete(minfo);
	return NULL;
    }

    if (fstat(minfo->fd, &minfo->st) == -1) {
	perror("fstat");
	mmap_info_delete(minfo);
	return NULL;
    }

    minfo->length = minfo->st.st_size;

    if (!minfo->length) {
	fprintf(stderr, "file %s is empty", minfo->name);
	mmap_info_delete(minfo);
	return NULL;
    }

    return minfo;
}
Ejemplo n.º 5
0
extern sd_hash_iter_t* sd_hash_lookadd(sd_hash_t* a_this, const void* a_key)
{
    int			h;
    sd_hash_iter_t*	p;

    if (a_this == 0 || a_key == 0)			return 0;
    if ((p = sd_hash_lookup(a_this, a_key)) != 0)	return p;
    if ((p = sd_calloc(1, sizeof(*p))) == 0)		return 0;

    if (a_this->ops->key_dup != 0)
        p->key = a_this->ops->key_dup(a_key);
    else
        p->key = (void*) a_key;

    p->hash					= a_this;
    p->__hkey					= a_this->ops->hash(a_key);

    if (a_this->nelem > SD_HASH_FULLTAB * a_this->size) rehash(a_this);

    h						= hindex(p->__hkey,
                                     a_this->size);
    p->__next					= a_this->tab[h];
    a_this->tab[h]				= p;
    if (p->__next != 0) p->__next->__prev	= p;

    a_this->nelem++;

    return p;
}
Ejemplo n.º 6
0
extern sd_list_iter_t* sd_list_iter_insert(sd_list_iter_t* a_this,
					   void* a_data)
{
    sd_list_iter_t* i;
    
    if (! a_this) return 0;
    
    if (a_this->list->head == a_this)
	return sd_list_prepend(a_this->list, a_data);
    
    if ((i = sd_calloc(1, sizeof(*i))) == 0)
	return 0;
    
    i->data			= a_data;
    i->list			= a_this->list;
    i->__prev			= a_this->__prev;
    i->__next			= a_this;
    
    /* CAUTION: always exists since a_this is not the head */
    a_this->__prev->__next	= i;    
    a_this->__prev		= i;
    
    a_this->list->nelem++;
    
    return i;
}
Ejemplo n.º 7
0
extern sd_list_t* sd_list_new(size_t a_capacity)
{
    sd_list_t* this;
    
    this	= sd_calloc(1, sizeof(sd_list_t));
    this->head	= 0;
    this->tail	= 0;
    this->nelem	= 0;
    return this;
}
Ejemplo n.º 8
0
extern log4c_layout_t* log4c_layout_new(const char* a_name)
{
    log4c_layout_t* this;
    
    if (!a_name)
	return NULL;

    this	    = sd_calloc(1, sizeof(log4c_layout_t));
    this->lo_name   = sd_strdup(a_name);
    this->lo_type   = &log4c_layout_type_basic;
    this->lo_udata  = NULL;

    return this;
}
Ejemplo n.º 9
0
extern sd_factory_t* sd_factory_new(const char* a_name,
  const sd_factory_ops_t* a_ops)
{
  sd_factory_t* this;
  
  if (!a_name || !a_ops)
    return NULL;
  
  this           = sd_calloc(1, sizeof(*this));
  this->fac_name = sd_strdup(a_name);
  this->fac_ops  = a_ops;
  this->fac_hash = sd_hash_new(20, NULL);
  return this;
}
Ejemplo n.º 10
0
extern log4c_appender_t* log4c_appender_new(const char* a_name)
{
  log4c_appender_t* this;
  
  if (!a_name)
    return NULL;
  
  this	     = sd_calloc(1, sizeof(log4c_appender_t));
  this->app_name   = sd_strdup(a_name);
  this->app_type   = &log4c_appender_type_stream;
  this->app_layout = log4c_layout_get("basic");
  this->app_isopen = 0;
  this->app_udata  = NULL;
  return this;
}
Ejemplo n.º 11
0
extern log4c_logging_event_t* log4c_logging_event_new(
    const char* a_category,
    int		a_priority,
    const char*	a_message)
{
    log4c_logging_event_t* evt;

    evt 		= sd_calloc(1, sizeof(log4c_logging_event_t));    
    evt->evt_category	= a_category;
    evt->evt_priority	= a_priority;
    evt->evt_msg	= a_message;
    
    SD_GETTIMEOFDAY(&evt->evt_timestamp, NULL);

    return evt;
}
Ejemplo n.º 12
0
LOG4C_API log4c_rollingpolicy_t* log4c_rollingpolicy_new(const char* a_name){
  log4c_rollingpolicy_t* this;
  
  sd_debug("log4c_rollingpolicy_new[ ");
  if (!a_name)
    return NULL;
  sd_debug("new policy name='%s'", a_name);
  this	          = sd_calloc(1, sizeof(log4c_rollingpolicy_t));
  this->policy_name     = sd_strdup(a_name);
  this->policy_type     = &log4c_rollingpolicy_type_sizewin;
  this->policy_udata    = NULL;
  this->policy_rfudatap  = NULL;
  this->policy_flags = 0; 
  
  sd_debug("]");
  
  return this;
}
Ejemplo n.º 13
0
extern sd_list_iter_t* sd_list_add(sd_list_t* a_this, void* a_data)
{
    sd_list_iter_t* i;
    
    if (! a_this) return 0;
    
    
    if ((i = sd_calloc(1, sizeof(*i))) == 0)
	return 0;
    
    i->data		= a_data;
    i->list		= a_this;    
    i->__next		= a_this->head;
    i->__prev		= 0;
    a_this->head	= i;
    
    if (i->__next) i->__next->__prev	= i;
    if (!a_this->tail) a_this->tail	= i;
    
    a_this->nelem++;
    
    return i;
}