Ejemplo n.º 1
0
Archivo: blob.c Proyecto: KeenS/benz
static pic_value
pic_blob_bytevector_length(pic_state *pic)
{
  struct pic_blob *bv;

  pic_get_args(pic, "b", &bv);

  return pic_size_value(bv->len);
}
Ejemplo n.º 2
0
static pic_value
pic_str_string_length(pic_state *pic)
{
  pic_str *str;

  pic_get_args(pic, "s", &str);

  return pic_size_value(pic_str_len(str));
}
Ejemplo n.º 3
0
Archivo: port.c Proyecto: KeenS/benz
static pic_value
pic_port_read_blob_ip(pic_state *pic)
{
  struct pic_port *port;
  struct pic_blob *bv;
  int n;
  char *buf;
  size_t start, end, i, len;

  n = pic_get_args(pic, "b|pkk", &bv, &port, &start, &end);
  switch (n) {
  case 1:
    port = pic_stdin(pic);
  case 2:
    start = 0;
  case 3:
    end = bv->len;
  }

  assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-bytevector!");

  if (end < start) {
    pic_errorf(pic, "read-bytevector!: end index must be greater than or equal to start index");
  }

  len = end - start;

  buf = pic_calloc(pic, len, sizeof(char));
  i = xfread(buf, sizeof(char), len, port->file);
  memcpy(bv->data + start, buf, i);
  pic_free(pic, buf);

  if (i == 0) {
    return pic_eof_object();
  }
  else {
    return pic_size_value(i);
  }
}