예제 #1
0
void * 
createPlayList(char * title)
{
    PlayList * pl = MEM_ALLOC(sizeof(PlayList));
    if (pl==NULL){
        PL_ERR("%s failed, no memory!\n", __FUNCTION__);
        goto err;
    }

    MEM_ZERO(pl, sizeof(PlayList));

    if (title==NULL)
        title = DEFAULT_PL_TITLE;

    
    pl->title = MEM_ALLOC(strlen(title)+1);
    if (pl->title==NULL){
        PL_ERR("%s failed, no memory!\n");
        goto err;
    }
    strcpy(pl->title, title);
    
    
    return (void *)pl;
err:
    if (pl){
        MEM_FREE(pl);
        pl=NULL;
    }
    return (void *)pl;
}
예제 #2
0
static pkt_cap_ctx_p pkt_cap_ctx_new(int num)
{
	pkt_cap_ctx_p snap = NULL;
	
	MEM_ALLOC(snap, pkt_cap_ctx_p, sizeof(pkt_cap_ctx_t) * num, NULL);
	for (int i = 0; i < num; i++) {
		MEM_ALLOC(snap[i].p_pkt_info, pkt_info_p, sizeof(pkt_info_t) * PKT_TYPE_NUM, NULL);
		snap[i].num = PKT_TYPE_NUM;
	}

	pkt_cap_ctx_clear(snap, num);	

	return snap;
}
예제 #3
0
PlayItem * 
addItemAtTail(void * hdl, fsl_player_s8 * iName, fsl_player_s32 copy)
{
    PlayItemCtl * item = NULL;
    PlayList * pl = (PlayList *)hdl;
    
    if ((pl==NULL)||(iName==NULL)){
        PL_ERR("%s failed, parameters error!\n", __FUNCTION__);
        goto err;
    }

    item = MEM_ALLOC(sizeof(PlayItemCtl));
    if (item==NULL){
        PL_ERR("%s failed, no memory!\n");
        goto err;
    }

    MEM_ZERO(item, sizeof(PlayItemCtl));

    if (copy){
        item->buffer = MEM_ALLOC(strlen(iName));
        if (item->buffer==NULL){
            PL_ERR("%s failed, no memory!\n");
            goto err;
        }
        strcpy(item->buffer, iName);
        item->pi.name = item->buffer;
    }else{
        item->pi.name = iName;
    }

    item->pl = pl;

    item->prev = pl->tail;
    
    if (pl->head){
        pl->tail->next = item;
        pl->tail= item;
    }else{
        pl->head = pl->tail = item;
    }
    return (PlayItem *)item;
err:
    if (item){
        MEM_FREE(item);
        item=NULL;
    }
    return (PlayItem *)item;
}
예제 #4
0
파일: util.c 프로젝트: hoangt/beluga
/*
 *  accumulates strings managing a buffer for them;
 *  calls to snbuf() must not be interleaved;
 *  used in:
 *    - build() from inc.c to construct full paths;
 *    - concat() from mcr.c to splice tokens and
 *    - derror() from proc.c to collect following tokens
 */
char *(snbuf)(size_t len, int cp)
{
    static char buf[64],    /* size must be power of 2 */
                *p = buf;
    static size_t blen = sizeof(buf);

    assert(p);

    if (len == (size_t)-1) {
        if (p != buf)
            MEM_FREE(p);
    } else if (len <= blen)
        return p;
    else {
        blen = (len + sizeof(buf)-1) & ~(sizeof(buf)-1);
        if (p == buf) {
            p = MEM_ALLOC(blen);
            if (cp)
                strcpy(p, buf);
        } else
            MEM_RESIZE(p, blen);
    }

    return p;
}
예제 #5
0
파일: conf.c 프로젝트: mycoboco/beluga
/*
 *  sets the current section
 */
int (conf_section)(const char *sec)
{
    size_t len;
    char buf[30], *pbuf;
    const char *hkey;
    table_t *tab;

    assert(sec);

    /* sepunit() always clears errcode */

    len = strlen(sec);
    pbuf = strcpy((len > sizeof(buf)-1)? MEM_ALLOC(len+1): buf, sec);

    if (sepunit(pbuf, &pbuf) != CONF_ERR_OK) {
        if (pbuf != buf)
            MEM_FREE(pbuf);
        return errcode;    /* sepunit sets errcode */
    }

    hkey = hash_string((control & CONF_OPT_CASE)? pbuf: lower(pbuf));
    if (pbuf != buf)
        MEM_FREE(pbuf);

    tab = table_get(section, hkey);
    if (tab)
        current = tab;
    else
        errcode = CONF_ERR_SEC;

    return errcode;
}
예제 #6
0
파일: henv.c 프로젝트: gitrider/wxsj2
RETCODE SQL_API 
SQLAllocEnv (HENV FAR * phenv)
{
  GENV_t FAR *genv;

  genv = (GENV_t *) MEM_ALLOC (sizeof (GENV_t));

  if (genv == NULL)
    {
      *phenv = SQL_NULL_HENV;

      return SQL_ERROR;
    }

#if (ODBCVER >= 0x0300 )
  genv->type = SQL_HANDLE_ENV;
#endif

  genv->henv = SQL_NULL_HENV;	/* driver's env list */
  genv->hdbc = SQL_NULL_HDBC;	/* driver's dbc list */
  genv->herr = SQL_NULL_HERR;	/* err list          */

  *phenv = (HENV) genv;

  return SQL_SUCCESS;
}
예제 #7
0
void mac_comm_status_indication_callback(mlme_comm_status_ind_t *mcsi) {
    /* Only generate NLME_JOIN.indication if the association was successful. */
    if (MAC_SUCCESS != (mcsi->status)) {
        return;
    }
    
    /* Try to allocate some memory to build the indication on. */
    nlme_join_ind_t *nji = (nlme_join_ind_t *)MEM_ALLOC(nlme_join_ind_t);
    
    /* Verify that memory was allocated. */
    if (NULL == nji) {
        return;
    }
    
    /* Build the NLME_JOIN.indication. */
    nji->ShortAddress = nwk_param.join_ind.allocted_address;
    memcpy((void *)(&(nji->ExtendedAddress)), (void *)(&(mcsi->DstAddr)),sizeof(uint64_t));
    nji->CapabilityInformation = nwk_param.join_ind.capability_information;
    
    /* Add information about the newly added node in the Neighbor Table. */
    zigbee_neighbor_table_item_t *child = zigbee_neighbor_table_find(nwk_param.join_ind.allocted_address);
    if (NULL != child) { 
        memcpy((void *)(&(child->ExtendedAddress)), (void *)(&(mcsi->DstAddr)), sizeof(uint64_t));
        memcpy((void *)(&(child->NetworkAddress)), (void *)(&(nwk_param.join_ind.allocted_address)), sizeof(uint16_t));
    }
    
    /* Post event. */
    if (true != vrt_post_event(zigbee_join_indication_do_callback, (uint8_t *)nji)) {
        MEM_FREE(nji);
    }
}
Err sbuReceiveResponse( SyncBmrResponse_t **respP ) {

   UInt    cardNo;
   LocalID dbID;
   DWord   result;
   Err     error;

   SyncBmrData_t *dataP;

   sbuFindSyncBmr( &cardNo, &dbID );  // find SyncBmr

   // Allocate memory for SyncBmr comm block
   dataP = (SyncBmrData_t *)MEM_ALLOC( sizeof( SyncBmrData_t ) );
   ErrFatalDisplayIf( !dataP, "memory allocation" );

   MemPtrSetOwner( dataP, 0 );        // set owner of storage to system

   dataP->waitForResponse = true;     // indicate a response is expected
   dataP->requestP        = NULL;     // indicate no document to send
   dataP->responseP       = NULL;     // indicate no document received yet

   // Cause SyncBmr to be programmatically launched
   error = SysAppLaunch( cardNo, dbID,
                         sysAppLaunchFlagNewGlobals,
                         sysAppLaunchSyncBmrReceive,
                         (void *)dataP, &result );

   *respP = (SyncBmrResponse_t *)dataP->responseP;  // return received document

   MEM_FREE( dataP );                               // free SyncBmr comm block

   return 0;

} // sbuSendResponse()
예제 #9
0
void create_ts_packet_buf(psi_sec_info_t *p_ts_buf,
u8 partition_id, u16 user_id, u16 section_max_size)
{
  mem_mgr_alloc_param_t alloc_param = { 0 };
  
  /*!
    Allocating TS buffer for saving temporary parsing result
  */
  CHECK_FAIL_RET_VOID(p_ts_buf != NULL);

  p_ts_buf->i_section_max_size = section_max_size;
  p_ts_buf->b_complete_header  = 0;
  p_ts_buf->i_continuity_counter = 0;

  p_ts_buf->i_need           = 0;
  p_ts_buf->b_this_sec_using = FALSE;

  alloc_param.id      = partition_id;
  alloc_param.user_id = user_id;
  alloc_param.size    = section_max_size;

  p_ts_buf->p_cur_sec_buf    = MEM_ALLOC(&alloc_param);

  if(p_ts_buf->p_cur_sec_buf != NULL)
  {
    memset(p_ts_buf->p_cur_sec_buf, 0, p_ts_buf->i_section_max_size);
  }

}
예제 #10
0
b_file  *_AllocFile( int h, f_attrs attrs, long int fpos ) {
// Allocate file structure.
    b_file      *io;
    struct stat info;
    int         buff_size;

    if( fstat( h, &info ) == -1 ) {
        FSetSysErr( NULL );
        return( NULL );
    }
    attrs &= ~CREATION_MASK;
    if( S_ISCHR( info.st_mode ) ) {
        io = MEM_ALLOC( sizeof( a_file ) );
        // Turn off truncate just in case we turned it on by accident due to
        // a buggy NT dos box.  We NEVER want to truncate a device.
        attrs &= ~TRUNC_ON_WRITE;
        attrs |= CHAR_DEVICE;
    } else {
        attrs |= BUFFERED;
        buff_size = IOBufferSize;
        io = MEM_ALLOC( sizeof( b_file ) + IOBufferSize - MIN_BUFFER );
        if( ( io == NULL ) && ( IOBufferSize > MIN_BUFFER ) ) {
            // buffer is too big (low on memory) so use small buffer
            buff_size = MIN_BUFFER;
            io = MEM_ALLOC( sizeof( b_file ) );
        }
    }
    if( io == NULL ) {
        close( h );
        FSetErr( IO_NO_MEM, NULL );
    } else {
        if( attrs & CARRIAGE_CONTROL ) {
            attrs |= CC_NOLF;
        }
        io->attrs = attrs;
        io->handle = h;
        if( attrs & BUFFERED ) {
            io->b_curs = 0;
            io->read_len = 0;
            io->buff_size = buff_size;
            io->high_water = 0;
        }
        io->phys_offset = fpos;
        IOOk( io );
    }
    return( io );
}
예제 #11
0
void *my_malloc(u32 size)
{
  mem_mgr_alloc_param_t para = {0};
  para.id = MEM_SYS_PARTITION;
  para.size = size;
  return MEM_ALLOC(&para);
  //return malloc(size);
}
예제 #12
0
파일: telnet.c 프로젝트: LoEE/luasched
static void teel_autocomplete(void* ud, char* path, int len, int* nb, char*** tab)
{
  TelnetState* ts = (TelnetState*) ud;
  lua_State* L = ts->L;

  lua_rawgeti(L, LUA_REGISTRYINDEX, ts->autocompletefuncref); // retrieve the auto complete function associated to that userdata

  if (lua_isnil(L, -1))
  {
    lua_pop(L, 1); // remove the nil from the stack to make it balanced
    *nb = 0;
    *tab = 0;
    return;
  }
  lua_pushlstring(L, path, len);
  int err = lua_pcall(L, 1, 2, 0);
  if (err != 0) // error during the call to get the table of completion proposals
  {
    output(ts); // output the error on the screen !
    lua_pop(L, 1); // remove the error from the stack to make it balanced
    *nb = 0;
    *tab = 0;
    return;
  }
  const char* s;
  size_t l;
  int n, i;
  s = lua_tolstring(L, -1, &l);
  n = lua_tointeger(L, -2);

  if (!n) // no completion proposals
  {
    *nb = 0;
    *tab = 0;
    lua_pop(L, 2); // make the stack balanced !
    return;
  }

  int msize = n*sizeof(char*)+l+1;
  char** t = MEM_ALLOC(msize);
  char*b = (char*)t + n*sizeof(char*);
  memcpy(b, s, l);
  b[l] = 0; // terminate with a nul char


  for (i = 0; i < n; ++i)
  {
    t[i] = b;
    b += strlen(b)+1;
  }
  assert(b == (char*)t+msize);

  lua_pop(L, 2); // make the stack balanced !

  *nb = n;
  *tab = t;
}
예제 #13
0
파일: adapt.c 프로젝트: joeeyles/allencahn
ADAPT_STAT *get_adapt_stat(const int dim, const char *name,
                           const char *prefix, int info,
                           ADAPT_STAT *adapt_stat)
{
    FUNCNAME("get_adapt_stat");
    ADAPT_STAT  adapt_stand = {nil, 1.0, 2, 30, 2, nil, nil, nil, nil,
                               nil, 0.0, 0.0, nil, nil, nil, nil,
                               dim, 0, dim, 1, 0.5, 0.1, 0.9, 0.2,
                               0.6, 0.1, 0.1
                              };
    char  key[1024];
    ADAPT_STAT *adapt;

    if (dim == 0) {
        WARNING("Adaption does not make sense for dim == 0!\n");
        return nil;
    }

    if (adapt_stat)
        adapt = adapt_stat;
    else {
        adapt = MEM_ALLOC(1, ADAPT_STAT);
        *adapt = adapt_stand;
        if (name)
            adapt->name = strdup(name);
        if (!adapt->name  && prefix)
            adapt->name = strdup(prefix);
    }

    if (!prefix)
        return(adapt);

    sprintf(key, "%s->tolerance", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->tolerance);
    sprintf(key, "%s->p", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->p);
    sprintf(key, "%s->max_iteration", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->max_iteration);
    sprintf(key, "%s->info", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->info);

    sprintf(key, "%s->refine_bisections", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->refine_bisections);
    sprintf(key, "%s->coarsen_allowed", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->coarsen_allowed);
    if (adapt->coarsen_allowed)
    {
        sprintf(key, "%s->coarse_bisections", prefix);
        GET_PARAMETER(info-2, key, "%d", &adapt->coarse_bisections);
    }

    init_strategy(funcName, prefix, info-1, adapt);

    return(adapt);
}
예제 #14
0
////////////////////////////////////////////////////////////////////////////////
///
/// \brief Clones circle
///
/// \return Pointer to cloned circle
///
////////////////////////////////////////////////////////////////////////////////
CCircle* CCircle::clone() const
{
    METHOD_ENTRY("CCircle::clone");
    
    CCircle* pClone = new CCircle();
    MEM_ALLOC("IShape")
        
    pClone->copy(this);
    
    return pClone;
}
예제 #15
0
파일: telnet.c 프로젝트: LoEE/luasched
static char* tabify(const char* buf, size_t* l)
{
  #define TAB_SIZE  8
  char* b;
  size_t i, j, o;
  size_t len = *l;
  int found = 0;

  // compute the number of chars to add because of tabs
  for (i=0, j=0, o=0; i < len; ++i)
  {
    if ((buf[i]=='\t'))
    {
      j += TAB_SIZE-(o%TAB_SIZE);
      found = 1;
    }
    else
    {
      j++;
      if ((buf[i]=='\n'))
        o = 0;
      else
        o++;
    }
  }

  if (!found)
    return 0;

  b = MEM_ALLOC(j);

  // replace tabs by spaces
  for (i=0, j=0, o=0; i < len; ++i)
  {
    if ((buf[i]=='\t'))
    {
      int k = TAB_SIZE-(o%TAB_SIZE);
      for (; k>0; k--)
        b[j++] = ' ';
    }
    else
    {
      b[j++] = buf[i];
      if ((buf[i]=='\n'))
        o = 0;
      else
        o++;
    }
  }

  *l = j;
  return b;
}
예제 #16
0
파일: text.c 프로젝트: mycoboco/beluga
/*
 *  converts a text to a C string
 */
char *(text_get)(char *str, int size, text_t s)
{
    assert(s.len >= 0 && s.str);

    if (str == NULL)
        str = MEM_ALLOC(s.len + 1);    /* +1 for null character */
    else
        assert(size >= s.len + 1);

    memcpy(str, s.str, s.len);
    str[s.len] = '\0';

    return str;
}
예제 #17
0
RETCODE SQL_API SQLAllocEnv(
									HENV* phenv)
{
	env_t*   penv;

	*phenv = penv = (env_t*)MEM_ALLOC(sizeof(env_t));

	if ( ! penv )
		return SQL_ERROR;

	penv->herr = 0;
	penv->hdbc = 0;

	return SQL_SUCCESS;
}
/*----------------------------------------------------------------*/
static data_range_t *add_field(char *name)
{
    data_range_t *f;

    if (nfields == 0)
        fields = MEM_ALLOC(data_range_t);
    else
        fields = MEM_GROW(fields, nfields+1, data_range_t);
    f = &fields[nfields++];
    f->name = MEM_STRDUP(name);
    f->npt = 0;
    f->min_value = 0.0;
    f->max_value = 0.0;
    return f;
}
예제 #19
0
void GrowBuffer(WriteBuffer* buf, int size)
{
    if (buf->len + size > buf->size)
    {
        int newsize = max(buf->size * 2, buf->len + size);
        if (buf->buffer != buf->prealloc)
            buf->buffer = MEM_REALLOC(buf->buffer, newsize);
        else
        {
            buf->buffer = MEM_ALLOC(newsize);
            memcpy(buf->buffer, buf->prealloc, sizeof(buf->prealloc));
        }
        buf->size = newsize;
    }
}
예제 #20
0
파일: text.c 프로젝트: mycoboco/beluga
/*
 *  allocates storage in the text space.
 *
 *  Note that the zero size for storage is permitted in order to allow for an empty text. The code
 *  given here differs from the original one in three places:
 *  - it checks if the limit or avail member of current is a null pointer; the original code in the
 *    book did not, which results in undefined behavior;
 *  - an operation adding an integer to a pointer for comparison was revised to that subtracting a
 *    pointer from another pointer (see ISATEND()); and
 *  - a composite assignment expression was decomposed to two separate assignment expressions to
 *    avoid undefined behavior.
 *
 *  The last item deserves more explanation. The original expression:
 *
 *      current = current->link = MEM_ALLOC(sizeof(*current) + 10*1024 + len);
 *
 *  modifies current which is also referenced between two sequence points. Even if it is not
 *  crystal-clear whether or not the reference to current is necessary to determine a new value to
 *  store into current, the literal reading of the standard says undefined behavior about it. Thus,
 *  it seems clever to avoid it.
 */
static char *alloc(int len)
{
    assert(len >= 0);

    if (!current->avail || len > current->limit - current->avail) {
        /* new chunk added to list */
        current->link = MEM_ALLOC(sizeof(*current) + 10*1024 + len);    /* extra 10Kb */
        current = current->link;
        current->avail = (char *)(current + 1);
        current->limit = current->avail + 10*1024 + len;
        current->link = NULL;
    }
    current->avail += len;

    return current->avail - len;
}
예제 #21
0
파일: conf.c 프로젝트: mycoboco/beluga
/*
 *  retrieves a pointer to a value with a section/variable name
 */
static void *valget(const char *secvar)
{
    size_t len;
    char buf[30], *pbuf;
    char *sec, *var;
    table_t *tab;
    const char *hkey;
    void *pnode;

    assert(secvar);

    /* sep() always clears errcode */

    len = strlen(secvar);
    pbuf = strcpy((len > sizeof(buf)-1)? MEM_ALLOC(len+1): buf, secvar);

    if (sep(pbuf, &sec, &var) != CONF_ERR_OK) {
        if (pbuf != buf)
            MEM_FREE(pbuf);
        return NULL;    /* sep sets errcode */
    }

    if (!sec) {    /* current selected */
        if (!current)    /* no current section, thus global */
            tab = table_get(section, hash_string(""));
        else
            tab = current;
    } else    /* section name given */
        tab = table_get(section, hash_string((control & CONF_OPT_CASE)? sec: lower(sec)));

    if (!tab) {
        if (pbuf != buf)
            MEM_FREE(pbuf);
        errcode = CONF_ERR_SEC;
        return NULL;
    }

    hkey = hash_string((control & CONF_OPT_CASE)? var: lower(var));
    if (pbuf != buf)
        MEM_FREE(pbuf);

    pnode = table_get(tab, hkey);
    if (!pnode)
        errcode = CONF_ERR_VAR;

    return pnode;
}
예제 #22
0
void mac_associate_indication_callback(mlme_associate_ind_t *mai) {
    /* Allcoate some memory to build the MLME_ASSOCIATE.response on. */
    mlme_associate_resp_t *response = (mlme_associate_resp_t *)MEM_ALLOC(mlme_associate_resp_t);
    
    if (NULL == response) {
        return;
    }
    
    memcpy((void *)(&(response->DeviceAddress)), (void *)(&(mai->DeviceAddress)), sizeof(uint64_t));
    nwk_param.join_ind.capability_information = mai->CapabilityInformation;
    
    /* Check if the device with this long address has been given a short address
     * already. That is this device is the parent.
     */
    zigbee_neighbor_table_item_t *child = zigbee_neighbor_table_find_long(mai->DeviceAddress);
    if (NULL != child) {
        response->AssocShortAddress = child->NetworkAddress;
        nwk_param.join_ind.allocted_address = child->NetworkAddress;
    
        response->status = ASSOCIATION_SUCCESSFUL;
    } else {
        /* Check if the joining device is an End device or Router. */
        if (((mai->CapabilityInformation) & (0x02)) != (0x02)) {
            /* Check if it is possible to join the end device. */
            child = zigbee_neighbor_table_add_device();
        } else {
            /* Check if it is possible to join the router. */
            child = zigbee_neighbor_table_add_router();
        }
        
        if (NULL == child) {
            response->AssocShortAddress = 0xFFFF;
            response->status = PAN_AT_CAPACITY;
            /* Also upate the permit joining PIB in the IEEE 802.15.4 MAC to
             * reflect that the system is now not to associate more devices.
             */
            IEEE802_15_4_SET_ASSOCIATION_PERMITTED(false);
        } else {
            response->AssocShortAddress = child->NetworkAddress;
            nwk_param.join_ind.allocted_address = child->NetworkAddress;
            response->status = ASSOCIATION_SUCCESSFUL;
        }
    }
    
    (bool)ieee802_15_4_associate_response(response);
    MEM_FREE(response);
}
예제 #23
0
파일: rb_ogl3_uniform.c 프로젝트: vaplv/foo
/*******************************************************************************
 *
 * Uniform implementation.
 *
 ******************************************************************************/
int
rb_get_named_uniform
  (struct rb_context* ctxt,
   struct rb_program* program,
   const char* name,
   struct rb_uniform** out_uniform)
{
  struct rb_uniform* uniform = NULL;
  GLuint uniform_index = GL_INVALID_INDEX;
  size_t name_len = 0;
  int err = 0;

  if(!ctxt || !program || !name || !out_uniform)
    goto error;

  if(!program->is_linked)
    goto error;

  OGL(GetUniformIndices(program->name, 1, &name, &uniform_index));
  if(uniform_index == GL_INVALID_INDEX)
    goto error;

  err = get_active_uniform(ctxt, program, uniform_index, 0, NULL, &uniform);
  if(err != 0)
    goto error;

  name_len = strlen(name) + 1;
  uniform->name = MEM_ALLOC(ctxt->allocator, sizeof(char) * name_len);
  if(!uniform->name)
    goto error;

  uniform->name = strncpy(uniform->name, name, name_len);
  uniform->location = OGL(GetUniformLocation(program->name, uniform->name));

exit:
  *out_uniform = uniform;
  return err;

error:
  if(uniform) {
    RB(uniform_ref_put(uniform));
    uniform = NULL;
  }
  err = -1;
  goto exit;
}
예제 #24
0
파일: conf.c 프로젝트: mycoboco/beluga
/*
 *  constructs a default set for configuration variables
 *
 *  conf_preset() cannot be implemented with conf_set() since they differ in handling an omitted
 *  section name. conf_section() cannot affect conf_preset() because the former is not callable
 *  before the latter. Thus, conf_preset() can safely assume that a section name is given properly
 *  whenever necessary. On the other hand, because conf_set() is affected by conf_section(), a
 *  variable name without a section name and a period should be recognized as referring to the
 *  current section, not to the global section.
 *
 *  TODO:
 *    - some adjustment on arguments to table_new() is necessary;
 *    - considering changes to the format of a configuration file as a program to accept it is
 *      upgraded, making it a recoverable error to encounter a non-preset section or variable name
 *      would be useful; this enables an old version of the program to accept a new configuration
 *      file with diagnostics.
 */
int (conf_preset)(const conf_t *tab, int ctrl)
{
    size_t len;
    char *pbuf, *sec, *var;
    const char *hkey;
    table_t *t;
    struct valnode_t *pnode;

    assert(!section);
    assert(tab);

    control = ctrl;
    section = table_new(0, NULL, NULL);
    errcode = CONF_ERR_OK;

    for (; tab->var; tab++) {
        assert(tab->defval);
        assert(tab->type == CONF_TYPE_BOOL || tab->type == CONF_TYPE_INT ||
               tab->type == CONF_TYPE_UINT || tab->type == CONF_TYPE_REAL ||
               tab->type == CONF_TYPE_STR);

        len = strlen(tab->var);
        pbuf = strcpy(MEM_ALLOC(len+1 + strlen(tab->defval)+1), tab->var);
        if (sep(pbuf, &sec, &var) != CONF_ERR_OK) {
            MEM_FREE(pbuf);
            break;    /* sep sets errcode */
        }
        if (!sec)    /* means global section in this case */
            sec = "";    /* lower modifies sec only when necessary */
        hkey = hash_string((control & CONF_OPT_CASE)? sec: lower(sec));
        t = table_get(section, hkey);
        if (!t) {    /* new section */
            t = table_new(0, NULL, NULL);
            table_put(section, hkey, t);
        }
        MEM_NEW(pnode);
        pnode->type = tab->type;
        pnode->freep = pbuf;
        pnode->val = strcpy(pbuf + len+1, tab->defval);
        table_put(t, hash_string((control & CONF_OPT_CASE)? var: lower(var)), pnode);
    }

    preset = 1;

    return errcode;
}
예제 #25
0
파일: henv.c 프로젝트: tws67/bayonne-cygwin
SQLRETURN 
SQLAllocEnv_Internal (SQLHENV * phenv, int odbc_ver)
{
  GENV (genv, NULL);
  int retcode = SQL_SUCCESS;

  genv = (GENV_t *) MEM_ALLOC (sizeof (GENV_t));

  if (genv == NULL)
    {
      *phenv = SQL_NULL_HENV;

      return SQL_ERROR;
    }
  genv->rc = 0;

  /*
   *  Initialize this handle
   */
  genv->type = SQL_HANDLE_ENV;
  genv->henv = SQL_NULL_HENV;	/* driver's env list */
  genv->hdbc = SQL_NULL_HDBC;	/* driver's dbc list */
  genv->herr = SQL_NULL_HERR;	/* err list          */
#if (ODBCVER >= 0x300)
  genv->odbc_ver = odbc_ver;
  genv->connection_pooling = _iodbcdm_attr_connection_pooling;
  genv->cp_match = SQL_CP_MATCH_DEFAULT;
  genv->pdbc_pool = NULL;
#endif
  genv->err_rec = 0;

  *phenv = (SQLHENV) genv;

  /*
   * Initialize tracing 
   */
  if (++_iodbc_env_counter == 1)
    _iodbcdm_env_settracing (genv);

  return retcode;
}
예제 #26
0
int	nnodbc_attach_stmt(void* hdbc, void* hstmt)
{
	dbc_t*		pdbc = hdbc;
	gstmt_t*	pstmt;

	pstmt = (gstmt_t*)MEM_ALLOC(sizeof(gstmt_t));

	if( ! pstmt )
	{
		PUSHSQLERR( pdbc->herr, en_S1001 );
		return SQL_ERROR;
	}

	pstmt->next = pdbc->stmt;
	pdbc->stmt  = pstmt;

	pstmt->hstmt= hstmt;
	pstmt->hdbc = pdbc;

	return SQL_SUCCESS;
}
예제 #27
0
/*******************************************************************************
 *
 * Vertex array functions.
 *
 ******************************************************************************/
int
rb_create_vertex_array
  (struct rb_context* ctxt,
   struct rb_vertex_array** out_array)
{
  struct rb_vertex_array* array = NULL;

  if(!ctxt || !out_array)
    return -1;

  array = MEM_ALLOC(ctxt->allocator, sizeof(struct rb_vertex_array));
  if(!array)
    return -1;
  ref_init(&array->ref);
  RB(context_ref_get(ctxt));
  array->ctxt = ctxt;

  OGL(GenVertexArrays(1, &array->name));
  *out_array = array;
  return 0;
}
예제 #28
0
static void mg_keep_alive(struct mg_connection* conn, const struct mg_request_info* ri) {
	const char *cl;
	char *buf;
	int len;

	mg_printf(conn, "%s", standard_reply);
	if (strcmp(ri->request_method, "POST") == 0 &&
		(cl = mg_get_header(conn, "Content-Length")) != NULL) {
		len = atoi(cl);
		if ((buf = MEM_ALLOC(len+1)) != NULL) {
			mg_read(conn, buf, len);
			buf[len] = '\0';

			uint id;
			sscanf(buf, "%u", &id); 
			MEM_FREE(buf);

			// Invoke keep_alive
			_invoke("keep_alive_cb", id, NULL);
		}
	}
}
예제 #29
0
static void _precalc_vis(DArray geometry, NavMesh* res) {
	assert(res);

	Segment* segs = DARRAY_DATA_PTR(geometry, Segment);

	res->vis_bitmap = MEM_ALLOC(sizeof(uint) * vis_bitmap_size);
	memset(res->vis_bitmap, 0, sizeof(uint) * vis_bitmap_size);

	for(uint y = 0; y < vis_bitmap_height; ++y) {
		for(uint x = 0; x < vis_bitmap_width; ++x) {
			// Construct corresponding screen rect
			float fx = (float)x;
			float fy = (float)y;
			RectF r = rectf(
				fx * vis_cell_width, fy * vis_cell_height,
				(fx + 1.0f) * vis_cell_width, (fy + 1.0f) * vis_cell_height
			);

			// Check if any wall segment intersects rect
			bool solid = false;
			for(uint i = 0; i < geometry.size; ++i) {
				// Raycast is used as a simple binary check
				Vector2 hitp = rectf_raycast(&r, &segs[i].p1, &segs[i].p2);

				// Float comparison is ok here - see rectf_raycast code
				if(hitp.x != segs[i].p2.x || hitp.y != segs[i].p2.y) {
					solid = true;
					break;
				}	
			}

			// Set bit
			if(solid) {
				uint cell = IDX_2D(x, y, vis_bitmap_width);
				res->vis_bitmap[cell/32] |= (1 << (31 - (cell % 32)));
			}
		}
	}
}
예제 #30
0
static void mg_leave(struct mg_connection* conn, const struct mg_request_info* ri) {
	const char *cl;
	char *buf;
	int len;

	if (strcmp(ri->request_method, "POST") == 0 &&
		(cl = mg_get_header(conn, "Content-Length")) != NULL) {
		len = atoi(cl);
		if ((buf = MEM_ALLOC(len+1)) != NULL) {
			mg_read(conn, buf, len);
			buf[len] = '\0';

			uint id;
			sscanf(buf, "%u", &id); 
			MEM_FREE(buf);

			if(aatree_size(&clients)) {
				aatree_remove(&clients, id);

				// Invoke leave_cb
				_invoke("leave_cb", id, NULL);

				mg_printf(conn, "%s", standard_reply);
				return;
			}
			else {
				goto error;
			}
		}
	}
	else if(strcmp(ri->request_method, "OPTIONS") == 0) {
		mg_printf(conn, "%s", standard_reply);
		return;
	}

error:
	mg_error(conn, ri);
}