Exemple #1
0
static ssize_t
port_write (void *cookie, const char *buf, size_t siz)
{
  SCM port = PTR2SCM (cookie);

#ifdef GUILE_CHARS_ARE_UCS4
  if (siz > SSIZE_MAX)
    {
      scm_c_write (port, buf, SSIZE_MAX);
      return SSIZE_MAX;
    }
  else
    {
      scm_c_write (port, buf, siz);
      return siz;
    }
#else
  {
    size_t i;
    SCM chr_as_int;
    SCM chr;

    for (i = 0; i < siz; i++)
      {
	chr_as_int = scm_from_uchar ((unsigned char) buf[i]);
	chr = scm_integer_to_char (chr_as_int);
	scm_write_char (chr, port);
      }
  }

  return siz;
#endif
}
Exemple #2
0
static int
port_close (void *cookie)
{
  SCM port = PTR2SCM (cookie);

  scm_close_port (port);

  return PORT_OK;
}
Exemple #3
0
/* This callback function sends some data from a port over to curl. */
static size_t
read_callback (void *ptr, size_t size, size_t nmemb, void *userdata)
{
  size_t length1;
  SCM port;

  port = PTR2SCM(userdata);
  length1 = scm_c_read (port, ptr, size * nmemb);
  return length1;
}
Exemple #4
0
static int
port_seek (void *cookie, off64_t * pos, int whence)
{
  SCM port = PTR2SCM (cookie);
  SCM new_pos;

  new_pos = scm_seek (port, scm_from_int64 (*pos), scm_from_int (whence));
  *pos = scm_to_int64 (new_pos);

  return PORT_OK;
}
Exemple #5
0
static ssize_t
port_read (void *cookie, char *buf, size_t siz)
{
  SCM port = PTR2SCM (cookie);

#ifdef GUILE_CHARS_ARE_UCS4
  int c;
  if (siz >= 1)
    {
      c = scm_get_byte_or_eof (port);

      if (c == EOF)
	return 0;
      else
	buf[0] = c;

      return 1;
    }
  else
    return PORT_ERR;
#else
  /* For Guile 1.8.x, we use scm_read_char so we can preserve line
     and column information.  */
  SCM c;
  if (siz >= 1)
    {
      c = scm_read_char (port);

      if (scm_is_true (scm_eof_object_p (c)))
	return 0;
      else
	buf[0] = scm_to_char (c);

      return 1;
    }
  else
    return PORT_ERR;
#endif
}
Exemple #6
0
static void
invoke_finalizer (void *obj, void *data)
{
  scm_call_1 (PTR2SCM (data), PTR2SCM (obj));
}