Exemplo n.º 1
0
void do_tests() {
#ifndef __NO_BUFFER_TYPE__
    int i = random(100000);
    
    ASSERT(sizeof(allocate_buffer(i)) == i);
    ASSERT(catch(allocate_buffer(-20)));
#endif
}
Exemplo n.º 2
0
// Allocates all of the field buffers
void kernel_initialise(
        Settings* settings, int x, int y, KView* density0, 
        KView* density, KView* energy0, KView* energy, KView* u, 
        KView* u0, KView* p, KView* r, KView* mi, 
        KView* w, KView* kx, KView* ky, KView* sd, 
        KView* volume, KView* x_area, KView* y_area, KView* cell_x, 
        KView* cell_y, KView* cell_dx, KView* cell_dy, KView* vertex_dx, 
        KView* vertex_dy, KView* vertex_x, KView* vertex_y, KView* comms_buffer,
        Kokkos::View<double*>::HostMirror* host_comms_mirror, 
        double** cg_alphas, double** cg_betas, double** cheby_alphas, 
        double** cheby_betas)
{
    print_and_log(settings,
            "Performing this solve with the Kokkos Functors %s solver\n",
            settings->solver_name);

    Kokkos::initialize();

    new(density0) KView("density0", x*y);
    new(density) KView("density", x*y);
    new(energy0) KView("energy0", x*y);
    new(energy) KView("energy", x*y);
    new(u) KView("u", x*y);
    new(u0) KView("u0", x*y);
    new(p) KView("p", x*y);
    new(r) KView("r", x*y);
    new(mi) KView("mi", x*y);
    new(w) KView("w", x*y);
    new(kx) KView("kx", x*y);
    new(ky) KView("ky", x*y);
    new(sd) KView("sd", x*y);
    new(volume) KView("volume", x*y);
    new(x_area) KView("x_area", (x+1)*y);
    new(y_area) KView("y_area", x*(y+1));
    new(cell_x) KView("cell_x", x);
    new(cell_y) KView("cell_y", y);
    new(cell_dx) KView("cell_dx", x);
    new(cell_dy) KView("cell_dy", y);
    new(vertex_dx) KView("vertex_dx", (x+1));
    new(vertex_dy) KView("vertex_dy", (y+1));
    new(vertex_x) KView("vertex_x", (x+1));
    new(vertex_y) KView("vertex_y", (y+1));

    new(comms_buffer) KView("comms_buffer", MAX(x, y)*settings->halo_depth);
    new(host_comms_mirror) KView::HostMirror(); 
    *host_comms_mirror = Kokkos::create_mirror_view(*comms_buffer);

    allocate_buffer(cg_alphas, settings->max_iters, 1);
    allocate_buffer(cg_betas, settings->max_iters, 1);
    allocate_buffer(cheby_alphas, settings->max_iters, 1);
    allocate_buffer(cheby_betas, settings->max_iters, 1);
}
Exemplo n.º 3
0
void process(const YV12Image &in_data, const YV12Image &out_data)
{
	// (1) Fill the format descriptors for the top and bottom fields. The same
	// context can not be used for both fields, as they are located at opposite
	// offsets from the image center. If the fields were to be scaled as
	// progressive-scan images of half height, spatial misalignment of the
	// output would occur.
	zimgxx::zimage_format in_format_t = get_image_format(in_data, true);
	zimgxx::zimage_format in_format_b = get_image_format(in_data, false);
	zimgxx::zimage_format out_format_t = get_image_format(out_data, true);
	zimgxx::zimage_format out_format_b = get_image_format(out_data, false);

	// (2) Build the processing contexts.
	zimgxx::FilterGraph graph_t{ zimgxx::FilterGraph::build(in_format_t, out_format_t) };
	zimgxx::FilterGraph graph_b{ zimgxx::FilterGraph::build(in_format_b, out_format_b) };

	// (3) Allocate scanline and temporary buffers for input and output data. In
	// this case, the same buffers can be used for both fields.
	unsigned input_buffering_t = graph_t.get_input_buffering();
	unsigned input_buffering_b = graph_b.get_input_buffering();
	unsigned output_buffering_t = graph_t.get_input_buffering();
	unsigned output_buffering_b = graph_b.get_input_buffering();
	size_t tmp_size_t = graph_t.get_tmp_size();
	size_t tmp_size_b = graph_b.get_tmp_size();

	std::cout << "input buffering:  " << std::max(input_buffering_t, input_buffering_b) << '\n';
	std::cout << "output buffering: " << std::max(output_buffering_t, output_buffering_b) << '\n';
	std::cout << "heap usage: " << std::max(tmp_size_t, tmp_size_b) << '\n';

	auto in_buf = allocate_buffer(in_format_t, std::max(input_buffering_t, input_buffering_b));
	auto out_buf = allocate_buffer(out_format_t, std::max(output_buffering_t, output_buffering_b));
	auto tmp_buf = allocate_buffer(std::max(tmp_size_t, tmp_size_b));

	// (4) Store context information required by the I/O callbacks. The
	// callbacks convert between the on-disk and z.lib alignment requirements.
	Callback unpack_data = { &in_buf.first, &in_data, false, true };
	Callback pack_data = { &out_buf.first, &out_data, true, true };

	// (5) Process the top field.
	graph_t.process(in_buf.first.as_const(), out_buf.first, tmp_buf.get(),
	                yv12_bitblt_callback, &unpack_data, yv12_bitblt_callback, &pack_data);

	// (6) Process the bottom field.
	unpack_data.top_field = false;
	pack_data.top_field = false;

	graph_b.process(in_buf.first.as_const(), out_buf.first, tmp_buf.get(),
	                yv12_bitblt_callback, &unpack_data, yv12_bitblt_callback, &pack_data);
}
Exemplo n.º 4
0
static void
send_data(void)
{
  char buf[MAX_PAYLOAD_LEN];

  if (init_buffer(COAP_DATA_BUFF_SIZE)) {
    int data_size = 0;
    coap_packet_t* request = (coap_packet_t*)allocate_buffer(sizeof(coap_packet_t));
    init_packet(request);

    coap_set_method(request, COAP_POST);
    request->tid = xact_id++;
    request->type = MESSAGE_TYPE_NON;
    coap_set_header_uri(request, service_url);

    data_size = serialize_packet(request, buf);

//    PRINTF("Client sending request to:[");
//    PRINT6ADDR(&client_conn->ripaddr);
//    PRINTF("]:%u/%s\n", (uint16_t)REMOTE_PORT, service_urls[service_id]);
    uip_udp_packet_send(client_conn, buf, data_size);

    delete_buffer();
  }
}
Exemplo n.º 5
0
BOOL CHistory::load_from_file(LPTSTR filename, OUT FILETIME* pass_last_modified)
{
	CFileM file(filename, OPEN_EXISTING);
	if (INVALID_HANDLE_VALUE == file.m_h_file)
		return FALSE;
	
// file format
//	| _g_pass_no		|
//	| m_page_amount		|
//	| m_length			|
//	| m_cursor			|
//	| m_cursor_initial	|
//  | history data		|
	init(TRUE);
	file.set_file_pointer(0);
	file.read(&_g_pass_no,			sizeof(INT));
	file.read(pass_last_modified,	sizeof(FILETIME));
	file.read(&m_page_amount,		sizeof(INT));
	file.read(&m_length,			sizeof(INT));
	file.read(&m_cursor,			sizeof(INT));
	file.read(&m_cursor_initial,	sizeof(INT));
	m_cursor_initial	= m_length - 1;
	m_cursor			= -1;
	allocate_buffer();

	for (INT i = 0; i < m_page_amount; i ++)
	{
		file.read(*(m_pp_data + i), HISTORY_PAGE_SIZE * sizeof(HISTORY_ENTRY));
	}
	return TRUE;
}
Exemplo n.º 6
0
el_blob::el_blob(int size, int en, int id, uint32_t buf_size):
	_var_size(false), _true_size(size), _sp_buffer(NULL)
{
	/* Set variables defined in parent */
	_size = 1; /* This is size for flush function */
	_buffer = NULL;
	_filled = 0;

	if (size == 65535) { /* Element with variable size */
		_var_size = true;
	}

	setName(en, id);
	this->set_type();

	if (buf_size == 0) {
		 buf_size = RESERVED_SPACE;
	}

	allocate_buffer(buf_size);

	/* Allocate the sp buffer */
	_sp_buffer_size = buf_size;
	_sp_buffer = (char *) realloc(_sp_buffer, _sp_buffer_size);
	if (_sp_buffer == NULL) {
		MSG_ERROR(MSG_MODULE, "Memory allocation failed!");
	}
	/* Fill the offset of first element */
	*(uint64_t *) _sp_buffer = 0;
	_sp_buffer_offset = 8; /* 8 byte numbers are used to record offset */
}
Exemplo n.º 7
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _bootloader_list_image
* Returned Value   : 
* Comments         :
*    
*
*END*----------------------------------------------------------------------*/
boolean _bootloader_check_image(boolean autoboot, uint_32 index)
{
   uchar_ptr           read_buffer;
   MQX_FILE_PTR        nandflash_hdl;
   IMAGE_INFO_PTR      image;
   uint_32             i,image_num = 0;
   
   /* Open the flash device */
   read_buffer = allocate_buffer(IMAGE_TABLE_SIZE, "read");
   nandflash_hdl = fopen("nandflash:", NULL);
   if (nandflash_hdl == NULL) {
        printf("\nUnable to open NAND flash device");
        return FALSE;
   }
   image = (IMAGE_INFO_PTR)read_buffer;
   
   fseek(nandflash_hdl, IMAGE_TABLE_PAGE_LOCATION, IO_SEEK_SET);
   read(nandflash_hdl, read_buffer,IMAGE_TABLE_SIZE/NAND_FLASH_PAGE_SIZE);
   while(image->IS_IMAGE == IMAGE_IN_TABLE_MASK) {
      if(autoboot&&image->BOOT_DEFAULT) {
         return TRUE;
      }
      else
      if(index == image->INDEX) {
         return TRUE;
      }
      image++;
   }
   
   fclose(nandflash_hdl);
   free(read_buffer);
   return FALSE;
}
Exemplo n.º 8
0
static
void send_data()
{
  int data_size = 0;
  static unsigned temperature;

  temperature = 21;
  clear_buffer(outputBuffer);
  clear_buffer(payload_buf);
  generate_payload(payload_buf,temperature);

  if(init_buffer(COAP_DATA_BUFF_SIZE)){
    coap_packet_t* request =\
    (coap_packet_t*)allocate_buffer(sizeof(coap_packet_t));
    init_packet(request);
    coap_set_method(request, COAP_POST);
    request->tid = xact_id++;
    request->type = MESSAGE_TYPE_CON;
    coap_set_header_uri(request,service_uri);
    coap_set_option(request, Option_Type_Uri_Host,
      sizeof(char)*strlen(server_ip), (uint8_t*)server_ip);
    coap_set_option(request, Option_Type_Proxy_Uri,
    sizeof(char)*strlen(proxy_uri), (uint8_t*)proxy_uri);
    coap_set_payload(request,(uint8_t*)payload_buf,
    sizeof(char)*strlen(payload_buf));
    data_size = serialize_packet(request, (uint8_t*)outputBuffer);

    PRINTF("Now sending request to base station [");
    PRINTF(&client_conn->ripaddr);
    PRINTF("]:%u/%s\n",REMOTE_PORT,service_uri);
    uip_udp_packet_send(client_conn, outputBuffer, data_size);
    delete_buffer();
  }
}
Exemplo n.º 9
0
static int hbootctrl_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) {
	int ret;
	int handle;
	struct hboot_buffer_req buf_req;

	ret = 0;
	switch (cmd) {
		case HBOOT_ALLOCATE_BUFFER:
			if (copy_from_user((void*)&buf_req, (void*)arg, sizeof(struct hboot_buffer_req)) != 0) {
				return -EINVAL;
			}
			ret = allocate_buffer(buf_req.tag, buf_req.type, buf_req.attrs, buf_req.size, buf_req.rest);
			break;
		case HBOOT_FREE_BUFFER:
			handle = (int)arg;
			ret = free_buffer(handle);
			break;
		case HBOOT_SELECT_BUFFER:
			handle = (int)arg;
			ret = select_buffer(handle);
			if (ret >= 0) {
				file->f_pos = 0;
			}
			break;
		case HBOOT_BOOT:
			handle = (int)arg;
			ret = hboot_boot(handle);
			break;
		default:
			ret = -EINVAL;
			break;
	}
	return ret;
}
Exemplo n.º 10
0
void f_compress (void)
{
   unsigned char* buffer;
   unsigned char* input;
   int size;
   buffer_t* real_buffer;
   uLongf new_size;

   if (sp->type == T_STRING) {
      size = SVALUE_STRLEN(sp);
      input = (unsigned char*)sp->u.string;
   } else if (sp->type == T_BUFFER) {
      size = sp->u.buf->size;
      input = sp->u.buf->item;
   } else {
      pop_n_elems(st_num_arg);
      push_undefined();
      return ;
   }

   new_size = size;
   // Make it a little larger as specified in the docs.
   buffer = (unsigned char*)DXALLOC(size * 101 / 100 + 12, TAG_TEMPORARY, "compress");
   compress(buffer, &new_size, input, size);

   // Shrink it down.
   pop_n_elems(st_num_arg);
   real_buffer = allocate_buffer(new_size);
   write_buffer(real_buffer, 0, (char *)buffer, new_size);
   FREE(buffer);
   push_buffer(real_buffer);
}
Exemplo n.º 11
0
int sc_plugin_interface::buffer_alloc_read_channels(uint32_t index, const char * filename, uint32_t start,
                                                    uint32_t frames, uint32_t channel_count,
                                                    const uint32_t * channel_data)
{
    SndfileHandle f(filename);
    if (!f)
        return -1; /* file cannot be opened */

    uint32_t sf_channels = uint32_t(f.channels());
    const uint32_t * max_chan = std::max_element(channel_data, channel_data + channel_count);
    if (*max_chan >= sf_channels)
        return -2;

    const size_t sf_frames = f.frames();

    if (start > sf_frames)
        start = sf_frames;

    if (frames == 0 || frames > sf_frames - start)
        frames = sf_frames - start;

    SndBuf * buf = World_GetNRTBuf(&world, index);
    allocate_buffer(buf, frames, channel_count, f.samplerate());

    f.seek(start, SEEK_SET);
    read_channel(f, channel_count, channel_data, frames, buf->data);

    return 0;
}
Exemplo n.º 12
0
XCamReturn
V4l2Device::init_buffer_pool ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    uint32_t i = 0;

    _buf_pool.clear ();
    _buf_pool.reserve (_buf_count);

    for (; i < _buf_count; i++) {
        SmartPtr<V4l2Buffer> new_buf;
        ret = allocate_buffer (new_buf, _format, i);
        if (ret != XCAM_RETURN_NO_ERROR) {
            break;
        }
        _buf_pool.push_back (new_buf);
    }

    if (_buf_pool.empty()) {
        XCAM_LOG_ERROR ("No bufer allocated in device(%s)", XCAM_STR (_name));
        return XCAM_RETURN_ERROR_MEM;
    }

    if (i != _buf_count) {
        XCAM_LOG_WARNING (
            "device(%s) allocate buffer count:%d failback to %d",
            XCAM_STR (_name), _buf_count, i);
        _buf_count = i;
    }

    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 13
0
static connection_data *allocate_connection(int client_fd)
{
    connection_data* connection = (connection_data*) callocate(pool, sizeof(connection_data));
    connection->fd = client_fd;
    allocate_buffer(&connection->data);
    return connection;
}
Exemplo n.º 14
0
ssize_t
fwrite(const void *ptr, size_t size, FILE *stream)
{
    ssize_t ret = 0;
    size_t bytes_tx, buffered, whole_chunks;
    const unsigned char *ptr_ = ptr;

    if (size > SSIZE_MAX || stream->mode != WRITE)
        return EXIT_FAILURE;

    if (size == 0)
        return ret;

    // Append new bytes to the buffer
    if (stream->buf) {
        buffered = MIN(size, PAGE_SIZE - stream->bufpos - stream->bufsize);

        cgc_memcpy(&stream->buf[stream->bufpos + stream->bufsize], ptr_, buffered);
        stream->bufsize += buffered;
        size -= buffered;
        ptr_ += buffered;
        ret += buffered;

        if (size == 0)
            return ret;

        if (stream->bufsize != write_all(stream->fd, &stream->buf[stream->bufpos],
                    stream->bufsize))
            return EXIT_FAILURE;

        stream->bufsize = 0;
        stream->bufpos = 0;
    }

    // Write whole chunks
    if (size >= PAGE_SIZE) {
        whole_chunks = size & ~(PAGE_SIZE - 1);

        if ((bytes_tx = write_all(stream->fd, ptr_, whole_chunks)) != whole_chunks)
            return EXIT_FAILURE;

        size &= PAGE_SIZE - 1;
        ptr_ += whole_chunks;
        ret += whole_chunks;

        if (size == 0)
            return ret;
    }

    // Buffer the remainder
    if (!stream->buf && allocate_buffer(stream) != EXIT_SUCCESS)
        return EXIT_FAILURE;

    cgc_memcpy(stream->buf, ptr_, size);
    stream->bufsize = size;
    ret += size;

    return ret;
}
Exemplo n.º 15
0
int main(int argc, char** argv)
{
  allocate_buffer();
#ifdef CONFIG_KPROBES
  *buffer = 'a'; // ERROR
#endif
   return 0;
}
Exemplo n.º 16
0
	density_mask(int width, int height):
		m_width(width),
		m_height(height),
		m_buffer(allocate_buffer(width, height)),
		m_rbuf(m_buffer, width, height, width),
		m_pixf(m_rbuf)
	{
	}
Exemplo n.º 17
0
void SendReply(class SnmpMessage Reply)
{
  buffer ReplyBuf, RealReplyBuf, tmpbuf;
  int i,j,k,l,m;
  ReplyBuf=allocate_buffer(500);
  ReplyBuf[0]=SEQUENCE;
  ReplyBuf[1]=0;
  ReplyBuf[2]=INTEGER;
  ReplyBuf[3]=1;
  ReplyBuf[4]=Reply->version;
  ReplyBuf[5]=OCTET_STRING;
  ReplyBuf[6]=sizeof(Reply->community);
  i=write_buffer(ReplyBuf, 7, Reply->community);
  i=sizeof(Reply->community)+7;
  ReplyBuf[i]=Reply->RequestType;
  ReplyBuf[i+1]=0;
  ReplyBuf[i+2]=2;
  ReplyBuf[i+3]=sizeof(Reply->PacketID);
  k=i+4;
  for(j=0;j<sizeof(Reply->PacketID);j++)
  {
    ReplyBuf[k]=Reply->PacketID[j];
    k++;
  }
  ReplyBuf[k]=2;
  ReplyBuf[k+1]=1;
  ReplyBuf[k+2]=0;
  ReplyBuf[k+3]=2;
  ReplyBuf[k+4]=1;
  ReplyBuf[k+5]=0;
  ReplyBuf[k+6]=SEQUENCE;
  ReplyBuf[k+7]=0;
  l=k+8;
  for(j=0;j<sizeof(Reply->ObjectData);j++)
  {
    m=write_buffer(ReplyBuf, l, Reply->ObjectData[j]);
    l=l+sizeof(Reply->ObjectData[j]);
  }
  ReplyBuf[1]=l-2;
  ReplyBuf[k+7]=l-(k+8);
  RealReplyBuf=allocate_buffer(l);
  RealReplyBuf=ReplyBuf[0..l-1];
  RealReplyBuf[i+1]=sizeof(RealReplyBuf)-i-2;
  socket_write(s, RealReplyBuf, Reply->SourceAddress);
  return;
}
Exemplo n.º 18
0
static void
draw_gears(struct gears *gears)
{
	GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
	struct rectangle allocation;

	if (gears->surface[gears->current] == NULL)
		allocate_buffer(gears);

	glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_RENDERBUFFER_EXT,
				  gears->color_rbo[gears->current]);

	window_get_child_allocation(gears->window, &allocation);
	glViewport(allocation.x, allocation.y,
		   allocation.width, allocation.height);
	glScissor(allocation.x, allocation.y,
		   allocation.width, allocation.height);

	glEnable(GL_SCISSOR_TEST);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();

	glTranslatef(0.0, 0.0, -50);

	glRotatef(view_rotx, 1.0, 0.0, 0.0);
	glRotatef(view_roty, 0.0, 1.0, 0.0);
	glRotatef(view_rotz, 0.0, 0.0, 1.0);

	glPushMatrix();
	glTranslatef(-3.0, -2.0, 0.0);
	glRotatef(gears->angle, 0.0, 0.0, 1.0);
	glCallList(gears->gear_list[0]);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(3.1, -2.0, 0.0);
	glRotatef(-2.0 * gears->angle - 9.0, 0.0, 0.0, 1.0);
	glCallList(gears->gear_list[1]);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-3.1, 4.2, 0.0);
	glRotatef(-2.0 * gears->angle - 25.0, 0.0, 0.0, 1.0);
	glCallList(gears->gear_list[2]);
	glPopMatrix();

	glPopMatrix();

	glFlush();

	window_set_surface(gears->window, gears->surface[gears->current]);
	window_flush(gears->window);
}
Exemplo n.º 19
0
uint8_t*
copy_to_buffer(void* data, uint16_t len)
{
  uint8_t* buffer = allocate_buffer(len);
  if (buffer) {
    memcpy(buffer, data, len);
  }

  return buffer;
}
Exemplo n.º 20
0
u8_t*
copy_text_to_buffer(char* text)
{
  u8_t* buffer = allocate_buffer(strlen(text) + 1);
  if (buffer) {
    strcpy((char*)buffer, text);
  }

  return buffer;
}
Exemplo n.º 21
0
u8_t*
copy_to_buffer(void* data, u16_t len)
#endif /* (MAX_BUFFER_SIZE <= 255) */
{
  u8_t* buffer = allocate_buffer(len);
  if (buffer) {
    memcpy(buffer, data, len);
  }

  return buffer;
}
Exemplo n.º 22
0
static int __init cs598_init_module(void)
{
	int ret = 0;

	/* Create a proc directory entry cs598 */
	proc_dir = proc_mkdir("cs598",NULL);
	if ( proc_dir == NULL )
		goto bad;

	/* Create an entry hash under proc dir cs598 */
	proc_entry = create_proc_entry( "hash", 0666, proc_dir );
	if ( proc_entry == NULL )
		goto bad;

	proc_entry->write_proc = cs598_write_proc;
	proc_entry->read_proc = cs598_read_proc;

	/* Create a kernel thread that calculates the hash of phy mem */
	cs598_kernel_thread = kthread_run(cs598_kernel_thread_fn,
					  NULL,
					  "cs598kt");
	if ( cs598_kernel_thread == NULL )
		goto bad;

	/* Allocate buffer to share with user app */
	if (allocate_buffer() == -ENOMEM) {
		ret = -ENOMEM;
		goto bad;
	}

	/* Create a character device */
	if ((ret = cs598_create_char_dev()) != 0) {
		goto bad;
	}

	printk(KERN_INFO "cs598: Kernel module loaded\n");

	goto end;
 bad:
	if ( vmalloc_buffer ) {
		free_buffer();
	}

	if ( proc_entry ) {
		remove_proc_entry("hash",proc_dir);
	}
	if ( proc_dir ) {
		remove_proc_entry("cs598",NULL);
	}
	printk(KERN_INFO "cs598: Error");
	ret = -ENOMEM;
 end:
	return ret;
}
Exemplo n.º 23
0
el_float::el_float(int size, int en, int id, uint32_t buf_size) {
	_size = size;
	_filled = 0;
	_buffer = NULL;
	setName(en, id);
	this->set_type();
	if (buf_size == 0) {
		buf_size = RESERVED_SPACE;
	}
	allocate_buffer(buf_size);
}
Exemplo n.º 24
0
int read_md5_file(const char *c)
{
	char buff[HASH_LENGTH], found_name[256], remaining_name[256];

	/* Create the found and remaining names */
	snprintf(found_name, sizeof(found_name), "%s%s", c, ".found");
	snprintf(remaining_name, sizeof(remaining_name), "%s%s", c, ".remaining");

	/* Open the file to get the number of lines */
	FILE *file = fopen(c, "r");
	if (!file) {
		printf("%s failed to open password file: %d\n", __func__, errno);
		return 0;
	}

	found = fopen(found_name, "a");
	remaining = fopen(remaining_name, "w");
	if (!found) {
		printf("%s failed to open found password file: %d\n", __func__, errno);
		return 0;
	} else if (!remaining) {
		printf("%s failed to open remaining password file: %d\n", __func__, errno);
		return 0;
	}

	/* Count the number of lines */
	while (fgets(buff, HASH_LENGTH, file))
		count++;

	/* Initialize the buckets */
	init_buckets(count);

        /* Allocate the buffer */
	hash_buff = allocate_buffer(count);
	if (hash_buff == NULL)
		return 1;

	/* Read in the buffer */
	fseek(file, 0, SEEK_SET);
	count = 0;

	while (fgets(buff, HASH_LENGTH, file)) {
		md5_binary(buff, &hash_buff[count]);
		count++;
	}

	qsort(hash_buff, count, sizeof(md5_binary_t), compare_md5);
	fclose(file);

	/* Build the buckets */
	build_buckets(count);

	return count;
}
Exemplo n.º 25
0
el_ipv6::el_ipv6(int size, int en, int id, int part, uint32_t buf_size) {
	ipv6_value = 0;
	_size = size;
	_filled = 0;
	_buffer = NULL;
	setName(en, id, part);
	this->set_type();
	if (buf_size == 0) {
		 buf_size = RESERVED_SPACE;
	}
	allocate_buffer(buf_size);
}
Exemplo n.º 26
0
static PmError allocate_input_buffer(HMIDIIN h, long buffer_len)
{
    LPMIDIHDR hdr = allocate_buffer(buffer_len);
    if (!hdr) return pmInsufficientMemory;
    pm_hosterror = midiInPrepareHeader(h, hdr, sizeof(MIDIHDR));
    if (pm_hosterror) {
        pm_free(hdr);
        return pm_hosterror;
    }
    pm_hosterror = midiInAddBuffer(h, hdr, sizeof(MIDIHDR));
    return pm_hosterror;
}
Exemplo n.º 27
0
/**
 * Performs chemistry along the depth of a row-block of the concentration matrix
 */
void saprc99_chem_block(uint64_t argvp)
{
    /* Iterators */
    uint32_t i, j;
    
    uint32_t rows;
    
    timer_start(&metrics.chem);
    
    /* Get arguments from main memory synchronously */
    get_chemistry_argv(argvp, &rows);
    
    allocate_dma_list(&clist[0]);
    allocate_dma_list(&clist[1]);
    allocate_buffer(&conc[0]);
    allocate_buffer(&conc[1]);

    for(i=0; i<rows; i++)
    {
        printf("        SPE %d: Chemistry on row %d of %d...\n", envv.speid, i, rows);
        for(j=0; j<(NX_ALIGNED/VECTOR_LENGTH); j++)
        {
            fetch_chem_buffer(0, j*16);
            
            saprc99_buffer(0);
            
            write_chem_buffer(0);
        }
    }
    
    free_dma_list(&clist[0]);
    free_dma_list(&clist[1]);
    free_buffer(&conc[0]);
    free_buffer(&conc[1]);
    
    timer_stop(&metrics.chem);

    set_status(SPE_STATUS_WAITING);
}
Exemplo n.º 28
0
buffer to_buffer(mixed arg) {
    buffer ret;
    
    if (intp(arg))
	arg = arg + "";

    if (stringp(arg)) {
	ret = allocate_buffer(strlen(arg));
	write_buffer(ret, 0, arg);
    } 

    return ret;
}
Exemplo n.º 29
0
int
buffer_tlv(int type, const unsigned char *data, int datalen,
           const struct sockaddr_in6 *sin6, struct interface *interface)
{
    if(interface && sin6) {
        errno = EINVAL;
        return -1;
    }

    if(sendbuf == NULL)
        sendbuf = allocate_buffer(SENDBUF_SIZE);
    if(sendbuf == NULL)
        return -1;

    if(buffered &&
       ((interface && interface != buffered_interface) ||
        (!interface && (buffered_interface ||
                        memcmp(sin6, &buffered_sin6, sizeof(*sin6)) != 0)) ||
        buffered + datalen > 1400))
        flushbuf();

    if(buffered + datalen + 4 > SENDBUF_SIZE) {
        errno = EMSGSIZE;
        return -1;
    }

    if(!buffered) {
        /* NODE-ENDPOINT */
        DO_HTONS(sendbuf + 0, 3);
        DO_HTONS(sendbuf + 2, 8);
        memcpy(sendbuf + 4, myid, 4);
        DO_HTONL(sendbuf + 8,
                 interface ? interface->ifindex : sin6->sin6_scope_id);
        buffered = 12;
    }

    if(interface)
        buffered_interface = interface;
    else
        memcpy(&buffered_sin6, sin6, sizeof(*sin6));

    DO_HTONS(sendbuf + buffered, type); buffered += 2;
    DO_HTONS(sendbuf + buffered, datalen); buffered += 2;
    memcpy(sendbuf + buffered, data, datalen); buffered += datalen;

    if(debug_level >= 3)
        debugf("Buffering %s %d (%d)\n",
               interface ? "multicast" : "unicast", type, datalen);

    return 1;
}
Exemplo n.º 30
0
void f_map_bson_buf (void){

	buffer_t *buf;
	bson b[1];

	bson_init_empty(b);
	map_to_bson(sp, b);
	buf = allocate_buffer(bson_size(b));

	memcpy(buf->item, b->data, bson_size(b));
	pop_stack();
	push_refed_buffer(buf);
	bson_destroy( b );
}