Esempio n. 1
0
int
parse_param(void *val, AVP_List** avps) {

    char *p;
    str *s, content;
    AVP_List *mp = NULL;

    //LM_DBG("%.*s\n", content.len, content.s);

    content.s = (char*) val;
    content.len = strlen(content.s);


    p = (char*) pkg_malloc (content.len + 1);
    CHECK_ALLOC(p);

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

    s = (str*) pkg_malloc(sizeof(str));
    CHECK_ALLOC(s);

    for (;*p != '\0';) {

        mp = (AVP_List*) pkg_malloc (sizeof(AVP_List));
        CHECK_ALLOC(mp);
        mp->next = *avps;
        mp->pv = (pv_spec_p) pkg_malloc (sizeof(pv_spec_t));
        CHECK_ALLOC(mp->pv);

        for (; isspace(*p); p++);
        CHECK_COND(*p != '\0');

        mp->name.s = p;

        for(; isgraph(*p) && *p != '='; p++)
            CHECK_COND(*p != '\0');

        mp->name.len = p - mp->name.s;

        for (; isspace(*p); p++);
        CHECK_COND(*p != '\0' && *p == '=');
        p++;

        //LM_DBG("%.*s\n", mp->name.len, mp->name.s);

        for (; isspace(*p); p++);
        CHECK_COND(*p != '\0' && *p == '$');

        s->s = p;
        s->len = strlen(p);

        p = pv_parse_spec(s, mp->pv);

        for (; isspace(*p); p++);
        *avps = mp;
    }

    return 0;
}
void matrix_map_row(matrix_t* mat, const matrix_row_t* row, const offset_t i) {

    if( matrix_row( mat, i ) != NULL ) {
        //printf(" problem, sir" );
        return;
    }

    // allocate space to copy the row
    size_t copy_size =  (mat->num_mapped_rows+1)*sizeof(mapped_row_t);
    mat->mapped_rows = (mapped_row_t*)realloc( mat->mapped_rows, copy_size );
    CHECK_ALLOC( mat->mapped_rows );

    // setup the mapped row
    copy_size = sizeof(matrix_row_t);
    mapped_row_t* mapped_row = &(mat->mapped_rows[mat->num_mapped_rows]);
    mapped_row->i = i;
    memcpy( &(mapped_row->row), row, copy_size );

    assert( row->num_cells >= 0 );
    assert( row->num_cells <= mat->n );

    // allocate space for the copied cells and copy them
    copy_size = row->num_cells * sizeof(cell_t);
    mapped_row->row.cells = (cell_t*)malloc( copy_size );
    CHECK_ALLOC( mapped_row->row.cells );
    memcpy( mapped_row->row.cells, row->cells, copy_size );


    mat->num_mapped_rows++;

    assert( mat->num_mapped_rows <= mat->m - matrix_num_rows( mat ) );
}
Esempio n. 3
0
int parse_sets_func(unsigned int type, void *val) {

	rad_set_elem *elem;
	char *p = (char*) val, *pp = NULL;
	str content;
	int nr;

	elem = (rad_set_elem*) pkg_malloc (sizeof(rad_set_elem));
	CHECK_ALLOC(elem);

	for (; isspace(*p); p++);
	CHECK_COND(*p != '\0');

	elem->set_name.s = p;

	for(;isgraph(*p) && *p != '='; p++)
	CHECK_COND(*p != '\0');

	elem->set_name.len = p - elem->set_name.s;

	for (; isspace(*p); p++);
	CHECK_COND(*p != '\0' && *p == '=');
	p++;

	for (; isspace(*p); p++);
	CHECK_COND(*p != '\0' && *p == '(');
	p++;
	CHECK_COND(*p != '\0');

	elem->parsed = NULL;
	content.s = p;
	nr = 1;

	for (; *p != '\0'; p++) {
		if (*p == '(')
			nr++;
		if (*p == ')')
			pp = p, nr--;
	}

	CHECK_COND(pp && !nr);

	content.len = (pp - content.s) * sizeof(char);
	set_size++;

	sets = (rad_set_elem**) pkg_realloc (sets, set_size * sizeof(rad_set_elem*));
	CHECK_ALLOC(sets);

	sets[set_size - 1] = elem;

	if (parse_set_content(content, elem)) {
		LM_ERR("malformed modparam %.*s\n",sets[set_size - 1]->set_name.len,
				sets[set_size - 1]->set_name.s);
		return -1;
	}

	return 0;
}
Esempio n. 4
0
/*
 * allocates hash tables labels and provides a pointer to the data structure
 * has to be freed using freeSenna
 */
SENNA* sennaCreate(const char * opt_path) {
    SENNA* senna = (SENNA*) malloc(sizeof(SENNA));
    CHECK_ALLOC(senna);

    senna->word_hash = SENNA_Hash_new(opt_path, "hash/words.lst");
    senna->caps_hash = SENNA_Hash_new(opt_path, "hash/caps.lst");
    senna->suff_hash = SENNA_Hash_new(opt_path, "hash/suffix.lst");
    senna->gazt_hash = SENNA_Hash_new(opt_path, "hash/gazetteer.lst");

    senna->gazl_hash = SENNA_Hash_new_with_admissible_keys(opt_path, "hash/ner.loc.lst", "data/ner.loc.dat");
    senna->gazm_hash = SENNA_Hash_new_with_admissible_keys(opt_path, "hash/ner.msc.lst", "data/ner.msc.dat");
    senna->gazo_hash = SENNA_Hash_new_with_admissible_keys(opt_path, "hash/ner.org.lst", "data/ner.org.dat");
    senna->gazp_hash = SENNA_Hash_new_with_admissible_keys(opt_path, "hash/ner.per.lst", "data/ner.per.dat");

    // labels
    senna->pos_hash = SENNA_Hash_new(opt_path, "hash/pos.lst");
    // senna->chk_hash = SENNA_Hash_new(opt_path, "hash/chk.lst");
    // senna->pt0_hash = SENNA_Hash_new(opt_path, "hash/pt0.lst");
    // senna->ner_hash = SENNA_Hash_new(opt_path, "hash/ner.lst");
    // senna->vbs_hash = SENNA_Hash_new(opt_path, "hash/vbs.lst");
    // senna->srl_hash = SENNA_Hash_new(opt_path, "hash/srl.lst");
    senna->psg_left_hash = SENNA_Hash_new(opt_path, "hash/psg-left.lst");
    senna->psg_right_hash = SENNA_Hash_new(opt_path, "hash/psg-right.lst");

    senna->pos = SENNA_POS_new(opt_path, "data/pos.dat");
    // senna->chk = SENNA_CHK_new(opt_path, "data/chk.dat");
    // senna->pt0 = SENNA_PT0_new(opt_path, "data/pt0.dat");
    // senna->ner = SENNA_NER_new(opt_path, "data/ner.dat");
    // senna->vbs = SENNA_VBS_new(opt_path, "data/vbs.dat");
    // senna->srl = SENNA_SRL_new(opt_path, "data/srl.dat");
    senna->psg = SENNA_PSG_new(opt_path, "data/psg.dat");

    senna->tokenizer = SENNA_Tokenizer_new(
                           senna->word_hash,
                           senna->caps_hash,
                           senna->suff_hash,
                           senna->gazt_hash,
                           senna->gazl_hash,
                           senna->gazm_hash,
                           senna->gazo_hash,
                           senna->gazp_hash,
                           0);

    senna->lastSentence.tokens = NULL;
    senna->lastSentence.pos_labels = NULL;
    senna->lastSentence.psg_labels = NULL;

    senna->strbuf.ptr = (char *) malloc(sizeof(char) * 512);
    CHECK_ALLOC(senna->strbuf.ptr);
    senna->strbuf.length = 512;
    senna->strbuf.pos = 0;

    return senna;
}
Esempio n. 5
0
blargg_err_t Nes_Cart::load_patched_ines( Auto_File_Reader in, Auto_File_Reader patch )
{
	RETURN_ERR( in.open() );
	RETURN_ERR( patch.open() );
	
	// read file into memory
	long size = in->remain();
	byte* ines = (byte*) malloc( size );
	CHECK_ALLOC( ines );
	const char* err = in->read( ines, size );
	
	// apply patch
	if ( !err )
		err = apply_ips_patch( *patch, &ines, &size );
	
	// load patched file
	if ( !err )
	{
		Mem_File_Reader patched( ines, size );
		err = load_ines( patched );
	}
	
	free( ines );
	
	return err;
}
Esempio n. 6
0
CVisualPin* CVisualNode::AddPin(bool fInput, LONG_PTR pData, const CAtlStringW& strLabel, int nPinId)
{
    HRESULT hr;
    CVisualPin* pPin = new CVisualPin(this, 
                            CVisualRect(0, 0, PIN_WIDTH, PIN_HEIGHT), 
                            (fInput) ? CVisualObject::INPUT : CVisualObject::OUTPUT, strLabel, nPinId);
    CHECK_ALLOC( pPin );
    
    pPin->SetData(pData);

    if(fInput)
    {
        m_InputPins.Add(pPin);
    }
    else
    {
        m_OutputPins.Add(pPin);
    }

    pPin->SetHandler(ms_pPinHandler);
   
    RecalcPins();

Cleanup:
    return pPin;
}
Esempio n. 7
0
File: gme.cpp Progetto: kode54/Cog
gme_err_t gme_set_track_info( Music_Emu * me, gme_info_t* in, int track )
{
	track_info_t* info = BLARGG_NEW track_info_t;
	CHECK_ALLOC( info );
	
#define COPY(name) info->name = in->name;
	
	COPY( length );
	COPY( intro_length );
	COPY( loop_length );
	
#undef COPY
#define COPY(name) if ( in->name ) strncpy( info->name, in->name, sizeof(info->name) - 1 ), info->name[sizeof(info->name)-1] = '\0'; else info->name[0] = '\0';
    
	COPY( system );
	COPY( game );
	COPY( song );
	COPY( author );
	COPY( copyright );
	COPY( comment );
	COPY( dumper );
	
#undef COPY
	
	blargg_err_t err = me->set_track_info( info, track );
    
    delete info;
    
    return err;
}
Esempio n. 8
0
static int
http_client_on_header_value(struct http_parser *p, const char *at, size_t sz) {

	struct http_client *c = p->data;
	size_t n = c->header_count;

	/* Add data to the current header value. */
	CHECK_ALLOC(c, c->headers[n-1].val = realloc(c->headers[n-1].val,
			c->headers[n-1].val_sz + sz + 1));
	memcpy(c->headers[n-1].val + c->headers[n-1].val_sz, at, sz);
	c->headers[n-1].val_sz += sz;
	c->headers[n-1].val[c->headers[n-1].val_sz] = 0;

	c->last_cb = LAST_CB_VAL;


	/* react to some values. */
	if(strncmp("Expect", c->headers[n-1].key, c->headers[n-1].key_sz) == 0) {
		if(sz == 12 && strncasecmp(at, "100-continue", sz) == 0) {
			/* support HTTP file upload */
			char http100[] = "HTTP/1.1 100 Continue\r\n\r\n";
			int ret = write(c->fd, http100, sizeof(http100)-1);
			(void)ret;
		}
	} else if(strncasecmp("Connection", c->headers[n-1].key, c->headers[n-1].key_sz) == 0) {
		if(sz == 10 && strncasecmp(at, "Keep-Alive", sz) == 0) {
			c->keep_alive = 1;
		}
	}

	return 0;
}
Esempio n. 9
0
blargg_err_t Nes_Blitter::init()
{
	CHECK_ALLOC( ntsc = (nes_ntsc_emph_t*) malloc( sizeof *ntsc ) );
	static setup_t const s = { };
	setup_ = s;
	setup_.ntsc = nes_ntsc_composite;
	return setup( setup_ );
}
Esempio n. 10
0
void comm_schedule_init( comm_schedule_t* schedule, MPI_Comm comm ) {
    rank_t p, r;
    MPI_CALL( MPI_Comm_size(comm, &p) );
    MPI_CALL( MPI_Comm_rank(comm, &r) );

    schedule->comm = comm;

    schedule->map_size = p*p*sizeof(offset_t);
    schedule->comm_map = (offset_t*)malloc( schedule->map_size );
    CHECK_ALLOC( schedule->comm_map );
    memset( schedule->comm_map, 0, schedule->map_size );

    schedule->map_size = p*sizeof(offset_t*);
    schedule->recv_cols = (offset_t**)malloc( schedule->map_size );
    CHECK_ALLOC(schedule->recv_cols);
    memset( schedule->recv_cols, 0, schedule->map_size );
}
Esempio n. 11
0
static blargg_err_t new_opl_apu( Opl_Apu::type_t type, Opl_Apu** out )
{
	check( !*out );
	CHECK_ALLOC( *out = BLARGG_NEW( Opl_Apu ) );
	blip_time_t const period = 72;
	int const rate = clock_rate / period;
	return (*out)->init( rate * period, rate, period, type );
}
Esempio n. 12
0
void matrix_deserialize( matrix_t* mat, const char* buf ) {
    size_t offset = 0;
    size_t copy_size = 0;
    // copy matrix
    copy_size = sizeof(matrix_t);
    memcpy( mat, buf, copy_size );
    offset += copy_size;

    // explicitly set this null to avoid problems.
    mat->num_mapped_rows = 0;
    mat->mapped_rows = NULL;

    LOG(LOG_DEBUG, "deserializing matrix... from_i=%lu, to_i=%lu. #=%lu\n", mat->from_i, mat->to_i, matrix_num_rows(mat) );

    // copy rows
    copy_size = matrix_num_rows(mat) * sizeof(matrix_row_t);
    mat->rows = (matrix_row_t*)malloc( copy_size );
    CHECK_ALLOC( mat->rows );
    memset( mat->rows, 0, copy_size );

    memcpy( matrix_row(mat, mat->from_i), buf + offset, copy_size );
    offset += copy_size;

    LOG(LOG_DEBUG, "deserializing matrix... from_i=%lu, to_i=%lu\n", mat->from_i, mat->to_i );

    // copy cells of each row
    offset_t i;
    for( i = mat->from_i; i <= mat->to_i; i++ ) {

        matrix_row_t* row = matrix_row(mat, i);

        assert( row != NULL );
        assert( row->num_cells <= mat->n );


        LOG(LOG_DEBUG, "(%lu) has %lu\n", i, row->num_cells);

        if( row->num_cells > 0 ) {
            copy_size = row->num_cells * sizeof(cell_t);
            row->cells = (cell_t*)malloc( copy_size );
            CHECK_ALLOC( row->cells );
            memcpy( row->cells, buf + offset, row->num_cells * sizeof(cell_t) );
            offset += copy_size;
        }
    }
}
Esempio n. 13
0
blargg_err_t Nes_Vrc7_Apu::init()
{
    CHECK_ALLOC( opll = ym2413_init( 3579545, 3579545 / 72, 1 ) );

    set_output( 0 );
    volume( 1.0 );
    reset();
    return 0;
}
Esempio n. 14
0
const char * Nes_State_Writer::end( Nes_Emu const& emu )
{
    Nes_State* state = BLARGG_NEW Nes_State;
    CHECK_ALLOC( state );
    emu.save_state( state );
    const char * err = end( *state );
    delete state;
    return err;
}
Esempio n. 15
0
blargg_err_t Nes_Emu::save_state( Auto_File_Writer out ) const
{
    Nes_State* state = BLARGG_NEW Nes_State;
    CHECK_ALLOC( state );
    save_state( state );
    blargg_err_t err = state->write( out );
    delete state;
    return err;
}
// avoid using new []
blargg_err_t Effects_Buffer::new_bufs( int size )
{
    bufs = (buf_t*) malloc( size * sizeof *bufs );
    CHECK_ALLOC( bufs );
    for ( int i = 0; i < size; i++ )
        new (bufs + i) buf_t;
    bufs_size = size;
    return 0;
}
Esempio n. 17
0
/** Allocate a new memory pool to hold items of size <b>item_size</b>. We'll
 * try to fit about <b>chunk_capacity</b> bytes in each chunk. */
mp_pool_t *
mp_pool_new(size_t item_size, size_t chunk_capacity)
{
  mp_pool_t *pool;
  size_t alloc_size, new_chunk_cap;

  tor_assert(item_size < SIZE_T_CEILING);
  tor_assert(chunk_capacity < SIZE_T_CEILING);
  tor_assert(SIZE_T_CEILING / item_size > chunk_capacity);

  pool = ALLOC(sizeof(mp_pool_t));
  CHECK_ALLOC(pool);
  memset(pool, 0, sizeof(mp_pool_t));

  /* First, we figure out how much space to allow per item.  We'll want to
   * use make sure we have enough for the overhead plus the item size. */
  alloc_size = (size_t)(STRUCT_OFFSET(mp_allocated_t, u.mem) + item_size);
  /* If the item_size is less than sizeof(next_free), we need to make
   * the allocation bigger. */
  if (alloc_size < sizeof(mp_allocated_t))
    alloc_size = sizeof(mp_allocated_t);

  /* If we're not an even multiple of ALIGNMENT, round up. */
  if (alloc_size % ALIGNMENT) {
    alloc_size = alloc_size + ALIGNMENT - (alloc_size % ALIGNMENT);
  }
  if (alloc_size < ALIGNMENT)
    alloc_size = ALIGNMENT;
  ASSERT((alloc_size % ALIGNMENT) == 0);

  /* Now we figure out how many items fit in each chunk.  We need to fit at
   * least 2 items per chunk. No chunk can be more than MAX_CHUNK bytes long,
   * or less than MIN_CHUNK. */
  if (chunk_capacity > MAX_CHUNK)
    chunk_capacity = MAX_CHUNK;
  /* Try to be around a power of 2 in size, since that's what allocators like
   * handing out. 512K-1 byte is a lot better than 512K+1 byte. */
  chunk_capacity = (size_t) round_to_power_of_2(chunk_capacity);
  while (chunk_capacity < alloc_size * 2 + CHUNK_OVERHEAD)
    chunk_capacity *= 2;
  if (chunk_capacity < MIN_CHUNK)
    chunk_capacity = MIN_CHUNK;

  new_chunk_cap = (chunk_capacity-CHUNK_OVERHEAD) / alloc_size;
  tor_assert(new_chunk_cap < INT_MAX);
  pool->new_chunk_capacity = (int)new_chunk_cap;

  pool->item_alloc_size = alloc_size;

  log_debug(LD_MM, "Capacity is %lu, item size is %lu, alloc size is %lu",
            (unsigned long)pool->new_chunk_capacity,
            (unsigned long)pool->item_alloc_size,
            (unsigned long)(pool->new_chunk_capacity*pool->item_alloc_size));

  return pool;
}
Esempio n. 18
0
blargg_err_t Nes_Emu::load_state( Auto_File_Reader in )
{
    Nes_State* state = BLARGG_NEW Nes_State;
    CHECK_ALLOC( state );
    blargg_err_t err = state->read( in );
    if ( !err )
        load_state( *state );
    delete state;
    return err;
}
Esempio n. 19
0
int
http_client_add_to_body(struct http_client *c, const char *at, size_t sz) {

	CHECK_ALLOC(c, c->body = realloc(c->body, c->body_sz + sz + 1));
	memcpy(c->body + c->body_sz, at, sz);
	c->body_sz += sz;
	c->body[c->body_sz] = 0;

	return 0;
}
Esempio n. 20
0
char *get_device_name(cl_device_id device) {
    size_t name_len;
    CHECK(clGetDeviceInfo(device, CL_DEVICE_NAME, 0, NULL, &name_len));
    char *device_name = (char *)malloc(name_len + 1);
    CHECK_ALLOC(device_name);
    CHECK(clGetDeviceInfo(device, CL_DEVICE_NAME, name_len, device_name,
                NULL));
    device_name[name_len] = '\0';
    return device_name;
}
Esempio n. 21
0
blargg_err_t Sms_Fm_Apu::init( double clock_rate, double sample_rate )
{
	period_ = clock_rate / sample_rate + 0.5;
	CHECK_ALLOC( !apu.set_rate( sample_rate, clock_rate ) );
	
	set_output( 0 );
	volume( 1.0 );
	reset();
	return blargg_ok;
}
Esempio n. 22
0
blargg_err_t Classic_Emu::set_sample_rate_( long rate )
{
	if ( !buf )
	{
		if ( !stereo_buffer )
			CHECK_ALLOC( stereo_buffer = BLARGG_NEW Stereo_Buffer );
		buf = stereo_buffer;
	}
	return buf->set_sample_rate( rate, 1000 / 20 );
}
Esempio n. 23
0
blargg_err_t Nes_Cart::resize_chr( long size )
{
	if ( size != chr_size_ )
	{
		void* p = realloc( chr_, round_to_bank_size( size ) );
		CHECK_ALLOC( p || !size );
		chr_ = (byte*) p;
		chr_size_ = size;
	}
	return 0;
}
Esempio n. 24
0
const char * Nes_State_Reader::begin( Auto_File_Reader dr, Nes_State* out )
{
    state_ = out;
    if ( !out )
        CHECK_ALLOC( state_ = owned = BLARGG_NEW Nes_State );

    RETURN_ERR( Nes_File_Reader::begin( dr ) );
    if ( block_tag() != state_file_tag )
        return "Not a state snapshot file";
    return 0;
}
Esempio n. 25
0
blargg_err_t Nes_Vrc7_Apu::init()
{
	CHECK_ALLOC( opll = OPLL_new( 3579545, 3579545 / 72 ) );
	OPLL_SetChipMode((OPLL *) opll, 1);
	OPLL_setPatch((OPLL *) opll, vrc7_inst);

	set_output( 0 );
	volume( 1.0 );
	reset();
	return 0;
}
Esempio n. 26
0
const char * Nes_Core::init()
{
	if ( !impl )
	{
		CHECK_ALLOC( impl = BLARGG_NEW impl_t );
		impl->apu.dmc_reader( read_dmc, this );
		impl->apu.irq_notifier( apu_irq_changed, this );
	}
	
	return 0;
}
Esempio n. 27
0
static int
http_client_on_url(struct http_parser *p, const char *at, size_t sz) {

	struct http_client *c = p->data;

	CHECK_ALLOC(c, c->path = realloc(c->path, c->path_sz + sz + 1));
	memcpy(c->path + c->path_sz, at, sz);
	c->path_sz += sz;
	c->path[c->path_sz] = 0;

	return 0;
}
Esempio n. 28
0
/*
 *  appTeardown()
 *
 *    Teardown all modules, close all files, and tidy up all
 *    application state.
 *
 *    This function is idempotent.
 */
static void
appTeardown(
    void)
{
    static int teardownFlag = 0;
    RBLIST *iter;
    transfer_t *sndr;

    if (teardownFlag) {
        return;
    }
    teardownFlag = 1;

    if (!daemonized) {
        rbdestroy(transfers);
        skDLListDestroy(duplicate_dirs);
        skDLListDestroy(open_file_list);
        skdaemonTeardown();
        skAppUnregister();
        return;
    }

    NOTICEMSG("Begin shutting down...");

    shuttingdown = 1;

    transferShutdown();
    transferTeardown();

    /* Destroy stuff */
    iter = rbopenlist(transfers);
    CHECK_ALLOC(iter);
    while ((sndr = (transfer_t *)rbreadlist(iter)) != NULL) {
        if (sndr->ident != NULL) {
            free(sndr->ident);
        }
        if (sndr->addr) {
            skSockaddrArrayDestroy(sndr->addr);
        }
        free(sndr);
    }
    rbcloselist(iter);
    rbdestroy(transfers);

    skDLListDestroy(duplicate_dirs);
    skDLListDestroy(open_file_list);

    NOTICEMSG("Finished shutting down.");

    skdaemonTeardown();
    skthread_teardown();
    skAppUnregister();
}
Esempio n. 29
0
static blargg_err_t apply_ips_patch( Data_Reader& patch, byte** file, long* file_size )
{
	byte signature [5];
	RETURN_ERR( patch.read( signature, sizeof signature ) );
	if ( memcmp( signature, "PATCH", sizeof signature ) )
		return "Not an IPS patch file";
	
	while ( patch.remain() )
	{
		// read offset
		byte buf [6];
		RETURN_ERR( patch.read( buf, 3 ) );
		long offset = buf [0] * 0x10000 + buf [1] * 0x100 + buf [2];
		if ( offset == 0x454F46 ) // 'EOF'
			break;
		
		// read size
		RETURN_ERR( patch.read( buf, 2 ) );
		long size = buf [0] * 0x100 + buf [1];
		
		// size = 0 signals a run of identical bytes
		int fill = -1;
		if ( size == 0 )
		{
			RETURN_ERR( patch.read( buf, 3 ) );
			size = buf [0] * 0x100 + buf [1];
			fill = buf [2];
		}
		
		// expand file if new data is at exact end of file
		if ( offset == *file_size )
		{
			*file_size = offset + size;
			void* p = realloc( *file, *file_size );
			CHECK_ALLOC( p );
			*file = (byte*) p;
		}
		
		//dprintf( "Patch offset: 0x%04X, size: 0x%04X\n", (int) offset, (int) size );
		
		if ( offset < 0 || *file_size < offset + size )
			return "IPS tried to patch past end of file";
		
		// read/fill data
		if ( fill < 0 )
			RETURN_ERR( patch.read( *file + offset, size ) );
		else
			memset( *file + offset, fill, size );
	}
	
	return 0;
}
Esempio n. 30
0
static void connection_cb(uv_stream_t* s, int status) {
  int err;
  conn_t* conn;

  CHECK_ALLOC(conn = malloc(sizeof(*conn)));

  CHECK(uv_tcp_init(uv_default_loop(), &conn->tcp));
  CHECK(uv_accept(s, (uv_stream_t*) &conn->tcp));
  CHECK(uv_link_source_init(&conn->source, (uv_stream_t*) &conn->tcp));
  CHECK(uv_link_observer_init(&conn->observer));

  CHECK_ALLOC(conn->http = uv_http_create(request_cb, &err));
  CHECK(err);
  CHECK(uv_link_chain((uv_link_t*) &conn->source, (uv_link_t*) conn->http));
  CHECK(uv_link_chain((uv_link_t*) conn->http,
                      (uv_link_t*) &conn->observer));

  conn->observer.observer_read_cb = read_cb;
  conn->observer.data = conn;

  CHECK(uv_link_read_start((uv_link_t*) &conn->observer));
}