示例#1
0
文件: sparse.c 项目: Happuri/various
/* Scan the sparse file and create its map */
static bool
sparse_scan_file (struct tar_sparse_file *file)
{
  struct tar_stat_info *st = file->stat_info;
  int fd = file->fd;
  char buffer[BLOCKSIZE];
  size_t count = 0;
  off_t offset = 0;
  struct sp_array sp = {0, 0};

  st->archive_file_size = 0;

  if (ST_NBLOCKS (st->stat) == 0)
    offset = st->stat.st_size;
  else
    {
      if (!tar_sparse_scan (file, scan_begin, NULL))
	return false;

      while ((count = blocking_read (fd, buffer, sizeof buffer)) != 0
	     && count != SAFE_READ_ERROR)
	{
	  /* Analyze the block.  */
	  if (zero_block_p (buffer, count))
	    {
	      if (sp.numbytes)
		{
		  sparse_add_map (st, &sp);
		  sp.numbytes = 0;
		  if (!tar_sparse_scan (file, scan_block, NULL))
		    return false;
		}
	    }
	  else
	    {
	      if (sp.numbytes == 0)
		sp.offset = offset;
	      sp.numbytes += count;
	      st->archive_file_size += count;
	      if (!tar_sparse_scan (file, scan_block, buffer))
		return false;
	    }

	  offset += count;
	}
    }

  if (sp.numbytes == 0)
    sp.offset = offset;

  sparse_add_map (st, &sp);
  st->archive_file_size += count;
  return tar_sparse_scan (file, scan_end, NULL);
}
示例#2
0
static gboolean async_event_handle(GIOChannel *channel,
                                   GIOCondition condition,
                                   gpointer data){
  unsigned char buf[1];

  while(read(eventpipe[0],buf,1)>0){
    switch((int)buf[0]){
    case 0: /* exit */
      gtk_main_quit();
      break;
    case 1: /* hw1 opened */
      {
        char name[255];
        char len;
        blocking_read(eventpipe[0],&len,1);
        blocking_read(eventpipe[0],name,(int)len);

        rowreadout_light(panel0_readout_hw,1);
        rowwidget_add_label(panel0_readout_hw,name,1);
        rowreadout_light(panel10_readout_hw,1);
        rowwidget_add_label(panel10_readout_hw,name,1);
      }
      break;
    case 2: /* hw1 closed */
      rowreadout_light(panel0_readout_hw,0);
      rowwidget_add_label(panel0_readout_hw,NULL,1);
      rowreadout_light(panel10_readout_hw,0);
      rowwidget_add_label(panel10_readout_hw,NULL,1);
      break;
    case 5: /* update shaped dither setting */
      panel_dither_shaped = request_dither_shaped;
      rowtoggle_set_active(panel5_button_shaped,panel_dither_shaped);
      break;
    case 6: /* done with an output burst; back to silence */
      rowtoggle_set_active(panel10_button_silence,1);
    }
  }
  return TRUE;
}
示例#3
0
static void* socket_handle ( void* udata )
{
	jmp_buf storageBuf;
	void* rawData = NULL;
	void* unencryptedData = NULL;
	void* resultData = NULL;
	void* encryptedResultData = NULL;
	unsigned int packetLen;
	struct _socket_handle_data* hdata = (struct _socket_handle_data*)udata;
	if (!setjmp(storageBuf))
	{
		blocking_read(hdata->fd, &storageBuf, &packetLen, sizeof(packetLen));
		packetLen = ntohl(packetLen);
		rawData = malloc(packetLen);
		blocking_read(hdata->fd, &storageBuf, rawData, packetLen);
		unencryptedData = cduck_decrypt(rawData, packetLen, &packetLen);
		if (!unencryptedData)
			longjmp(storageBuf, 1);
		free(rawData);
		rawData = NULL;
		// handle the data here
		resultData = handle_packet(unencryptedData, packetLen, &packetLen);
		encryptedResultData = cduck_encrypt(resultData, packetLen, &packetLen);
		write(hdata->fd, encryptedResultData, packetLen);
	}
	if (rawData)
		free(rawData);
	if (unencryptedData)
		free(unencryptedData);
	if (resultData)
		free(resultData);
	if (encryptedResultData)
		free(encryptedResultData);
	close(hdata->fd);
	free(udata);
	return NULL;
}
示例#4
0
文件: edit.c 项目: radixo/openbsd-src
int
x_getc(void)
{
	char c;
	int n;

	while ((n = blocking_read(STDIN_FILENO, &c, 1)) < 0 && errno == EINTR)
		if (trap) {
			x_mode(false);
			runtraps(0);
			x_mode(true);
		}
	if (n != 1)
		return -1;
	return (int) (unsigned char) c;
}
示例#5
0
文件: shf.c 项目: Open343/bitrig
/* Fill up a read buffer.  Returns EOF for a read error, 0 otherwise. */
static int
shf_fillbuf(struct shf *shf)
{
	if (shf->flags & SHF_STRING)
		return 0;

	if (shf->fd < 0)
		internal_errorf(1, "shf_fillbuf: no fd");

	if (shf->flags & (SHF_EOF | SHF_ERROR)) {
		if (shf->flags & SHF_ERROR)
			errno = shf->errno_;
		return EOF;
	}

	if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF)
		return EOF;

	shf->flags |= SHF_READING;

	shf->rp = shf->buf;
	while (1) {
		shf->rnleft = blocking_read(shf->fd, (char *) shf->buf,
		    shf->rbsize);
		if (shf->rnleft < 0 && errno == EINTR &&
		    !(shf->flags & SHF_INTERRUPT))
			continue;
		break;
	}
	if (shf->rnleft <= 0) {
		if (shf->rnleft < 0) {
			shf->flags |= SHF_ERROR;
			shf->errno_ = errno;
			shf->rnleft = 0;
			shf->rp = shf->buf;
			return EOF;
		}
		shf->flags |= SHF_EOF;
	}
	return 0;
}