Exemple #1
0
int utility_file_read(FILE *file_stream, size_t buffer_inc,
                      int (*read_fn)(const char *line, void *args),
                      void *args)
{
  unsigned int nth_line = 0;
  char *buffer = NULL;
  size_t buffer_len = 0;

  int exit_status = -3;
  while (exit_status == -3) {
    ++nth_line;

    int rc = utility_file_readln(file_stream, &buffer, &buffer_len, buffer_inc);
    if (rc == -1) {
      exit_status = 0;
      continue;
    } else if (rc == -2) {
      log_error("Fail to read line #%u", nth_line);
      exit_status = -2;
      continue;
    }

    if (read_fn(buffer, args) != 0) {
      exit_status = -1;
      continue;
    }
  }

  if (buffer != NULL) {
    free(buffer);
  }
  return exit_status;
}
Exemple #2
0
int PNGAPI
pngx_read_image(png_structp png_ptr, png_infop info_ptr,
                png_const_charpp fmt_name, png_const_charpp fmt_description)
{
   png_byte sig[128];
   size_t num;
   int (*read_fn)(png_structp, png_infop, FILE *);
   FILE *stream;
   fpos_t fpos;
   int result;

   /* Precondition. */
#ifdef PNG_FLAG_MALLOC_NULL_MEM_OK
   PNGX_ASSERT_MSG(!(png_ptr->flags & PNG_FLAG_MALLOC_NULL_MEM_OK),
      "pngxtern requires a safe allocator");
#endif

   /* Read the signature bytes. */
   stream = (FILE *)png_get_io_ptr(png_ptr);
   PNGX_ASSERT(stream != NULL);
   if (fgetpos(stream, &fpos) != 0)
      png_error(png_ptr, "Can't ftell in input file stream");
   num = fread(sig, 1, sizeof(sig), stream);
   if (fsetpos(stream, &fpos) != 0)
      png_error(png_ptr, "Can't fseek in input file stream");

   /* Try the PNG format first. */
   if (pngx_sig_is_png(png_ptr, sig, num, fmt_name, fmt_description) > 0)
   {
      png_read_png(png_ptr, info_ptr, 0, NULL);
      if (getc(stream) != EOF)
      {
         png_warning(png_ptr, "Extraneous data found after IEND");
         fseek(stream, 0, SEEK_END);
      }
      return 1;
   }

   /* Check the signature bytes against other known image formats. */
   if (pngx_sig_is_bmp(sig, num, fmt_name, fmt_description) > 0)
      read_fn = pngx_read_bmp;
   else if (pngx_sig_is_gif(sig, num, fmt_name, fmt_description) > 0)
      read_fn = pngx_read_gif;
   else if (pngx_sig_is_jpeg(sig, num, fmt_name, fmt_description) > 0)
      read_fn = pngx_read_jpeg;
   else if (pngx_sig_is_pnm(sig, num, fmt_name, fmt_description) > 0)
      read_fn = pngx_read_pnm;
   else if (pngx_sig_is_tiff(sig, num, fmt_name, fmt_description) > 0)
      read_fn = pngx_read_tiff;
   else
      return 0;  /* not a known image format */

   /* Read the image. */
   result = read_fn(png_ptr, info_ptr, stream);
   /* Signature checking may give false positives; reading can still fail. */
   if (result <= 0)  /* this isn't the format we thought it was */
      if (fsetpos(stream, &fpos) != 0)
         png_error(png_ptr, "Can't fseek in input file stream");
   return result;
}
Exemple #3
0
static int __init xilinx_clocksource_init(void)
{
	if (clocksource_register_hz(&clocksource_microblaze, timer_clock_freq))
		panic("failed to register clocksource");

	/* stop timer1 */
	write_fn(read_fn(timer_baseaddr + TCSR1) & ~TCSR_ENT,
		 timer_baseaddr + TCSR1);
	/* start timer1 - up counting without interrupt */
	write_fn(TCSR_TINT|TCSR_ENT|TCSR_ARHT, timer_baseaddr + TCSR1);

	/* register timecounter - for ftrace support */
	init_xilinx_timecounter();
	return 0;
}
Exemple #4
0
/* Skip data from any stream by reading and simply discarding it. */
static svn_error_t *
skip_default_handler(void *baton, apr_size_t len, svn_read_fn_t read_fn)
{
  apr_size_t bytes_read = 1;
  char buffer[4096];
  apr_size_t to_read = len;

  while ((to_read > 0) && (bytes_read > 0))
    {
      bytes_read = sizeof(buffer) < to_read ? sizeof(buffer) : to_read;
      SVN_ERR(read_fn(baton, buffer, &bytes_read));
      to_read -= bytes_read;
    }

  return SVN_NO_ERROR;
}
Exemple #5
0
void LK_VECTOR_Read(int fd, struct Vector* vec, struct Module_st* CMData, Adjust_t* adj,void (*read_fn)(int fd, struct Module_st* CMData, void* entry))
{
  Word i;
  Word offset;
  Word objSize;
  void* base;
  Word count=adj->count=LK_FILE_GET2(fd);
  if(count==0)
  {
    adj->offset=LK_VECTOR_Size(vec);
    return;
  }
  offset=adj->offset=LK_VECTOR_Grow(vec,count);
  base=LK_VECTOR_GetPtr(vec,offset);
  objSize=vec->objSize;
  for(i=0;i<count;i++)
  {
    read_fn(fd,CMData,((u_int8_t *)base)+i*objSize);
  }
}
Exemple #6
0
int
MimePartBufferRead (MimePartBufferData *data,
          nsresult (*read_fn) (const char *buf, PRInt32 size, void *closure),
          void *closure)
{
  int status = 0;
  NS_ASSERTION(data, "no data");
  if (!data) return -1;

  if (data->part_buffer)
  {
    // Read it out of memory.
    status = read_fn(data->part_buffer, data->part_buffer_fp, closure);
  }
  else if (data->file_buffer)
  {
    /* Read it off disk.
     */
    char *buf;
    PRInt32 buf_size = DISK_BUFFER_SIZE;

    NS_ASSERTION(data->part_buffer_size == 0 && data->part_buffer_fp == 0, "buffer size is not null");
    NS_ASSERTION(data->file_buffer, "no file buffer name");
    if (!data->file_buffer)
      return -1;

    buf = (char *) PR_MALLOC(buf_size);
    if (!buf)
      return MIME_OUT_OF_MEMORY;

    // First, close the output file to open the input file!
    if (data->output_file_stream)
      data->output_file_stream->Close();

    nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(data->input_file_stream), data->file_buffer);
    if (NS_FAILED(rv))
    {
      PR_Free(buf);
      return MIME_UNABLE_TO_OPEN_TMP_FILE;
    }
    while(1)
    {
      PRUint32 bytesRead = 0;
      rv = data->input_file_stream->Read(buf, buf_size - 1, &bytesRead);
      if (NS_FAILED(rv) || !bytesRead)
      {
        break;
      }
      else
      {
        /* It would be really nice to be able to yield here, and let
        some user events and other input sources get processed.
        Oh well. */

        status = read_fn (buf, bytesRead, closure);
        if (status < 0) break;
      }
    }
    PR_Free(buf);
  }

  return 0;
}
Exemple #7
0
static inline void xilinx_timer0_stop(void)
{
	write_fn(read_fn(timer_baseaddr + TCSR0) & ~TCSR_ENT,
		 timer_baseaddr + TCSR0);
}
Exemple #8
0
static int __init xilinx_timer_init(struct device_node *timer)
{
	struct clk *clk;
	static int initialized;
	u32 irq;
	u32 timer_num = 1;
	int ret;

	if (initialized)
		return -EINVAL;

	initialized = 1;

	timer_baseaddr = of_iomap(timer, 0);
	if (!timer_baseaddr) {
		pr_err("ERROR: invalid timer base address\n");
		return -ENXIO;
	}

	write_fn = timer_write32;
	read_fn = timer_read32;

	write_fn(TCSR_MDT, timer_baseaddr + TCSR0);
	if (!(read_fn(timer_baseaddr + TCSR0) & TCSR_MDT)) {
		write_fn = timer_write32_be;
		read_fn = timer_read32_be;
	}

	irq = irq_of_parse_and_map(timer, 0);
	if (irq <= 0) {
		pr_err("Failed to parse and map irq");
		return -EINVAL;
	}

	of_property_read_u32(timer, "xlnx,one-timer-only", &timer_num);
	if (timer_num) {
		pr_err("Please enable two timers in HW\n");
		return -EINVAL;
	}

	pr_info("%pOF: irq=%d\n", timer, irq);

	clk = of_clk_get(timer, 0);
	if (IS_ERR(clk)) {
		pr_err("ERROR: timer CCF input clock not found\n");
		/* If there is clock-frequency property than use it */
		of_property_read_u32(timer, "clock-frequency",
				    &timer_clock_freq);
	} else {
		timer_clock_freq = clk_get_rate(clk);
	}

	if (!timer_clock_freq) {
		pr_err("ERROR: Using CPU clock frequency\n");
		timer_clock_freq = cpuinfo.cpu_clock_freq;
	}

	freq_div_hz = timer_clock_freq / HZ;

	ret = setup_irq(irq, &timer_irqaction);
	if (ret) {
		pr_err("Failed to setup IRQ");
		return ret;
	}

	ret = xilinx_clocksource_init();
	if (ret)
		return ret;

	ret = xilinx_clockevent_init();
	if (ret)
		return ret;

	sched_clock_register(xilinx_clock_read, 32, timer_clock_freq);

	return 0;
}
Exemple #9
0
static u64 xilinx_clock_read(void)
{
	return read_fn(timer_baseaddr + TCR1);
}
Exemple #10
0
static inline void timer_ack(void)
{
	write_fn(read_fn(timer_baseaddr + TCSR0), timer_baseaddr + TCSR0);
}
Exemple #11
0
static void __init xilinx_timer_init(struct device_node *timer)
{
	struct clk *clk;
	static int initialized;
	u32 irq;
	u32 timer_num = 1;

	if (initialized)
		return;

	initialized = 1;

	timer_baseaddr = of_iomap(timer, 0);
	if (!timer_baseaddr) {
		pr_err("ERROR: invalid timer base address\n");
		BUG();
	}

	write_fn = timer_write32;
	read_fn = timer_read32;

	write_fn(TCSR_MDT, timer_baseaddr + TCSR0);
	if (!(read_fn(timer_baseaddr + TCSR0) & TCSR_MDT)) {
		write_fn = timer_write32_be;
		read_fn = timer_read32_be;
	}

	irq = irq_of_parse_and_map(timer, 0);

	of_property_read_u32(timer, "xlnx,one-timer-only", &timer_num);
	if (timer_num) {
		pr_emerg("Please enable two timers in HW\n");
		BUG();
	}

	pr_info("%s: irq=%d\n", timer->full_name, irq);

	clk = of_clk_get(timer, 0);
	if (IS_ERR(clk)) {
		pr_err("ERROR: timer CCF input clock not found\n");
		/* If there is clock-frequency property than use it */
		of_property_read_u32(timer, "clock-frequency",
				    &timer_clock_freq);
	} else {
		timer_clock_freq = clk_get_rate(clk);
	}

	if (!timer_clock_freq) {
		pr_err("ERROR: Using CPU clock frequency\n");
		timer_clock_freq = cpuinfo.cpu_clock_freq;
	}

	freq_div_hz = timer_clock_freq / HZ;

	setup_irq(irq, &timer_irqaction);
#ifdef CONFIG_HEART_BEAT
	microblaze_setup_heartbeat();
#endif
	xilinx_clocksource_init();
	xilinx_clockevent_init();

	sched_clock_register(xilinx_clock_read, 32, timer_clock_freq);
}