Exemplo n.º 1
0
SIZE_OR_ERROR FS_get(const char *path, char **return_buffer, size_t * buffer_length)
{
	SIZE_OR_ERROR size = 0 ;		/* current buffer string length */
	OWQ_allocate_struct_and_pointer( owq ) ;

	/* Check the parameters */
	if (return_buffer == NULL) {
		//  No buffer for read result.
		return -EINVAL;
	}

	if (path == NULL) {
		path = "/";
	}

	*return_buffer = NULL;				// default return string on error

	if ( BAD( OWQ_create(path, owq) ) ) {	/* Can we parse the input string */
		return -ENOENT;
	}

	if ( IsDir( PN(owq) ) ) { /* A directory of some kind */
		struct charblob cb ;
		CharblobInit(&cb) ;
		getdir( &cb, owq ) ;
		size = CharblobLength(&cb) ;
		*return_buffer = copy_buffer( CharblobData(&cb), size ) ;
		CharblobClear( &cb ) ;
	} else { /* A regular file  -- so read */
		if ( GOOD(OWQ_allocate_read_buffer(owq)) ) { // make the space in the buffer
			size = FS_read_postparse(owq) ;
			*return_buffer = copy_buffer( OWQ_buffer(owq), size ) ;
		}
	}
	// the buffer is allocated by getdir or getval
	OWQ_destroy(owq);

	/* Check the parameters */
	if (*return_buffer == NULL) {
		//  no data.
		return -EINVAL;
	}

	if ( buffer_length != NULL ) {
		*buffer_length = size ;
	}
	return size ;
}
Exemplo n.º 2
0
const gchar *
get_data (xml_weather *data,
          datas        type)
{
    gchar *str = NULL;
    gchar *p;

    if (!data)
        str = EMPTY_STRING;
    else 
    {
    
        switch (type & 0xFF00)
        {
            case DATAS_CC: str = get_data_cc(data->cc, type); break;
            case DATAS_LOC: str = get_data_loc(data->loc, type); break;
            default: str = EMPTY_STRING;
        }
    }

    p = copy_buffer(str);
    g_free(str);

    return p;
}
Exemplo n.º 3
0
static GstFlowReturn new_sample_callback (GstAppSink * sink, gpointer user_data)
{
        GstBuffer *buffer;
        GstSample *sample;
        Encoder *encoder = (Encoder *)user_data;

        *(encoder->output->heartbeat) = gst_clock_get_time (encoder->system_clock);
        sample = gst_app_sink_pull_sample (GST_APP_SINK (sink));
        buffer = gst_sample_get_buffer (sample);

        sem_wait (encoder->output->semaphore);

        (*(encoder->output->total_count)) += gst_buffer_get_size (buffer);

        /* update head_addr, free enough memory for current buffer. */
        while (cache_free (encoder) < gst_buffer_get_size (buffer) + 12) { /* timestamp + gop size = 12 */
                move_head (encoder);
        }

        if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
                /* 
                 * random access point found.
                 * write previous gop size to 4 bytes reservation,
                 * write current gop timestamp,
                 * reserve 4 bytes for size of current gop,
                 */
                if (encoder->mqdes == -1) {
                        /* no m3u8 output */
                        move_last_rap (encoder, buffer);

                } else if (GST_BUFFER_PTS (buffer) == encoder->last_running_time) {
                        gchar *msg;

                        move_last_rap (encoder, buffer);
                        msg = g_strdup_printf ("%lu", encoder->last_segment_duration);
                        if (mq_send (encoder->mqdes, msg, strlen (msg), 1) == -1) {
                                GST_ERROR ("mq_send error: %s", g_strerror (errno));
                        }
                        g_free (msg);
                        encoder->last_running_time = GST_CLOCK_TIME_NONE;
                }
        }

        /* udpstreaming? */
        if (encoder->udpstreaming) {
                udp_streaming (encoder, buffer);
        }

        /*
         * copy buffer to cache.
         * update tail_addr
         */
        copy_buffer (encoder, buffer);

        sem_post (encoder->output->semaphore);

        gst_sample_unref (sample);

        return GST_FLOW_OK;
}
Exemplo n.º 4
0
static void setup_DMA(void) {

	unsigned long addr,count;
	unsigned char dma_code;
	dma_code = DMA_WRITE;
	if (command == FD_READ)
		dma_code = DMA_READ;
	if (command == FD_FORMAT) {
		addr = (long) tmp_floppy_area;
		count = floppy->sect*4;
	} else {
		addr = (long) CURRENT->buffer;
		count = 1024;
	}
	if (read_track) {
/* mark buffer-track bad, in case all this fails.. */
		buffer_drive = buffer_track = -1;
		count = floppy->sect*floppy->head*512;
		addr = (long) floppy_track_buffer;
	} else if (addr >= LAST_DMA_ADDR) {
		addr = (long) tmp_floppy_area;
		if (command == FD_WRITE)
			copy_buffer(CURRENT->buffer, tmp_floppy_area);
	}
	cli();
	disable_dma(FLOPPY_DMA);

	//clear_dma_ff(FLOPPY_DMA);
	set_dma_mode(FLOPPY_DMA, (command == FD_READ)? DMA_MODE_READ : DMA_MODE_WRITE);
	set_dma_addr(FLOPPY_DMA, addr);
	set_dma_count(FLOPPY_DMA, count);
	enable_dma(FLOPPY_DMA);
	sti();
}
	Exception::Exception(lua_State* vm, ERROR::PopTheStack*)
		: m_len(0) // LCOV_EXCL_LINE
	{
		char const* str = lua_tolstring(vm, -1, &m_len);
		copy_buffer(m_buffer, str, m_len);
		lua_pop(vm, 1);
	}
Exemplo n.º 6
0
/**
 * Creates a deep copy of the specified Deque. A deep copy is a copy of
 * both the Deque structure and the data it holds.
 *
 * @note The new Deque is allocated using the original Deque's allocators
 *       and also inherits the configuration of the original Deque.
 *
 * @param[in] deque the deque to be copied
 * @param[in] cp   the copy function that should return a pointer to the copy of
 *                 the data.
 * @param[out] out Pointer to where the newly created copy is stored
 *
 * @return CC_OK if the copy was successfully created, or CC_ERR_ALLOC if the
 * memory allocation for the copy failed.
 */
enum cc_stat deque_copy_deep(Deque *deque, void *(*cp) (void*), Deque **out)
{
    Deque *copy = deque->mem_alloc(sizeof(Deque));

    if (!copy)
        return CC_ERR_ALLOC;

    if (!(copy->buffer = deque->mem_alloc(deque->capacity * sizeof(void*)))) {
        deque->mem_free(copy);
        return CC_ERR_ALLOC;
    }

    copy->size       = deque->size;
    copy->capacity   = deque->capacity;
    copy->mem_alloc  = deque->mem_alloc;
    copy->mem_calloc = deque->mem_calloc;
    copy->mem_free   = deque->mem_free;

    copy_buffer(deque, copy->buffer, cp);

    copy->first = 0;
    copy->last  = copy->size;

    *out = copy;

    return CC_OK;
}
Exemplo n.º 7
0
bool
send_frame( ether_device *device, buffer *frame ) {
    assert( device != NULL );
    assert( device->send_queue != NULL );
    assert( frame != NULL );
    assert( frame->length > 0 );

    if ( get_max_packet_buffers_length( device->send_queue ) <= get_packet_buffers_length( device->send_queue ) ) {
        warn( "Send queue is full ( device = %s, usage = %u/%u ).",
              device->name, get_packet_buffers_length( device->send_queue ), get_max_packet_buffers_length( device->send_queue ) );
        return false;
    }

    debug( "Enqueueing a frame to send queue ( frame = %p, device = %s, queue length = %d, fd = %d ).",
           frame, device->name, get_packet_buffers_length( device->send_queue ), device->fd );

    buffer *copy = get_free_packet_buffer( device->send_queue );
    assert( copy != NULL );
    copy_buffer( copy, frame );

    enqueue_packet_buffer( device->send_queue, copy );

    if ( ( get_packet_buffers_length( device->send_queue ) > 0 ) && ( device->fd >= 0 ) ) {
        set_writable_safe( device->fd, true );
    }

    return true;
}
Exemplo n.º 8
0
void set_shiny_buffer(shiny_thingy * thingy, pixel_buffer buff) {
	shiny_buffer * thing = SHINY_BUFFER(thingy);
	free_buffer(thing->buffer);
	thing->buffer = copy_buffer(buff);
	thingy->size.width = buff.width;
	thingy->size.height = buff.height;
}
Exemplo n.º 9
0
const gchar *
get_unit (units unit,
          datas type)
{
    gchar *str;
    
    switch (type & 0x00F0)
    {
        case 0x0020: 
            str = (unit == METRIC ? "\302\260C" : "\302\260F");
            break;
        case 0x0030:
            str = "%";
            break;
        case 0x0040:
            str = (unit == METRIC ? _("km/h") : _("mph"));
            break;
        case 0x0050: 
            str = (unit == METRIC ? _("hPa") : _("in"));
            break;
        case 0x0060:
            str = (unit == METRIC ? _("km") : _("mi"));
            break;
        default:
            str = "";
    }

    return copy_buffer (str);
}
Exemplo n.º 10
0
static void
coalesce_writes (uint32 fd, uint8 **bufpp, uint32 *lengthp, uint32 *offsetp)
{
  dcache_entry_t *backwards_dps[MAX_BACKWARDS];
  int backwards_index;

  dcache_entry_t *forwards_dps[MAX_FORWARDS];
  int forwards_index;

  /* find beginning of run */
  fill_run (backwards_dps, NELEM (backwards_dps), &backwards_index,
	    -DCACHE_BLOCK_SIZE, *offsetp, fd);

  /* find ending of run */
  fill_run (forwards_dps,  NELEM (forwards_dps),  &forwards_index,
	     DCACHE_BLOCK_SIZE, *offsetp, fd);

  if (backwards_index > 0 || forwards_index > 0)
    {
      int n_bufs;
      uint8 *bufp;
      uint8 *outbufp;
      uint32 length;
      dcache_entry_t *d;
      int i;

      n_bufs = backwards_index + 1 + forwards_index;

      /* allocate space for run */
      length = n_bufs * DCACHE_BLOCK_SIZE;
      bufp = malloc (length);
      outbufp = bufp;

      for (i = backwards_index - 1; i >= 0; --i)
	copy_buffer (&outbufp, backwards_dps[i]);

      d = dcache_entry_lookup (fd, *offsetp);
      copy_buffer (&outbufp, d);

      for (i = 0; i < forwards_index; ++i)
	copy_buffer (&outbufp, forwards_dps[i]);

      *bufpp = bufp;
      *lengthp = length;
      *offsetp -= DCACHE_BLOCK_SIZE * backwards_index;
    }
}
Exemplo n.º 11
0
static void setup_DMA(void)
{
	unsigned long addr,count;
	unsigned char dma_code;

	dma_code = DMA_WRITE;
	if (command == FD_READ)
		dma_code = DMA_READ;
	if (command == FD_FORMAT) {
		addr = (long) tmp_floppy_area;
		count = floppy->sect*4;
	} else {
		addr = (long) CURRENT->buffer;
		count = 1024;
	}
	if (read_track) {
/* mark buffer-track bad, in case all this fails.. */
		buffer_drive = buffer_track = -1;
		count = floppy->sect*2*512;
		addr = (long) floppy_track_buffer;
	} else if (addr >= LAST_DMA_ADDR) {
		addr = (long) tmp_floppy_area;
		if (command == FD_WRITE)
			copy_buffer(CURRENT->buffer,tmp_floppy_area);
	}
	cli();
#ifndef HHB_SYSMACROS
/* mask DMA 2 */
	outb_p(4|2,10);
/* output command byte. I don't know why, but everyone (minix, */
/* sanches & canton) output this twice, first to 12 then to 11 */
	outb_p(dma_code,12);
	outb_p(dma_code,11);
/* 8 low bits of addr */
	outb_p(addr,4);
	addr >>= 8;
/* bits 8-15 of addr */
	outb_p(addr,4);
	addr >>= 8;
/* bits 16-19 of addr */
	outb_p(addr,0x81);
/* low 8 bits of count-1 */
	count--;
	outb_p(count,5);
	count >>= 8;
/* high 8 bits of count-1 */
	outb_p(count,5);
/* activate DMA 2 */
	outb_p(0|2,10);
#else			/* just to show off my macros -- hhb */
	DISABLE_DMA(DMA2);
	CLEAR_DMA_FF(DMA2);
	SET_DMA_MODE(DMA2, (command == FD_READ)? DMA_MODE_READ : DMA_MODE_WRITE);
	SET_DMA_ADDR(DMA2, addr);
	SET_DMA_COUNT(DMA2, count);
	ENABLE_DMA(DMA2);
#endif
	sti();
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
  int in, out, mode, res = EXIT_FAILURE;

  // make sure the user provided the necessary command line arguments
  if (argc != 4) {
    fprintf(stderr, "Usage: %s <source> <dest> <mode>\n"
                    "\n"
                    "Copies a file from <source> to <dest>.\n"
                    "<mode> must be either 1 or 2 where\n"
                    "  mode==%d      use buffer copy algorithm\n"
                    "  mode==%d      use mmap copy algorithm\n",
                    argv[0], M_BUFFER, M_MMAP);
    exit(EXIT_FAILURE);
  }

  // first check the mode
  mode = atoi(argv[3]);
  if (!((mode == M_BUFFER) || (mode == M_MMAP))) {
    fprintf(stderr, "Invalid copy mode specified (%d)\n", mode);
    exit(EXIT_FAILURE);
  }


  // open the source file read-only and check for errors
  in = open(argv[1], O_RDONLY);
  if (in == -1) {
    perror("Error opening input file");
    exit(EXIT_FAILURE);
  }

  // check if output file exists and abort if yes
  if (access(argv[2], F_OK) == 0) {
    fprintf(stderr, "Cowardly refusing to overwrite an exiting file\n");
    exit(EXIT_FAILURE);
  }

  // open the destination file write-only and check for errors
  out = open(argv[2], O_CREAT|O_TRUNC|O_WRONLY,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
  if (out == -1) {
    perror("Error opening output file");
    exit(EXIT_FAILURE);
  }

  // invoke file copy
  switch (mode) {
    case M_BUFFER: res = copy_buffer(in, out);
                   break;
    case M_MMAP:   res = copy_mmap(in, out);
                   break;
  }

  // close source & destination
  close(in);
  close(out);

  return res;
}
Exemplo n.º 13
0
static void do_fd_action(int drive)
{
	struct request *req;
	DPRINT(("do_fd_action unit[drive].track=%d\n", unit[drive].track));

#ifdef TRACKBUFFER
repeat:

	if (IS_BUFFERED( drive, ReqSide, ReqTrack )) {
		req = CURRENT;
		if (ReqCmd == READ) {
			copy_buffer( SECTOR_BUFFER(ReqSector), ReqData );
			if (++ReqCnt < req->current_nr_sectors) {
				/* read next sector */
				setup_req_params( drive );
				goto repeat;
			} else {
				/* all sectors finished */
				req->nr_sectors -= req->current_nr_sectors;
				req->sector += req->current_nr_sectors;
				end_request(req, 1);
				redo_fd_request();
				return;
			}
		} else {
			/* cmd == WRITE, pay attention to track buffer
			 * consistency! */
			copy_buffer( ReqData, SECTOR_BUFFER(ReqSector) );
		}
	}
#endif

	if (SelectedDrive != drive) {
		/*unit[drive].track = -1; DAG */
		fd_select_drive(drive);
	};


	if (unit[drive].track == -1)
		fd_calibrate();
	else if (unit[drive].track != ReqTrack << unit[drive].disktype->stretch)
		fd_seek();
	else
		fd_rwsec();
}
Exemplo n.º 14
0
int lame_encode_finish(lame_global_flags *gfp,char *mp3buffer, int mp3buffer_size)
{
  int imp3,mp3count,mp3buffer_size_remaining;
  short int buffer[2][1152];
  memset((char *)buffer,0,sizeof(buffer));
  mp3count = 0;

  while (mf_samples_to_encode > 0) {

    mp3buffer_size_remaining = mp3buffer_size - mp3count;
    /* if user specifed buffer size = 0, dont check size */
    if (mp3buffer_size == 0) mp3buffer_size_remaining=0;  
    imp3=lame_encode(gfp,buffer,mp3buffer,mp3buffer_size_remaining);

    if (imp3 == -1) {
      /* fatel error: mp3buffer too small */
      desalloc_buffer(&bs);    /* Deallocate all buffers */
      return -1;
    }
    mp3buffer += imp3;
    mp3count += imp3;
    mf_samples_to_encode -= gfp->framesize;
  }


  gfp->frameNum--;
  if (!gfp->gtkflag && !gfp->silent) {
      timestatus(gfp->out_samplerate,gfp->frameNum,gfp->totalframes,gfp->framesize);
#ifdef BRHIST
      if (disp_brhist)
	{
	  brhist_add_count();
	  brhist_disp();
	  brhist_disp_total(gfp);
	}
#endif
      fprintf(stderr,"\n");
      fflush(stderr);
  }


  III_FlushBitstream();
  mp3buffer_size_remaining = mp3buffer_size - mp3count;
  /* if user specifed buffer size = 0, dont check size */
  if (mp3buffer_size == 0) mp3buffer_size_remaining=0;  

  imp3= copy_buffer(mp3buffer,mp3buffer_size_remaining,&bs);
  if (imp3 == -1) {
    /* fatel error: mp3buffer too small */
    desalloc_buffer(&bs);    /* Deallocate all buffers */
    return -1;
  }

  mp3count += imp3;
  desalloc_buffer(&bs);    /* Deallocate all buffers */
  return mp3count;
}
Exemplo n.º 15
0
DO_RET do_redit_reset( CHAR_DATA *ch, char *argument )
{
	ROOM_DATA		 *room = ch->dest_buf;
	EXTRA_DESCR_DATA *ed = ch->spare_ptr;

	switch ( ch->substate )
	{
	  case SUB_ROOM_DESCR:
		if ( !ch->dest_buf )
		{
			/* If theres no dest_buf, theres no object, so stick em back as playing */
			ch_printf( ch, "Fatal error: report to Coder.\r\n" );
			send_log( NULL, LOG_OLC, "do_redit_reset: sub_obj_extra: NULL ch->dest_buf" );
			ch->substate = SUB_NONE;
			ch->desc->connected = CON_PLAYING;
			return;
		}
		DISPOSE( room->description );
		room->description = copy_buffer( ch );
		stop_editing( ch );
		ch->dest_buf = room;
		ch->desc->connected = CON_REDIT;
		ch->substate = SUB_NONE;

		olc_log( ch->desc, "Edited room description" );
		redit_disp_menu( ch->desc );
		return;

	  case SUB_ROOM_EXTRA:
		DISPOSE( ed->description );
		ed->description = copy_buffer( ch );
		stop_editing( ch );
		ch->dest_buf = room;
		ch->spare_ptr = ed;
		ch->substate = SUB_NONE;
		ch->desc->connected = CON_REDIT;
		oedit_disp_extra_choice( ch->desc );
		OLC_MODE(ch->desc) = REDIT_EXTRADESC_CHOICE;
		olc_log( ch->desc, "Edit description for exdesc %s", ed->keyword );

		return;
	}
}
Exemplo n.º 16
0
__interrupt void Port_2(void) {
  P2IFG &= ~BUTTONS_MASK; //clear flag
  
  //send message
    switch (switchMessage) {
    case 0: //new_node
      node_id++;
      nuf_new_node[5] = node_id;
      copy_buffer(tx_buf_bcuart, nuf_new_node, DEFAULT_NUF_LEN);
      bcUartSend(tx_buf_bcuart, DEFAULT_NUF_LEN);
      break;
    case 1: //update_temp
      copy_buffer(tx_buf_bcuart, nuf_update_temp, 9);
      bcUartSend(tx_buf_bcuart, 9);
      break;
    case 2: //update_hum
      copy_buffer(tx_buf_bcuart, nuf_update_hum, 9);
      bcUartSend(tx_buf_bcuart, 9);
      break;
    default: break;
    }
    
}
Exemplo n.º 17
0
/**
 * Expands the deque capacity. This might operation might fail if the new
 * buffer cannot be allocated. If the capacity is already the maximum capacity
 * no new buffer is allocated and false is returned to indicated failure.
 *
 * @param[in] deque the deque whose capacity is being expanded
 *
 * @return true if the operation was successful
 */
static bool expand_capacity(Deque *deque)
{
    if (deque->capacity == MAX_POW_TWO)
        return false;

    size_t   new_capacity = deque->capacity << 1;
    void   **new_buffer   = deque->mem_calloc(new_capacity, sizeof(void*));

    copy_buffer(deque, new_buffer, NULL);

    deque->first    = 0;
    deque->last     = deque->size;
    deque->capacity = new_capacity;
    deque->buffer   = new_buffer;

    return true;
}
Exemplo n.º 18
0
/**
 * Returns a deep copy of the specified deque. A deep copy is a copy of
 * both the deque structure and the data it holds.
 *
 * @note The new deque is allocated using the original deque's allocators
 *       and also inherits the configuration of the original deque.
 *
 * @param[in] deque the deque to be copied
 * @param[in] cp the copy function that returns a copy of a deque element
 *
 * @return a deep copy of the specified deque
 */
Deque* deque_copy_deep(Deque *deque, void *(*cp) (void*))
{
    Deque *copy = deque->mem_alloc(sizeof(Deque));

    copy->size       = deque->size;
    copy->capacity   = deque->capacity;
    copy->mem_alloc  = deque->mem_alloc;
    copy->mem_calloc = deque->mem_calloc;
    copy->mem_free   = deque->mem_free;
    copy->buffer     = copy->mem_alloc(copy->capacity * sizeof(void*));

    copy_buffer(deque, copy->buffer, cp);

    copy->first = 0;
    copy->last  = copy->size; // XXX

    return copy;
}
Exemplo n.º 19
0
/**
 * Returns a shallow copy of the specified deque. A shallow copy is a copy of
 * the deque structure, but not the elements it holds.
 *
 * @note The new deque is allocated using the original deque's allocators
 *       and also inherits the configuration of the original deque.
 *
 * @param[in] deque the deque to be copied
 *
 * @return a shallow copy of the specified deque
 */
Deque* deque_copy_shallow(Deque *deque)
{
    Deque *copy = deque->mem_alloc(sizeof(Deque));

    copy->size       = deque->size;
    copy->capacity   = deque->capacity;
    copy->mem_alloc  = deque->mem_alloc;
    copy->mem_calloc = deque->mem_calloc;
    copy->mem_free   = deque->mem_free;
    copy->buffer     = copy->mem_alloc(copy->capacity * sizeof(void*));

    copy_buffer(deque, copy->buffer, NULL);

    copy->first = 0;
    copy->last  = copy->size;

    return copy;
}
Exemplo n.º 20
0
/**
 * Trims the capacity of the deque to a power of 2 that is the nearest to
 * the number of elements in the deque.
 *
 * @param[in] deque the deque on which this operation is being performed
 */
void deque_trim_capacity(Deque *deque)
{
    if (deque->capacity == deque->size)
        return;

    size_t new_size = upper_pow_two(deque->size);

    if (new_size == deque->capacity)
        return;

    void **new_buff = deque->mem_alloc(sizeof(void*) * new_size);

    copy_buffer(deque, new_buff, NULL);

    deque->buffer   = new_buff;
    deque->first    = 0;
    deque->last     = deque->size;
    deque->capacity = new_size;
}
Exemplo n.º 21
0
/*
 * The implementation of spdylay_on_data_chunk_recv_callback type. We
 * use this function to print the received response body.
 */
static void
spdy_cb_on_data_chunk_recv(spdylay_session *session,
                          uint8_t flags,
                          int32_t stream_id,
                          const uint8_t *data,
                          size_t len,
                          void *user_data)
{
  (void)flags;
  (void)user_data;

  struct Proxy *proxy;
  proxy = spdylay_session_get_stream_user_data(session, stream_id);

  if(NULL == proxy)
  {
    PRINT_INFO("proxy in spdy_cb_on_data_chunk_recv is NULL)");
    return;
	}

  if(!copy_buffer(data, len, &proxy->http_body, &proxy->http_body_size))
  {
    //TODO handle it better?
    PRINT_INFO("not enough memory (malloc/realloc returned NULL)");
    return;
  }
  /*
	if(NULL == proxy->http_body)
		proxy->http_body = au_malloc(len);
  else
		proxy->http_body = realloc(proxy->http_body, proxy->http_body_size + len);
	if(NULL == proxy->http_body)
	{
		PRINT_INFO("not enough memory (realloc returned NULL)");
		return ;
	}

	memcpy(proxy->http_body + proxy->http_body_size, data, len);
	proxy->http_body_size += len;
  */
  PRINT_INFO2("received data for %s; %zu bytes", proxy->url, len);
  glob_opt.spdy_data_received = true;
}
Exemplo n.º 22
0
void SPHSystem::animation()
{	
	if(sys_running != 1)
	{
		return;
	}

	set_parameters(hParam);

    calc_hash(dHash, dIndex,dMem, hParam->num_particle);
	sort_particles(dHash, dIndex, hParam->num_particle);
	find_start_end(dStart, dEnd, dHash, dIndex, hParam->num_particle, hParam->tot_cell);
	integrate_velocity(dMem, hParam->num_particle);
	compute(dMem, dHash, dIndex, dStart, dEnd, hParam->num_particle, hParam->tot_cell);

	copy_buffer(dMem, dPoints, hParam->num_particle);
	copy_array(hPoints, dPoints, sizeof(float2)*hParam->num_particle, CUDA_DEV_TO_HOST);
	copy_array(hMem, dMem, sizeof(Particle)*hParam->num_particle, CUDA_DEV_TO_HOST);
}
Exemplo n.º 23
0
/* Ripped off do_description for whois bio's -- Scryn*/
void do_bio( CHAR_DATA* ch, const char* argument)
{
   if( IS_NPC( ch ) )
   {
      send_to_char( "Mobs cannot set a bio.\r\n", ch );
      return;
   }
   if( ch->level < 5 )
   {
      set_char_color( AT_SCORE, ch );
      send_to_char( "You must be at least level five to write your bio...\r\n", ch );
      return;
   }
   if( !ch->desc )
   {
      bug( "%s", "do_bio: no descriptor" );
      return;
   }

   switch ( ch->substate )
   {
      default:
         bug( "%s", "do_bio: illegal substate" );
         return;

      case SUB_RESTRICTED:
         send_to_char( "You cannot use this command from within another command.\r\n", ch );
         return;

      case SUB_NONE:
         ch->substate = SUB_PERSONAL_BIO;
         ch->dest_buf = ch;
         start_editing( ch, ch->pcdata->bio );
         return;

      case SUB_PERSONAL_BIO:
         STRFREE( ch->pcdata->bio );
         ch->pcdata->bio = copy_buffer( ch );
         stop_editing( ch );
         return;
   }
}
Exemplo n.º 24
0
/**
 * Expands the deque capacity. This operation might fail if the new buffer
 * cannot be allocated. If the capacity is already the maximum capacity,
 * no new buffer is allocated.
 *
 * @param[in] deque the deque whose capacity is being expanded
 *
 * @return CC_OK if the buffer was expanded successfully, CC_ERR_ALLOC if
 * the memory allocation for the new buffer failed, or CC_ERR_MAX_CAPACITY
 * if the Deque is already at maximum capacity.
 */
static enum cc_stat expand_capacity(Deque *deque)
{
    if (deque->capacity == MAX_POW_TWO)
        return CC_ERR_MAX_CAPACITY;

    size_t new_capacity = deque->capacity << 1;
    void **new_buffer = deque->mem_calloc(new_capacity, sizeof(void*));

    if (!new_buffer)
        return CC_ERR_ALLOC;

    copy_buffer(deque, new_buffer, NULL);
    deque->mem_free(deque->buffer);

    deque->first    = 0;
    deque->last     = deque->size;
    deque->capacity = new_capacity;
    deque->buffer   = new_buffer;

    return CC_OK;
}
Exemplo n.º 25
0
/*
 * COMP3301 Addition
 * Read from immediate files with data stored directly in the inode.
 */
ssize_t do_immediate_read (struct file* flip, const char __user* buf,
	size_t len, loff_t *ppos) {

    struct inode *inode = flip->f_dentry->d_inode;
    struct ext2_inode_info *inode_info = EXT2_I(inode);
    char* new_buffer = (char *) kmalloc(sizeof(char) * len, GFP_KERNEL);
    char *data = (char *)inode_info->i_data;
    copy_buffer(new_buffer, data, len);

    if (*ppos + len > inode->i_size) {
    	len -= ((*ppos + len) - inode->i_size);
    }

	if (copy_to_user(buf, new_buffer + *ppos, len)) {
		kfree(new_buffer);
		return -1;
	}

	kfree(new_buffer);
	*ppos += len;

    return len;
}
Exemplo n.º 26
0
/* Ripped off do_description for whois bio's -- Scryn*/
void do_bio( CHAR_DATA * ch, const char *argument )
{
   if( IS_NPC( ch ) )
   {
      send_to_char( "Mobs can't set bio's!\r\n", ch );
      return;
   }

   if( !ch->desc )
   {
      bug( "do_bio: no descriptor", 0 );
      return;
   }

   switch ( ch->substate )
   {
      default:
         bug( "do_bio: illegal substate", 0 );
         return;

      case SUB_RESTRICTED:
         send_to_char( "You cannot use this command from within another command.\r\n", ch );
         return;

      case SUB_NONE:
         ch->substate = SUB_PERSONAL_BIO;
         ch->dest_buf = ch;
         start_editing( ch, (char *)ch->pcdata->bio );
         return;

      case SUB_PERSONAL_BIO:
         STRFREE( ch->pcdata->bio );
         ch->pcdata->bio = copy_buffer( ch );
         stop_editing( ch );
         return;
   }
}
Exemplo n.º 27
0
/*
 * Set your personal description				-Thoric
 */
void do_description( CHAR_DATA* ch, const char* argument)
{
   if( IS_NPC( ch ) )
   {
      send_to_char( "Monsters are too dumb to do that!\r\n", ch );
      return;
   }

   if( !ch->desc )
   {
      bug( "%s", "do_description: no descriptor" );
      return;
   }

   switch ( ch->substate )
   {
      default:
         bug( "%s", "do_description: illegal substate" );
         return;

      case SUB_RESTRICTED:
         send_to_char( "You cannot use this command from within another command.\r\n", ch );
         return;

      case SUB_NONE:
         ch->substate = SUB_PERSONAL_DESC;
         ch->dest_buf = ch;
         start_editing( ch, ch->description );
         return;

      case SUB_PERSONAL_DESC:
         STRFREE( ch->description );
         ch->description = copy_buffer( ch );
         stop_editing( ch );
         return;
   }
}
Exemplo n.º 28
0
unsigned cvsdelta::write_control(char region, unsigned start, unsigned len, const Byte *data, ByteArray& control_buffer, ByteArray& data_buffer, bool from_data)
{
  unsigned control=control_buffer.size();
  Byte *cp;
  unsigned char control_bit = region?0x80:0;

  control_buffer.resize(control_buffer.size()+32);

  cp = (Byte*)&control_buffer[control];

  if(region && !from_data)
    start = copy_buffer(data,start,len,data_buffer);

  if(len<0x20)
  {
    *(cp++)=(unsigned char)len|control_bit;
    control+=1;
  }
  else if(len<0x2000)
  {
    *(cp++)=(unsigned char)(len>>8)+0x20|control_bit;
    *(cp++)=(unsigned char)(len&0xFF);
    control+=2;
  }
Exemplo n.º 29
0
/**
 * Trims the capacity of the deque to a power of 2 that is the nearest
 * upper power of 2 to the number of elements in the deque.
 *
 * @param[in] deque Deque whose capacity is being trimmed
 *
 * @return CC_OK if the capacity was trimmed successfully, or CC_ERR_ALLOC if
 * the reallocation failed.
 */
enum cc_stat deque_trim_capacity(Deque *deque)
{
    if (deque->capacity == deque->size)
        return CC_OK;

    size_t new_size = upper_pow_two(deque->size);

    if (new_size == deque->capacity)
        return CC_OK;

    void **new_buff = deque->mem_alloc(sizeof(void*) * new_size);

    if (!new_buff)
        return CC_ERR_ALLOC;

    copy_buffer(deque, new_buff, NULL);
    deque->mem_free(deque->buffer);

    deque->buffer   = new_buff;
    deque->first    = 0;
    deque->last     = deque->size;
    deque->capacity = new_size;
    return CC_OK;
}
Exemplo n.º 30
0
const gchar *
get_data_f (xml_dayf *data,
            forecast  type)
{
    gchar *p, *str = NULL;

    if (data)
    {
        switch (type & 0x0F00)
        {
            case ITEMS:
                switch(type)
                {
                    case WDAY: str = data->day; break;
                    case TEMP_MIN: str = data->low; break;
                    case TEMP_MAX: str = data->hi; break;
                    default: str = g_strdup("-"); break;
                }
                break;
            case NPART:
                str = get_data_part(data->part[1], type);
                break;
            case DPART:
                str = get_data_part(data->part[0], type);
                break; 
        }
    }

    if (!str)
        str = "-";
    

    p = copy_buffer(str);
       //DBG ("value: %s", p);
    return p;
}